shortcut optimizations ig
mellobacon committed
Dec 1, 2022 at 01:19 UTC
b3bacee04faf7a5ad4ae8bb60471f3d1dbfca944
3 files changed
+64
-14
src/App.svelte
+41
@@ -6,8 +6,49 @@
6
import { Pane, Splitpanes } from 'svelte-splitpanes';
7
import SidebarView from "./components/Sidebar/SidebarView.svelte";
8
import { showsidebarview, tool } from "./components/Sidebar/Sidebar";
9
+ import settings from "./config/nucleus-settings.json";
10
+ import { executeWindowShortcut } from "./config/config";
11
+
12
+ const shortcuts = Object.entries(settings.shortcuts);
13
+ let keys = {};
14
+ function modifier(shortcut) {
15
+ switch (shortcut) {
16
+ case "Ctrl":
17
+ return "Control";
18
+ case "Shift":
19
+ return "Shift";
20
+ case "Alt":
21
+ return "Alt";
22
+ }
23
+ return "";
24
+ }
25
</script>
26
27
+<svelte:window on:contextmenu|preventDefault on:keyup={(e) => {
28
+ const key = e.key.charAt(0).toUpperCase() + e.key.slice(1);
29
+ keys[key] = false;
30
+ keys = {};
31
+}}
32
+on:keydown={async (e) => {
33
+ const key = e.key.charAt(0).toUpperCase() + e.key.slice(1);
34
+ keys[key] = true;
35
+ for (const [name, shortcutKey] of shortcuts) {
36
+ if (keys[modifier(shortcutKey.modifier)] && keys[modifier(shortcutKey.secondaryKey)] && keys[shortcutKey.primaryKey]) {
37
+ await executeWindowShortcut(name);
38
+ return false;
39
+ }
40
+ else if (keys[modifier(shortcutKey.modifier)] && shortcutKey.secondaryKey === "" && keys[shortcutKey.primaryKey]) {
41
+ await executeWindowShortcut(name);
42
+ return false;
43
+ }
44
+ else if (shortcutKey.modifier === "" && shortcutKey.secondaryKey === "" && keys[shortcutKey.primaryKey]) {
45
+ e.preventDefault();
46
+ await executeWindowShortcut(name);
47
+ break;
48
+ }
49
+ }
50
+}}></svelte:window>
51
+
52
<Header />
53
<div id="main">
54
<Sidebar />
src/components/Editor/CodeMirrorEditor.svelte
+4
-4
@@ -9,7 +9,7 @@
9
import { fs } from "@tauri-apps/api";
10
import settings from "../../config/nucleus-settings.json";
11
import { addNotification, NotifType } from "../Notifications/Notifications";
12
- import { execute } from "../../config/config";
12
+ import { executeEditorShortcut } from "../../config/config";
13
14
const shortcuts = Object.entries(settings.shortcuts);
15
let keys = {};
@@ -119,7 +119,7 @@ on:keydown={async (e) => {
119
keys[key] = true;
120
for (const [name, shortcutKey] of shortcuts) {
121
if (keys[modifier(shortcutKey.modifier)] && keys[modifier(shortcutKey.secondaryKey)] && keys[shortcutKey.primaryKey]) {
122
- await execute(name);
122
+ executeEditorShortcut(name);
123
return false;
124
}
125
else if (keys[modifier(shortcutKey.modifier)] && shortcutKey.secondaryKey === "" && keys[shortcutKey.primaryKey]) {
@@ -129,7 +129,7 @@ on:keydown={async (e) => {
129
getLineInfo();
130
return false;
131
}
132
- await execute(name);
132
+ executeEditorShortcut(name);
133
return false;
134
}
135
else if (shortcutKey.modifier === "" && shortcutKey.secondaryKey === "" && keys[shortcutKey.primaryKey]) {
@@ -139,7 +139,7 @@ on:keydown={async (e) => {
139
getLineInfo();
140
break;
141
}
142
- await execute(name);
142
+ executeEditorShortcut(name);
143
break;
144
}
145
}
src/config/config.ts
+19
-10
@@ -11,17 +11,8 @@ export function getShortcut({ primaryKey, secondaryKey, modifier }) {
11
return `${modifier}${secondaryKey}${primaryKey}`;
12
}
13
14
-export async function execute(shortcut) {
14
+export function executeEditorShortcut(shortcut) {
15
switch (shortcut) {
16
- case "new-file-shortcut":
17
- await addFileTab();
18
- break;
19
- case "open-file-shortcut":
20
- openFile();
21
- break;
22
- case "open-folder-shortcut":
23
- openFolder();
24
- break;
16
case "save-file-shortcut":
17
saveOpenFile();
18
break;
@@ -33,6 +24,19 @@ export async function execute(shortcut) {
24
break;
25
case "select-all-text-shortcut":
26
break;
27
+ }
28
+}
29
+export async function executeWindowShortcut(shortcut) {
30
+ switch (shortcut) {
31
+ case "new-file-shortcut":
32
+ await addFileTab();
33
+ break;
34
+ case "open-file-shortcut":
35
+ await openFile();
36
+ break;
37
+ case "open-folder-shortcut":
38
+ await openFolder();
39
+ break;
40
case "build-shortcut":
41
console.log(shortcut);
42
break;
@@ -43,4 +47,9 @@ export async function execute(shortcut) {
47
console.log(shortcut);
48
break;
49
}
50
+}
51
+
52
+export function getTime() {
53
+ let time = new Intl.DateTimeFormat('en-US', {dateStyle: "short", timeStyle: "long"}).format();
54
+ return time;
55
}
\ No newline at end of file