Skip to content
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
7 changes: 3 additions & 4 deletions demos/platform/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,9 @@ export default function App() {
</button>
</div>
</span>
<button onClick={() => setIsNoteEditorVisible(!isNoteEditorVisible)}>
{isNoteEditorVisible ? "Hide" : "Show"} note editor
</button>
<pre style={{ color: "black" }}>{contextMarker}</pre>
<pre title="contextMarker" style={{ color: "black" }}>
{contextMarker}
</pre>
</div>
{isOptionsDefined && (
<>
Expand Down
1 change: 0 additions & 1 deletion libs/shared-react/src/plugins/usj/CommandMenuPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LoggerBasic } from "shared";

/**
* This plugin prevents the backslash or forward slash key from being typed, or pasted or dragged.
* Later this plugin will open the command menu to insert USJ elements.
* @returns `null`. This plugin has no DOM presence.
*/
export function CommandMenuPlugin({ logger }: { logger?: LoggerBasic }): null {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { IS_APPLE } from "@lexical/utils";
import { COMMAND_PRIORITY_CRITICAL, KEY_DOWN_COMMAND } from "lexical";
import { useEffect } from "react";

/**
* Prevent undo and redo keyboard shortcuts while preserving command-based undo/redo.
* @returns `null`. This plugin has no DOM presence.
*/
export function DisableHistoryShortcutsPlugin(): null {
const [editor] = useLexicalComposerContext();

useEffect(() => {
return editor.registerCommand(
KEY_DOWN_COMMAND,
(event: KeyboardEvent) => {
const { key, shiftKey, metaKey, ctrlKey, altKey } = event;
if (!(IS_APPLE ? metaKey : ctrlKey) || altKey) return false;

const normalizedKey = key.toLowerCase();
const isUndo = normalizedKey === "z" && !shiftKey;
const isRedo = normalizedKey === "y" || (normalizedKey === "z" && shiftKey);

if (!isUndo && !isRedo) return false;

event.preventDefault();
return true;
},
COMMAND_PRIORITY_CRITICAL,
);
}, [editor]);

return null;
}
1 change: 1 addition & 0 deletions libs/shared-react/src/plugins/usj/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "./clipboard.utils";
export * from "./ClipboardPlugin";
export * from "./CommandMenuPlugin";
export * from "./ContextMenuPlugin";
export * from "./DisableHistoryShortcutsPlugin";
export * from "./EditablePlugin";
export * from "./LoadStatePlugin";
export * from "./NoteNodePlugin";
Expand Down
4 changes: 3 additions & 1 deletion packages/platform/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
ContextMenuPlugin,
DeltaOnChangePlugin,
DeltaOp,
DisableHistoryShortcutsPlugin,
EditablePlugin,
getDefaultViewOptions,
getInsertedNodeKey,
Expand Down Expand Up @@ -362,11 +363,12 @@ const Editor = forwardRef(function Editor<TLogger extends LoggerBasic>(
placeholder={<Placeholder />}
ErrorBoundary={LexicalErrorBoundary}
/>
{hasExternalUI && <DisableHistoryShortcutsPlugin />}
<HistoryPlugin />
{scrRef && onScrRefChange && (
<ScriptureReferencePlugin scrRef={scrRef} onScrRefChange={onScrRefChange} />
)}
{scrRef && (
{scrRef && !hasExternalUI && (
<UsjNodesMenuPlugin
trigger={markerMenuTrigger}
scrRef={scrRef}
Expand Down
Loading