mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
refac
This commit is contained in:
parent
651f855289
commit
9c0bd0c0ed
1 changed files with 13 additions and 4 deletions
|
|
@ -196,37 +196,48 @@
|
||||||
const setupKeyboardShortcuts = () => {
|
const setupKeyboardShortcuts = () => {
|
||||||
document.addEventListener('keydown', async (event) => {
|
document.addEventListener('keydown', async (event) => {
|
||||||
if (isShortcutMatch(event, shortcuts[Shortcut.SEARCH])) {
|
if (isShortcutMatch(event, shortcuts[Shortcut.SEARCH])) {
|
||||||
|
console.log('Shortcut triggered: SEARCH');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
showSearch.set(!$showSearch);
|
showSearch.set(!$showSearch);
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.NEW_CHAT])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.NEW_CHAT])) {
|
||||||
|
console.log('Shortcut triggered: NEW_CHAT');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.getElementById('sidebar-new-chat-button')?.click();
|
document.getElementById('sidebar-new-chat-button')?.click();
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.FOCUS_INPUT])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.FOCUS_INPUT])) {
|
||||||
|
console.log('Shortcut triggered: FOCUS_INPUT');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.getElementById('chat-input')?.focus();
|
document.getElementById('chat-input')?.focus();
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.COPY_LAST_CODE_BLOCK])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.COPY_LAST_CODE_BLOCK])) {
|
||||||
|
console.log('Shortcut triggered: COPY_LAST_CODE_BLOCK');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
[...document.getElementsByClassName('copy-code-button')]?.at(-1)?.click();
|
[...document.getElementsByClassName('copy-code-button')]?.at(-1)?.click();
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.COPY_LAST_RESPONSE])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.COPY_LAST_RESPONSE])) {
|
||||||
|
console.log('Shortcut triggered: COPY_LAST_RESPONSE');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
[...document.getElementsByClassName('copy-response-button')]?.at(-1)?.click();
|
[...document.getElementsByClassName('copy-response-button')]?.at(-1)?.click();
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.TOGGLE_SIDEBAR])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.TOGGLE_SIDEBAR])) {
|
||||||
|
console.log('Shortcut triggered: TOGGLE_SIDEBAR');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
showSidebar.set(!$showSidebar);
|
showSidebar.set(!$showSidebar);
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.DELETE_CHAT])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.DELETE_CHAT])) {
|
||||||
|
console.log('Shortcut triggered: DELETE_CHAT');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.getElementById('delete-chat-button')?.click();
|
document.getElementById('delete-chat-button')?.click();
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.OPEN_SETTINGS])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.OPEN_SETTINGS])) {
|
||||||
|
console.log('Shortcut triggered: OPEN_SETTINGS');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
showSettings.set(!$showSettings);
|
showSettings.set(!$showSettings);
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.SHOW_SHORTCUTS])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.SHOW_SHORTCUTS])) {
|
||||||
|
console.log('Shortcut triggered: SHOW_SHORTCUTS');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
showShortcuts.set(!$showShortcuts);
|
showShortcuts.set(!$showShortcuts);
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.CLOSE_MODAL])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.CLOSE_MODAL])) {
|
||||||
|
console.log('Shortcut triggered: CLOSE_MODAL');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
showSettings.set(false);
|
showSettings.set(false);
|
||||||
showShortcuts.set(false);
|
showShortcuts.set(false);
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.NEW_TEMPORARY_CHAT])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.NEW_TEMPORARY_CHAT])) {
|
||||||
|
console.log('Shortcut triggered: NEW_TEMPORARY_CHAT');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if ($user?.role !== 'admin' && $user?.permissions?.chat?.temporary_enforced) {
|
if ($user?.role !== 'admin' && $user?.permissions?.chat?.temporary_enforced) {
|
||||||
temporaryChatEnabled.set(true);
|
temporaryChatEnabled.set(true);
|
||||||
|
|
@ -238,15 +249,13 @@
|
||||||
document.getElementById('new-chat-button')?.click();
|
document.getElementById('new-chat-button')?.click();
|
||||||
}, 0);
|
}, 0);
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.GENERATE_MESSAGE_PAIR])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.GENERATE_MESSAGE_PAIR])) {
|
||||||
|
console.log('Shortcut triggered: GENERATE_MESSAGE_PAIR');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.getElementById('generate-message-pair-button')?.click();
|
document.getElementById('generate-message-pair-button')?.click();
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.REGENERATE_RESPONSE])) {
|
} else if (isShortcutMatch(event, shortcuts[Shortcut.REGENERATE_RESPONSE])) {
|
||||||
|
console.log('Shortcut triggered: REGENERATE_RESPONSE');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
[...document.getElementsByClassName('regenerate-response-button')]?.at(-1)?.click();
|
[...document.getElementsByClassName('regenerate-response-button')]?.at(-1)?.click();
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.STOP_GENERATING])) {
|
|
||||||
// This shortcut is handled in Chat.svelte
|
|
||||||
} else if (isShortcutMatch(event, shortcuts[Shortcut.PREVENT_FILE_CREATION])) {
|
|
||||||
// This shortcut is handled by the paste event in MessageInput.svelte
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue