Added Apple keyboard shortcut Meta+s to save notes.

This commit is contained in:
Christian Bastian
2024-07-28 08:47:19 -04:00
parent ddb0170b4f
commit fcb2c426f4
2 changed files with 18 additions and 6 deletions

View File

@@ -53,7 +53,7 @@ Designed to support desktop, mobile and multi-screen devices.
- View file info and metadata.
- Rename, move or **permanently** remove a model and all of it's related files.
- Read, edit and save notes. (Saved as a `.txt` file beside the model).
- `Ctrl+S` to save a note when the textarea is in focus.
- `Ctrl+s` to save a note when the textarea is in focus.
- Autosave can be enabled in settings. (Note: Once the model info view is closed, the undo history is lost.)
- Change or remove a model's preview image.
- View training tags and use the random tag generator to generate prompt ideas.

View File

@@ -59,11 +59,12 @@ class KeyComboListener {
this.action = action;
this.element = element;
element.addEventListener("keydown", (e) => {
document.addEventListener("keydown", (e) => {
const code = e.code;
const keyCodes = this.#keyCodes;
const combo = this.#combo;
if (keyCodes.includes(code) && !combo.includes(code)) {
console.log(`COMBO ADD: ${code}, COMBO:${combo}`);
combo.push(code);
}
if (combo.length === 0 || keyCodes.length !== combo.length) {
@@ -74,13 +75,24 @@ class KeyComboListener {
return;
}
}
if (document.activeElement !== this.element) {
console.log("not active");
return;
}
console.log("SAVE");
e.preventDefault();
e.stopPropagation();
this.action();
});
element.addEventListener("keyup", (e) => {
document.addEventListener("keyup", (e) => {
// Mac keyup doesn't fire when meta key is held: https://stackoverflow.com/a/73419500
const code = e.code;
this.#combo = this.#combo.filter(x => x !== code);
if (code === "MetaLeft" || code === "MetaRight") {
this.#combo.length = 0;
}
else {
this.#combo = this.#combo.filter(x => x !== code);
}
});
}
}
@@ -2715,12 +2727,12 @@ class ModelInfo {
notes,
);
new KeyComboListener(
["ControlLeft", "KeyS"],
["MetaLeft", "KeyS"],
saveDebounce,
notes,
);
new KeyComboListener(
["ControlRight", "KeyS"],
["MetaRight", "KeyS"],
saveDebounce,
notes,
);