Skip to content

Commit 978c2d0

Browse files
authored
feat: allow user to Ctrl-C copy active option and close window
1 parent 3692dd4 commit 978c2d0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/launcher.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import type { Ext } from 'extension'
1212
import type { ShellWindow } from 'window'
1313
import type { JsonIPC } from 'launcher_service'
1414

15-
const { Clutter, Gio, GLib, Meta, Shell } = imports.gi
15+
const { Clutter, Gio, GLib, Meta, Shell, St } = imports.gi
1616

1717
const app_sys = Shell.AppSystem.get_default();
1818

19+
const Clipboard = St.Clipboard.get_default();
20+
const CLIPBOARD_TYPE = St.ClipboardType.CLIPBOARD;
21+
1922
interface SearchOption {
2023
result: JsonIPC.SearchResult
2124
menu: St.Widget
@@ -96,6 +99,16 @@ export class Launcher extends search.Search {
9699
this.service?.quit(option.result.id)
97100
}
98101
}
102+
103+
this.copy = (id: number) => {
104+
const option = this.options_array[id];
105+
if (!option) return;
106+
if (option.result.description) {
107+
Clipboard.set_text(CLIPBOARD_TYPE, option.result.description);
108+
} else if (option.result.name) {
109+
Clipboard.set_text(CLIPBOARD_TYPE, option.result.name);
110+
}
111+
}
99112
}
100113

101114
on_response(response: JsonIPC.Response) {

src/search.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class Search {
4444
search: (search: string) => void = () => {}
4545
select: (id: number) => void = () => {}
4646
quit: (id: number) => void = () => {}
47+
copy: (id: number) => void = () => {}
4748

4849
constructor() {
4950
this.active_id = 0;
@@ -190,6 +191,19 @@ export class Search {
190191
// Ctrl + Q shall quit the selected application
191192
this.quit(this.active_id);
192193
return;
194+
} else if (
195+
key === "Copy" ||
196+
(ctrlKey && (key === "C" || key === "Insert"))
197+
) {
198+
if ((this.text as any).get_selection()) {
199+
// If text entry has selected text, behave as normal
200+
return;
201+
} else {
202+
// If nothing is selected, copy the active option and close
203+
this.copy(this.active_id);
204+
this.close();
205+
this.cancel();
206+
}
193207
}
194208

195209
this.select(this.active_id);

0 commit comments

Comments
 (0)