Skip to content

ctrl-shift state fix + add new keybindings to docs #1792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/docs/keybindings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ replace "Cmd" with "Alt" (note that "Ctrl" is "Ctrl" on both Mac, Windows, and L
| <Kbd k="Cmd:]"/> | Switch tab right |
| <Kbd k="Cmd:Ctrl:1-9"/> | Switch to workspace number |
| <Kbd k="Cmd:Shift:r"/> | Refresh the UI |
| <Kbd k="Ctrl:Shift:i"/> | Toggle terminal multi-input mode |

## File Preview Keybindings

Expand All @@ -64,6 +65,7 @@ replace "Cmd" with "Alt" (note that "Ctrl" is "Ctrl" on both Mac, Windows, and L
| <Kbd k="Cmd:r"/> | Reload webpage |
| <Kbd k="Cmd:ArrowLeft"/> | Back |
| <Kbd k="Cmd:ArrowRight"/> | Forward |
| <Kbd k="Cmd:f"/> | Find in webpage |

## WaveAI Keybindings

Expand All @@ -73,11 +75,12 @@ replace "Cmd" with "Alt" (note that "Ctrl" is "Ctrl" on both Mac, Windows, and L

## Terminal Keybindings

| Key | Function |
| ----------------------- | -------------- |
| <Kbd k="Ctrl:Shift:c"/> | Copy |
| <Kbd k="Ctrl:Shift:v"/> | Paste |
| <Kbd k="Cmd:k"/> | Clear Terminal |
| Key | Function |
| ----------------------- | ---------------- |
| <Kbd k="Ctrl:Shift:c"/> | Copy |
| <Kbd k="Ctrl:Shift:v"/> | Paste |
| <Kbd k="Cmd:k"/> | Clear Terminal |
| <Kbd k="Cmd:f"/> | Find in Terminal |

## Customizeable Systemwide Global Hotkey

Expand Down
9 changes: 9 additions & 0 deletions emain/emain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import { getWebServerEndpoint } from "../frontend/util/endpoints";

export const WaveAppPathVarName = "WAVETERM_APP_PATH";

// not necessarily exact, but we use this to help get us unstuck in certain cases
let lastCtrlShiftSate: boolean = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in variable name.

The variable name contains a typo: lastCtrlShiftSate should be lastCtrlShiftState.

-let lastCtrlShiftSate: boolean = false;
+let lastCtrlShiftState: boolean = false;

Committable suggestion skipped: line range outside the PR's diff.


export function delay(ms): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

function setCtrlShift(wc: Electron.WebContents, state: boolean) {
lastCtrlShiftSate = state;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in variable usage.

The same typo appears in the variable usage.

-    lastCtrlShiftSate = state;
+    lastCtrlShiftState = state;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
lastCtrlShiftSate = state;
lastCtrlShiftState = state;

wc.send("control-shift-state-update", state);
}

Expand All @@ -30,6 +34,11 @@ export function handleCtrlShiftState(sender: Electron.WebContents, waveEvent: Wa
setCtrlShift(sender, true);
}
}
if (lastCtrlShiftSate) {
if (!waveEvent.control || !waveEvent.shift) {
setCtrlShift(sender, false);
}
}
return;
}
if (waveEvent.type == "keydown") {
Expand Down
4 changes: 3 additions & 1 deletion frontend/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PLATFORM,
removeFlashError,
} from "@/store/global";
import { appHandleKeyDown } from "@/store/keymodel";
import { appHandleKeyDown, keyboardMouseDownHandler } from "@/store/keymodel";
import { getElemAsStr } from "@/util/focusutil";
import * as keyutil from "@/util/keyutil";
import * as util from "@/util/util";
Expand Down Expand Up @@ -193,9 +193,11 @@ const AppKeyHandlers = () => {
useEffect(() => {
const staticKeyDownHandler = keyutil.keydownWrapper(appHandleKeyDown);
document.addEventListener("keydown", staticKeyDownHandler);
document.addEventListener("mousedown", keyboardMouseDownHandler);

return () => {
document.removeEventListener("keydown", staticKeyDownHandler);
document.removeEventListener("mousedown", keyboardMouseDownHandler);
};
}, []);
return null;
Expand Down
6 changes: 6 additions & 0 deletions frontend/app/store/keymodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ import * as jotai from "jotai";
const simpleControlShiftAtom = jotai.atom(false);
const globalKeyMap = new Map<string, (waveEvent: WaveKeyboardEvent) => boolean>();

export function keyboardMouseDownHandler(e: MouseEvent) {
if (!e.ctrlKey || !e.shiftKey) {
unsetControlShift();
}
}

function getFocusedBlockInStaticTab() {
const tabId = globalStore.get(atoms.staticTabId);
const layoutModel = getLayoutModelForTabById(tabId);
Expand Down
Loading