Fix number overlay hotkeys conflict with screenshot in macos (#222)

This commit is contained in:
Red J Adaya 2024-08-15 05:38:02 +08:00 committed by GitHub
parent 961502916b
commit 688ed8a870
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 16 deletions

View File

@ -360,28 +360,47 @@ function genericClose(tabId: string) {
services.ObjectService.DeleteBlock(activeBlockId); services.ObjectService.DeleteBlock(activeBlockId);
} }
const simpleCmdShiftAtom = jotai.atom(false); const simpleControlShiftAtom = jotai.atom(false);
const AppKeyHandlers = () => { const AppKeyHandlers = () => {
const tabId = jotai.useAtomValue(atoms.activeTabId); const tabId = jotai.useAtomValue(atoms.activeTabId);
function setControlShift() {
globalStore.set(simpleControlShiftAtom, true);
setTimeout(() => {
const simpleState = globalStore.get(simpleControlShiftAtom);
if (simpleState) {
globalStore.set(atoms.controlShiftDelayAtom, true);
}
}, 400);
}
function unsetControlShift() {
globalStore.set(simpleControlShiftAtom, false);
globalStore.set(atoms.controlShiftDelayAtom, false);
}
function handleKeyUp(event: KeyboardEvent) { function handleKeyUp(event: KeyboardEvent) {
const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(event); const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(event);
if (waveEvent.key == "Control" || waveEvent.key == "Shift") { if (waveEvent.key === "Control" || waveEvent.key === "Shift") {
globalStore.set(simpleCmdShiftAtom, false); unsetControlShift();
globalStore.set(atoms.cmdShiftDelayAtom, false); }
if (waveEvent.key == "Meta") {
if (waveEvent.control && waveEvent.shift) {
setControlShift();
}
} }
} }
function handleKeyDown(waveEvent: WaveKeyboardEvent): boolean { function handleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
if ((waveEvent.key == "Control" || waveEvent.key == "Shift") && waveEvent.control && waveEvent.shift) { if (waveEvent.key === "Control" || waveEvent.key === "Shift" || waveEvent.key === "Meta") {
globalStore.set(simpleCmdShiftAtom, true); if (waveEvent.control && waveEvent.shift && !waveEvent.meta) {
setTimeout(() => { // Set the control and shift without the Meta key
const simpleState = globalStore.get(simpleCmdShiftAtom); setControlShift();
if (simpleState) { } else {
globalStore.set(atoms.cmdShiftDelayAtom, true); // Unset if Meta is pressed
} unsetControlShift();
}, 400); }
return false; return false;
} }

View File

@ -228,7 +228,7 @@ function BlockNum({ blockId }: { blockId: string }) {
} }
const BlockMask = ({ blockId, preview, isFocused }: { blockId: string; preview: boolean; isFocused: boolean }) => { const BlockMask = ({ blockId, preview, isFocused }: { blockId: string; preview: boolean; isFocused: boolean }) => {
const isLayoutMode = jotai.useAtomValue(atoms.cmdShiftDelayAtom); const isLayoutMode = jotai.useAtomValue(atoms.controlShiftDelayAtom);
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId)); const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
const style: React.CSSProperties = {}; const style: React.CSSProperties = {};

View File

@ -103,7 +103,7 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) {
} }
return windowData.activetabid; return windowData.activetabid;
}); });
const cmdShiftDelayAtom = jotai.atom(false); const controlShiftDelayAtom = jotai.atom(false);
const updateStatusAtom = jotai.atom<UpdaterStatus>("up-to-date") as jotai.PrimitiveAtom<UpdaterStatus>; const updateStatusAtom = jotai.atom<UpdaterStatus>("up-to-date") as jotai.PrimitiveAtom<UpdaterStatus>;
try { try {
globalStore.set(updateStatusAtom, getApi().getUpdaterStatus()); globalStore.set(updateStatusAtom, getApi().getUpdaterStatus());
@ -126,7 +126,7 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) {
tabAtom: tabAtom, tabAtom: tabAtom,
activeTabId: activeTabIdAtom, activeTabId: activeTabIdAtom,
isFullScreen: isFullScreenAtom, isFullScreen: isFullScreenAtom,
cmdShiftDelayAtom: cmdShiftDelayAtom, controlShiftDelayAtom: controlShiftDelayAtom,
updaterStatusAtom: updateStatusAtom, updaterStatusAtom: updateStatusAtom,
}; };
} }

View File

@ -16,7 +16,7 @@ declare global {
tabAtom: jotai.Atom<Tab>; // driven from WOS tabAtom: jotai.Atom<Tab>; // driven from WOS
activeTabId: jotai.Atom<string>; // derrived from windowDataAtom activeTabId: jotai.Atom<string>; // derrived from windowDataAtom
isFullScreen: jotai.PrimitiveAtom<boolean>; isFullScreen: jotai.PrimitiveAtom<boolean>;
cmdShiftDelayAtom: jotai.PrimitiveAtom<boolean>; controlShiftDelayAtom: jotai.PrimitiveAtom<boolean>;
updaterStatusAtom: jotai.PrimitiveAtom<UpdaterStatus>; updaterStatusAtom: jotai.PrimitiveAtom<UpdaterStatus>;
}; };