forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathselectionMenu.js
More file actions
77 lines (69 loc) · 1.81 KB
/
selectionMenu.js
File metadata and controls
77 lines (69 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const exec = (command) => {
const { editor } = editorManager;
editor.execCommand(command);
if (command === "selectall") {
editor.scrollToRow(Number.POSITIVE_INFINITY);
editor.setSelection(true);
editor.setMenu(true);
}
editor.focus();
};
const showCodeActions = async () => {
const { editor } = editorManager;
if (!editor) return;
try {
const { showCodeActionsMenu, supportsCodeActions } = await import("cm/lsp");
if (supportsCodeActions(editor)) {
await showCodeActionsMenu(editor);
}
} catch (error) {
console.warn("[SelectionMenu] Code actions not available:", error);
}
};
const items = [];
export default function selectionMenu() {
return [
item(
() => exec("copy"),
<span className="icon copy"></span>,
"selected",
true,
),
item(() => exec("cut"), <span className="icon cut"></span>, "selected"),
item(() => exec("paste"), <span className="icon paste"></span>, "all"),
item(
() => exec("selectall"),
<span className="icon text_format"></span>,
"all",
true,
),
item(
(color) => acode.exec("insert-color", color),
<span className="icon color_lenspalette"></span>,
"all",
),
item(
() => showCodeActions(),
<span className="icon lightbulb" title="Code Actions"></span>,
"all",
true,
),
...items,
];
}
/**
*
* @param {function} onclick function to be called when the item is clicked
* @param {string | HTMLElement} text content of the item
* @param {'selected'|'all'} mode mode supported by the item
* @param {boolean} readOnly whether to show the item in readOnly mode
*/
selectionMenu.add = (onclick, text, mode, readOnly) => {
items.push(item(onclick, text, mode, readOnly));
};
selectionMenu.exec = (command) => {
exec(command);
};
function item(onclick, text, mode = "all", readOnly = false) {
return { onclick, text, mode, readOnly };
}