Ctrl+Up/Down message navigation: improve 3

This commit is contained in:
Enrico Ros
2024-10-25 09:15:07 -07:00
parent 9468f29aae
commit 2ff060ba38
3 changed files with 13 additions and 8 deletions
+9 -6
View File
@@ -489,7 +489,7 @@ export function AppChat() {
optimaActions().openModelOptions(chatLLMId);
}, []);
const handleMoveFocus = React.useCallback((direction: number) => {
const handleMoveFocus = React.useCallback((direction: number, wholeList?: boolean) => {
// find the parent list
let messageListElement: HTMLElement | null;
const activeElement = document.activeElement as HTMLElement;
@@ -509,11 +509,12 @@ export function AppChat() {
const currentIndex = messageElements.findIndex(el => el.contains(activeElement));
// if going down and we're at/past the last message, scroll to bottom
const snapToBottom = direction > 0 && (currentIndex === -1 || currentIndex >= messageElements.length - 1);
const nextIndex = snapToBottom ? messageElements.length - 1
: (isAtBottom && direction < 0) ? currentIndex
: currentIndex === -1 ? (direction < 0 ? 0 : messageElements.length - 1)
: currentIndex + direction;
const snapToBottom = direction > 0 && (wholeList || (currentIndex === -1 || currentIndex >= messageElements.length - 1));
const nextIndex = (wholeList && direction < 0) ? 0
: snapToBottom ? messageElements.length - 1
: (isAtBottom && direction < 0) ? currentIndex
: currentIndex === -1 ? (direction < 0 ? 0 : messageElements.length - 1)
: currentIndex + direction;
if (nextIndex < 0 || nextIndex >= messageElements.length) return;
// perform the smooth scroll and focus
@@ -536,6 +537,8 @@ export function AppChat() {
// change active message (in any possible panel)
{ key: ShortcutKey.Up, ctrl: true, action: () => handleMoveFocus(-1) },
{ key: ShortcutKey.Down, ctrl: true, action: () => handleMoveFocus(1) },
{ key: ShortcutKey.Up, ctrl: true, shift: true, action: () => handleMoveFocus(-1, true) },
{ key: ShortcutKey.Down, ctrl: true, shift: true, action: () => handleMoveFocus(1, true) },
// open the dropdowns
{ key: 'l', ctrl: true, action: () => llmDropdownRef.current?.openListbox() /*, description: 'Open Models Dropdown'*/ },
{ key: 'p', ctrl: true, action: () => personaDropdownRef.current?.openListbox() /*, description: 'Open Persona Dropdown'*/ },
+2 -2
View File
@@ -28,8 +28,8 @@ const shortcutsMd = platformAwareKeystrokes(`
| Ctrl + Shift + N | **New** chat |
| Ctrl + Shift + X | **Reset** chat |
| Ctrl + Shift + D | **Delete** chat |
| Ctrl + Up | Previous message |
| Ctrl + Down | Next message |
| Ctrl + Up | Previous message (hold shift for top) |
| Ctrl + Down | Next message (hold shift to bottom) |
| Ctrl + [ | **Previous** chat (in history) |
| Ctrl + ] | **Next** chat (in history) |
| **Settings** | |
@@ -14,6 +14,8 @@ export const ShortcutKey = {
Right: 'ArrowRight',
Up: 'ArrowUp',
Down: 'ArrowDown',
PageUp: 'PageUp',
PageDown: 'PageDown',
};
export interface ShortcutObject {