Skip to content

Commit

Permalink
[editor] Handle CMD/CTRL + S to Save
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Holinshead committed Jan 3, 2024
1 parent 64b1af1 commit 455cdc5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,27 @@ export default function EditorContainer({
return () => clearInterval(saveInterval);
}, [isDirty, onSave]);

// Override CMD+s and CTRL+s to save
useEffect(() => {
const saveHandler = (e: KeyboardEvent) => {
// Note platform property to distinguish between CMD and CTRL for
// Mac/Windows/Linux is deprecated.
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform
// Just handle both for now.
if (e.key === "s" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();

if (stateRef.current._ui.isDirty) {
onSave();
}
}
};

window.addEventListener("keydown", saveHandler, false);

return () => window.removeEventListener("keydown", saveHandler);
}, [onSave]);

return (
<AIConfigContext.Provider value={contextValue}>
<Notifications />
Expand Down
3 changes: 3 additions & 0 deletions python/src/aiconfig/editor/travel.aiconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
{
"name": "get_activities",
"input": "Tell me 10 fun attractions to do in NYC.",
"metadata": {
"parameters": {}
},
"outputs": [
{
"output_type": "execute_result",
Expand Down

0 comments on commit 455cdc5

Please sign in to comment.