Skip to content

Commit 81f6fe2

Browse files
committed
platform: disable more UI controls
- if `hasExternalUI` then undo & redo keyboard shortcuts are disabled. - if `hasExternalUI` then the marker menu is disabled.
1 parent a7c90a6 commit 81f6fe2

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

demos/platform/src/app/app.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,9 @@ export default function App() {
399399
</button>
400400
</div>
401401
</span>
402-
<button onClick={() => setIsNoteEditorVisible(!isNoteEditorVisible)}>
403-
{isNoteEditorVisible ? "Hide" : "Show"} note editor
404-
</button>
405-
<pre style={{ color: "black" }}>{contextMarker}</pre>
402+
<pre title="contextMarker" style={{ color: "black" }}>
403+
{contextMarker}
404+
</pre>
406405
</div>
407406
{isOptionsDefined && (
408407
<>

libs/shared-react/src/plugins/usj/CommandMenuPlugin.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { LoggerBasic } from "shared";
66

77
/**
88
* This plugin prevents the backslash or forward slash key from being typed, or pasted or dragged.
9-
* Later this plugin will open the command menu to insert USJ elements.
109
* @returns `null`. This plugin has no DOM presence.
1110
*/
1211
export function CommandMenuPlugin({ logger }: { logger?: LoggerBasic }): null {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2+
import { IS_APPLE } from "@lexical/utils";
3+
import { COMMAND_PRIORITY_CRITICAL, KEY_DOWN_COMMAND } from "lexical";
4+
import { useEffect } from "react";
5+
6+
/**
7+
* Prevent undo and redo keyboard shortcuts while preserving command-based undo/redo.
8+
* @returns `null`. This plugin has no DOM presence.
9+
*/
10+
export function DisableHistoryShortcutsPlugin(): null {
11+
const [editor] = useLexicalComposerContext();
12+
13+
useEffect(() => {
14+
return editor.registerCommand(
15+
KEY_DOWN_COMMAND,
16+
(event: KeyboardEvent) => {
17+
const { key, shiftKey, metaKey, ctrlKey, altKey } = event;
18+
if (!(IS_APPLE ? metaKey : ctrlKey) || altKey) return false;
19+
20+
const normalizedKey = key.toLowerCase();
21+
const isUndo = normalizedKey === "z" && !shiftKey;
22+
const isRedo = normalizedKey === "y" || (normalizedKey === "z" && shiftKey);
23+
24+
if (!isUndo && !isRedo) return false;
25+
26+
event.preventDefault();
27+
return true;
28+
},
29+
COMMAND_PRIORITY_CRITICAL,
30+
);
31+
}, [editor]);
32+
33+
return null;
34+
}

libs/shared-react/src/plugins/usj/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from "./clipboard.utils";
77
export * from "./ClipboardPlugin";
88
export * from "./CommandMenuPlugin";
99
export * from "./ContextMenuPlugin";
10+
export * from "./DisableHistoryShortcutsPlugin";
1011
export * from "./EditablePlugin";
1112
export * from "./LoadStatePlugin";
1213
export * from "./NoteNodePlugin";

packages/platform/src/editor/Editor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
ContextMenuPlugin,
6565
DeltaOnChangePlugin,
6666
DeltaOp,
67+
DisableHistoryShortcutsPlugin,
6768
EditablePlugin,
6869
getDefaultViewOptions,
6970
getInsertedNodeKey,
@@ -362,11 +363,12 @@ const Editor = forwardRef(function Editor<TLogger extends LoggerBasic>(
362363
placeholder={<Placeholder />}
363364
ErrorBoundary={LexicalErrorBoundary}
364365
/>
366+
{hasExternalUI && <DisableHistoryShortcutsPlugin />}
365367
<HistoryPlugin />
366368
{scrRef && onScrRefChange && (
367369
<ScriptureReferencePlugin scrRef={scrRef} onScrRefChange={onScrRefChange} />
368370
)}
369-
{scrRef && (
371+
{scrRef && !hasExternalUI && (
370372
<UsjNodesMenuPlugin
371373
trigger={markerMenuTrigger}
372374
scrRef={scrRef}

0 commit comments

Comments
 (0)