Skip to content

Commit

Permalink
fix!: disabled edit buttons temporarily
Browse files Browse the repository at this point in the history
system shortcuts should do for now
  • Loading branch information
mellobacon committed Aug 1, 2023
1 parent 9c73635 commit fb0a03d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/config/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,35 @@ export const commands = {
},
"undo": {
"keybind": "Control+Z",
"disabled": "true",
"command": async () => {
await undoChange();
}
},
"redo": {
"keybind": "Control+Shift+Z",
"disabled": "true",
"command": async () => {
await redoChange();
}
},
"cut": {
"keybind": "Control+X",
"disabled": "true",
"command": async () => {
await cut();
}
},
"copy": {
"keybind": "Control+C",
"disabled": "true",
"command": async () => {
await copy();
}
},
"paste": {
"keybind": "Control+V",
"disabled": "true",
"command": async () => {
const content = await navigator.clipboard.readText();
append(content);
Expand All @@ -73,6 +78,7 @@ export const commands = {
},
"delete": {
"keybind": "Delete",
"disabled": "true",
"command": async () => {
await deleteChars();
}
Expand Down
13 changes: 5 additions & 8 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { loadTheme } from "./themehandler";
import { Store } from "tauri-plugin-store-api";
import { setEditorFontFamily, setEditorFontSize } from "../lib/Editor.svelte";
import { watch } from "tauri-plugin-fs-watch-api";
import { getActiveTab } from "../lib/EditorTabList.svelte";

export const systemfonts = writable([]);
export const editorfont = writable("");
Expand Down Expand Up @@ -49,15 +48,13 @@ function parseKeybind(keybind: string) {
export async function getShortcuts() {
const shortcuts = getKeybinds();
for (const shortcut of shortcuts) {
// skip binding shorcuts that are disabled
if (shortcut.disabled === true) {
continue;
}
const keybind = parseKeybind(shortcut.keybind);
Mousetrap.bind(keybind, async (e) => {
// prevent editor functions firing outside editor instances
if (getActiveTab().isfile) {
e.preventDefault();
}
else {
return;
}
e.preventDefault();
await fireAction(shortcut.command);
});
}
Expand Down
18 changes: 1 addition & 17 deletions src/lib/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@
}
onMount(async () => {
// disable default copy/paste/delete keys
// instead implement our own functions for copy/paste/delete so it can be bound to different keybindings
const disabledKeys = [
{
key: "Ctrl-v",
preventDefault: true
},
{
key: "Ctrl-c",
preventDefault: true
},
{
key: "Delete",
preventDefault: true
}
]
editorView = new EditorView({
parent: ref,
state: EditorState.create({
Expand All @@ -73,7 +57,6 @@
EditorState.allowMultipleSelections.of(true),
syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
keymap.of([
...disabledKeys,
...defaultKeymap
])
],
Expand Down Expand Up @@ -163,6 +146,7 @@
}
}
// TODO: need to find a much better way of handling this
// yes im aware how messy all these functions are but it works!
export async function append(value: string) {
let cursorpos = getCurrentEditor().getView().state.selection.main.head + value.length;
Expand Down
14 changes: 7 additions & 7 deletions src/lib/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
{name: "Close Tab", disabled: $tabs.length === 0, shortcut: "", action: async () => {await closeActiveTab()}},
]},
{menuname: "Edit", children: [
{name: "Undo", shortcut: commands.undo.keybind, action: commands.undo.command},
{name: "Redo", shortcut: commands.redo.keybind, action: commands.redo.command},
{name: "Cut", shortcut: commands.cut.keybind, action: commands.cut.command},
{name: "Copy", shortcut: commands.copy.keybind, action: commands.copy.command},
{name: "Paste", shortcut: commands.paste.keybind, action: commands.paste.command},
{name: "Undo", disabled: commands.undo.disabled, shortcut: commands.undo.keybind, action: commands.undo.command},
{name: "Redo", disabled: commands.redo.disabled, shortcut: commands.redo.keybind, action: commands.redo.command},
{name: "Cut", disabled: commands.cut.disabled, shortcut: commands.cut.keybind, action: commands.cut.command},
{name: "Copy", disabled: commands.copy.disabled, shortcut: commands.copy.keybind, action: commands.copy.command},
{name: "Paste", disabled: commands.paste.disabled, shortcut: commands.paste.keybind, action: commands.paste.command},
{name: "Paste From History...", disabled: true, shortcut: commands.pasteFromHistory.keybind, action: commands.pasteFromHistory.command},
{name: "Delete", shortcut: commands.delete.keybind, action: commands.delete.command},
{name: "Find", disabled: true, shortcut: commands.find.keybind, action: () => commands.find.command},
{name: "Delete", disabled: commands.delete.disabled, shortcut: commands.delete.keybind, action: commands.delete.command},
{name: "Find", disabled: true, shortcut: commands.find.keybind, action: () => commands.find.command},
{name: "Replace", disabled: true, shortcut: commands.replace.keybind, action: commands.replace.command},
]},
{menuname: "View", children: [
Expand Down

0 comments on commit fb0a03d

Please sign in to comment.