Skip to content

Commit 8b6ac67

Browse files
authored
fix searchbar not working on mobile (#5773)
1 parent 4c3ee2a commit 8b6ac67

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

src/ext/searchbox.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class SearchBox {
2121
* @param {never} [showReplaceForm]
2222
*/
2323
constructor(editor, range, showReplaceForm) {
24-
/**@type {any}*/
24+
/**@type {HTMLInputElement}*/
2525
this.activeInput;
26-
var div = dom.createElement("div");
27-
dom.buildDom(["div", {class:"ace_search right"},
26+
/**@type {HTMLDivElement}*/
27+
this.element = dom.buildDom(["div", {class:"ace_search right"},
2828
["span", {action: "hide", class: "ace_searchbtn_close"}],
2929
["div", {class: "ace_search_form"},
3030
["input", {class: "ace_search_field", placeholder: nls("search-box.find.placeholder", "Search for"), spellcheck: "false"}],
@@ -46,16 +46,15 @@ class SearchBox {
4646
["span", {action: "toggleWholeWords", class: "ace_button", title: nls("search-box.toggle-whole-word.title", "Whole Word Search")}, "\\b"],
4747
["span", {action: "searchInSelection", class: "ace_button", title: nls("search-box.toggle-in-selection.title", "Search In Selection")}, "S"]
4848
]
49-
], div);
50-
/**@type {any}*/
51-
this.element = div.firstChild;
49+
]);
5250

5351
this.setSession = this.setSession.bind(this);
5452
this.$onEditorInput = this.onEditorInput.bind(this);
5553

5654
this.$init();
5755
this.setEditor(editor);
5856
dom.importCssString(searchboxCss, "ace_searchbox", editor.container);
57+
event.addListener(this.element, "touchstart", function(e) { e.stopPropagation(); }, editor);
5958
}
6059

6160
/**

src/lib/dom.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ var useragent = require("./useragent");
44
var XHTML_NS = "http://www.w3.org/1999/xhtml";
55

66
/**
7-
*
7+
* @template {keyof HTMLElementTagNameMap} K
8+
* @overload
9+
* @param {[K, ...any[]]} arr
10+
* @param {HTMLElement} [parent]
11+
* @param {Record<string, Node>} [refs]
12+
* @returns {HTMLElementTagNameMap[K]}
13+
*/
14+
/**
15+
* @overload
816
* @param {any} arr
917
* @param {HTMLElement} [parent]
1018
* @param [refs]

types/ace-ext.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ declare module "ace-code/src/ext/command_bar" {
1919
eventListeners: {};
2020
elements: {};
2121
commands: {};
22-
tooltipEl: any[] | HTMLElement | Text;
23-
moreOptionsEl: any[] | HTMLElement | Text;
22+
tooltipEl: HTMLDivElement;
23+
moreOptionsEl: HTMLDivElement;
2424
/**
2525
* Registers a command on the command bar tooltip.
2626
*
@@ -170,8 +170,8 @@ declare module "ace-code/src/ext/searchbox" {
170170
export type Editor = import("ace-code/src/editor").Editor;
171171
export class SearchBox {
172172
constructor(editor: Editor, range?: never, showReplaceForm?: never);
173-
activeInput: any;
174-
element: any;
173+
activeInput: HTMLInputElement;
174+
element: HTMLDivElement;
175175
setSession(e: any): void;
176176
setEditor(editor: Editor): void;
177177
editor: Editor;

types/ace-lib.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ declare module "ace-code/src/lib/useragent" {
2626
export const isMobile: boolean;
2727
}
2828
declare module "ace-code/src/lib/dom" {
29+
/**
30+
* @overload
31+
*/
32+
export function buildDom<K extends keyof HTMLElementTagNameMap>(arr: [
33+
K,
34+
...any[]
35+
], parent?: HTMLElement, refs?: Record<string, Node>): HTMLElementTagNameMap[K];
36+
/**
37+
* @overload
38+
*/
2939
export function buildDom(arr: any, parent?: HTMLElement, refs?: any): HTMLElement | Text | any[];
3040
export function getDocumentHead(doc?: Document): HTMLHeadElement | HTMLElement;
3141
export function createElement<T extends keyof HTMLElementTagNameMap>(tag: T | string, ns?: string): HTMLElementTagNameMap[T];

types/ace-modules.d.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,11 @@ declare module "ace-code/src/virtual_renderer" {
12721272
textarea: HTMLTextAreaElement;
12731273
enableKeyboardAccessibility?: boolean;
12741274
showInvisibles?: boolean;
1275-
theme?: any;
1275+
theme /**
1276+
* @overload
1277+
*/? /**
1278+
* @overload
1279+
*/: any;
12761280
destroyed?: boolean;
12771281
session: Ace.EditSession;
12781282
keyboardFocusClassName?: string;
@@ -2723,7 +2727,13 @@ declare module "ace-code/src/editor" {
27232727
type Completer = import("ace-code").Ace.Completer;
27242728
type SearchBox = import("ace-code").Ace.SearchBox;
27252729
}
2726-
export interface Editor extends Ace.EditorMultiSelectProperties, Ace.OptionsProvider<Ace.EditorOptions>, Ace.EventEmitter<Ace.EditorEvents>, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension {
2730+
export interface Editor extends Ace.EditorMultiSelectProperties /**
2731+
* @overload
2732+
*/, /**
2733+
* @overload
2734+
*/ Ace
2735+
.OptionsProvider<Ace.EditorOptions>, Ace.
2736+
EventEmitter<Ace.EditorEvents>, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension {
27272737
session: Ace.EditSession;
27282738
env?: any;
27292739
widgetManager?: Ace.LineWidgets;
@@ -2892,7 +2902,11 @@ declare module "ace-code/src/autocomplete/popup" {
28922902
hide: () => void;
28932903
anchor: "top" | "bottom";
28942904
anchorPosition: Ace.Point;
2895-
tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom", forceShow?: boolean) => boolean;
2905+
tryShow: (pos: any, lineHeight: number,
2906+
/**
2907+
* @overload
2908+
*/
2909+
anchor: "top" | "bottom", forceShow?: boolean) => boolean;
28962910
show: (pos: any, lineHeight: number, topdownOnly?: boolean) => void;
28972911
goTo: (where: Ace.AcePopupNavigation) => void;
28982912
getTextLeftOffset: () => number;

0 commit comments

Comments
 (0)