@setoelkahfi / svara / commits / fb0a03d

fix!: disabled edit buttons temporarily

system shortcuts should do for now

mellbacon committed Aug 1, 2023 at 13:47 UTC fb0a03d6e0fed450e498676da16f99b614a581a9
4 files changed +19 -32
src/config/commands.ts
+6
@@ -36,30 +36,35 @@ export const commands = {
36 },
37 "undo": {
38 "keybind": "Control+Z",
39 + "disabled": "true",
40 "command": async () => {
41 await undoChange();
42 }
43 },
44 "redo": {
45 "keybind": "Control+Shift+Z",
46 + "disabled": "true",
47 "command": async () => {
48 await redoChange();
49 }
50 },
51 "cut": {
52 "keybind": "Control+X",
53 + "disabled": "true",
54 "command": async () => {
55 await cut();
56 }
57 },
58 "copy": {
59 "keybind": "Control+C",
60 + "disabled": "true",
61 "command": async () => {
62 await copy();
63 }
64 },
65 "paste": {
66 "keybind": "Control+V",
67 + "disabled": "true",
68 "command": async () => {
69 const content = await navigator.clipboard.readText();
70 append(content);
@@ -73,6 +78,7 @@ export const commands = {
78 },
79 "delete": {
80 "keybind": "Delete",
81 + "disabled": "true",
82 "command": async () => {
83 await deleteChars();
84 }
src/config/config.ts
+5 -8
@@ -6,7 +6,6 @@ import { loadTheme } from "./themehandler";
6 import { Store } from "tauri-plugin-store-api";
7 import { setEditorFontFamily, setEditorFontSize } from "../lib/Editor.svelte";
8 import { watch } from "tauri-plugin-fs-watch-api";
9 -import { getActiveTab } from "../lib/EditorTabList.svelte";
9
10 export const systemfonts = writable([]);
11 export const editorfont = writable("");
@@ -49,15 +48,13 @@ function parseKeybind(keybind: string) {
48 export async function getShortcuts() {
49 const shortcuts = getKeybinds();
50 for (const shortcut of shortcuts) {
51 + // skip binding shorcuts that are disabled
52 + if (shortcut.disabled === true) {
53 + continue;
54 + }
55 const keybind = parseKeybind(shortcut.keybind);
56 Mousetrap.bind(keybind, async (e) => {
54 - // prevent editor functions firing outside editor instances
55 - if (getActiveTab().isfile) {
56 - e.preventDefault();
57 - }
58 - else {
59 - return;
60 - }
57 + e.preventDefault();
58 await fireAction(shortcut.command);
59 });
60 }
src/lib/Editor.svelte
+1 -17
@@ -40,22 +40,6 @@
40 }
41
42 onMount(async () => {
43 - // disable default copy/paste/delete keys
44 - // instead implement our own functions for copy/paste/delete so it can be bound to different keybindings
45 - const disabledKeys = [
46 - {
47 - key: "Ctrl-v",
48 - preventDefault: true
49 - },
50 - {
51 - key: "Ctrl-c",
52 - preventDefault: true
53 - },
54 - {
55 - key: "Delete",
56 - preventDefault: true
57 - }
58 - ]
43 editorView = new EditorView({
44 parent: ref,
45 state: EditorState.create({
@@ -73,7 +57,6 @@
57 EditorState.allowMultipleSelections.of(true),
58 syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
59 keymap.of([
76 - ...disabledKeys,
60 ...defaultKeymap
61 ])
62 ],
@@ -163,6 +146,7 @@
146 }
147 }
148
149 + // TODO: need to find a much better way of handling this
150 // yes im aware how messy all these functions are but it works!
151 export async function append(value: string) {
152 let cursorpos = getCurrentEditor().getView().state.selection.main.head + value.length;
src/lib/Header.svelte
+7 -7
@@ -17,14 +17,14 @@
17 {name: "Close Tab", disabled: $tabs.length === 0, shortcut: "", action: async () => {await closeActiveTab()}},
18 ]},
19 {menuname: "Edit", children: [
20 - {name: "Undo", shortcut: commands.undo.keybind, action: commands.undo.command},
21 - {name: "Redo", shortcut: commands.redo.keybind, action: commands.redo.command},
22 - {name: "Cut", shortcut: commands.cut.keybind, action: commands.cut.command},
23 - {name: "Copy", shortcut: commands.copy.keybind, action: commands.copy.command},
24 - {name: "Paste", shortcut: commands.paste.keybind, action: commands.paste.command},
20 + {name: "Undo", disabled: commands.undo.disabled, shortcut: commands.undo.keybind, action: commands.undo.command},
21 + {name: "Redo", disabled: commands.redo.disabled, shortcut: commands.redo.keybind, action: commands.redo.command},
22 + {name: "Cut", disabled: commands.cut.disabled, shortcut: commands.cut.keybind, action: commands.cut.command},
23 + {name: "Copy", disabled: commands.copy.disabled, shortcut: commands.copy.keybind, action: commands.copy.command},
24 + {name: "Paste", disabled: commands.paste.disabled, shortcut: commands.paste.keybind, action: commands.paste.command},
25 {name: "Paste From History...", disabled: true, shortcut: commands.pasteFromHistory.keybind, action: commands.pasteFromHistory.command},
26 - {name: "Delete", shortcut: commands.delete.keybind, action: commands.delete.command},
27 - {name: "Find", disabled: true, shortcut: commands.find.keybind, action: () => commands.find.command},
26 + {name: "Delete", disabled: commands.delete.disabled, shortcut: commands.delete.keybind, action: commands.delete.command},
27 + {name: "Find", disabled: true, shortcut: commands.find.keybind, action: () => commands.find.command},
28 {name: "Replace", disabled: true, shortcut: commands.replace.keybind, action: commands.replace.command},
29 ]},
30 {menuname: "View", children: [