Skip to content

Commit 4577ea9

Browse files
committed
fix(launcher): Delay search 100ms after last input
1 parent e123d78 commit 4577ea9

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/dialog_search.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as rect from 'rectangle';
66

77
import { SearchOption } from 'launcher_service';
88

9+
const GLib: GLib = imports.gi.GLib;
10+
911
const { Clutter, Shell, St } = imports.gi;
1012
const { ModalDialog } = imports.ui.modalDialog;
1113

@@ -52,7 +54,6 @@ export class Search {
5254

5355
this.active_id = 0;
5456
this.widgets = [];
55-
5657
this.entry = new St.Entry({
5758
style_class: "pop-shell-entry",
5859
can_focus: true,
@@ -65,13 +66,35 @@ export class Search {
6566
(this.text as any).set_use_markup(true)
6667
this.dialog.setInitialKeyFocus(this.text);
6768

68-
this.text.connect("activate", () => this.activate_option(this.active_id));
69+
let text_changed: null | number = null;
70+
71+
this.text.connect("activate", () => {
72+
if (text_changed !== null) GLib.source_remove(text_changed)
73+
text_changed = null
74+
this.activate_option(this.active_id)
75+
});
6976

7077
this.text.connect("text-changed", (entry: any) => {
71-
this.clear();
78+
if (text_changed !== null) GLib.source_remove(text_changed)
79+
80+
const text = (entry as Clutter.Text).get_text().trim()
81+
82+
const update = () => {
83+
this.clear()
84+
const update = search(text)
85+
if (update) this.update_search_list(update)
86+
}
87+
88+
if (text.length === 0) {
89+
update()
90+
return
91+
}
7292

73-
const update = search((entry as Clutter.Text).get_text().trim())
74-
if (update) this.update_search_list(update)
93+
text_changed = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
94+
text_changed = null
95+
update()
96+
return false;
97+
})
7598
});
7699

77100
this.text.connect("key-press-event", (_: any, event: any) => {

0 commit comments

Comments
 (0)