Skip to content

Commit

Permalink
more mac + electron binds
Browse files Browse the repository at this point in the history
  • Loading branch information
jackschedel committed Nov 16, 2024
1 parent ee2dee7 commit 03d689a
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,6 @@ function App() {
setModelDefs(defaultModelDefs);
}

const handleGenerate = () => {
if (useStore.getState().generating) return;
const updatedChats: ChatInterface[] = JSON.parse(
JSON.stringify(useStore.getState().chats)
);
const content = bottomMessageRef?.current?.value;
const updatedMessages = updatedChats[currentChatIndex].messages;
if (!content) {
return;
}

updatedMessages.push({ role: 'user', content: content });
if (bottomMessageRef && bottomMessageRef?.current) {
bottomMessageRef.current.value = '';
}

setChats(updatedChats);
handleSubmit();
};

const pasteSubmit = async () => {
try {
if (useStore.getState().generating) return;
Expand Down Expand Up @@ -157,19 +137,27 @@ function App() {
bottomMessageRef?.current?.focus();
}

// ctrl+s - Save bottom message + generate
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
handleGenerate();
}

// ctrl+p - New chat from clipboard (insta-generate)
if (e.ctrlKey && e.key === 'p') {
e.preventDefault();
addChat();
pasteSubmit();
}

if (isElectron()) {
// ctrl+tab - Next chat
if (e.ctrlKey && e.key === 'Tab') {
e.preventDefault();
goForward();
}

// ctrl+shift+tab + Previous chat
if (e.ctrlKey && e.shiftKey && e.key === 'Tab') {
e.preventDefault();
goBack();
}
}

if (isMac()) {
// ctrl+left - Previous chat
if (e.ctrlKey && e.key === 'ArrowLeft') {
Expand All @@ -182,6 +170,13 @@ function App() {
e.preventDefault();
goForward();
}

// cmd+t (desktop only) - New chat
if (isElectron() && e.metaKey && e.key === 't') {
e.preventDefault();
addChat();
bottomMessageRef?.current?.focus();
}
}
};

Expand Down

0 comments on commit 03d689a

Please sign in to comment.