mirror of
https://github.com/outline/outline.git
synced 2026-12-06 19:22:29 +03:00
Add keyboard access to mermaid diagram editing (#11834)
This commit is contained in:
1 parent
fa17f78ae6
commit
a0039b2a09
3 files changed
+28
-1
No files matched your search
@@ -443,8 +443,8 @@ export class Editor extends React.PureComponent<
|
||||
schema: this.schema,
|
||||
doc,
|
||||
plugins: [
|
||||
...this.keymaps,
|
||||
...this.plugins,
|
||||
...this.keymaps,
|
||||
anchorPlugin(),
|
||||
dropCursor({
|
||||
color: this.props.theme.cursor,
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
import { isMermaid } from "@shared/editor/lib/isCode";
|
||||
import type { MenuItem } from "@shared/editor/types";
|
||||
import type { Dictionary } from "~/hooks/useDictionary";
|
||||
import { metaDisplay } from "@shared/utils/keyboard";
|
||||
|
||||
export default function codeMenuItems(
|
||||
state: EditorState,
|
||||
@@ -67,6 +68,7 @@ export default function codeMenuItems(
|
||||
name: "edit_mermaid",
|
||||
icon: <EditIcon />,
|
||||
tooltip: dictionary.editDiagram,
|
||||
shortcut: `${metaDisplay} Enter`,
|
||||
visible: isMermaid(node) && !isEditingMermaid && !readOnly,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -439,6 +439,31 @@ export default function Mermaid({
|
||||
decorations(state) {
|
||||
return this.getState(state)?.decorationSet;
|
||||
},
|
||||
handleKeyDown(view, event) {
|
||||
if (event.key === "Enter" && event.metaKey && !editor.props.readOnly) {
|
||||
const { selection } = view.state;
|
||||
const isNodeSel = selection instanceof NodeSelection;
|
||||
const isMermaidNode =
|
||||
isNodeSel && isMermaid((selection as NodeSelection).node);
|
||||
if (isNodeSel && isMermaidNode) {
|
||||
editor.commands.edit_mermaid();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.key === "Escape") {
|
||||
const mermaidState = pluginKey.getState(view.state) as MermaidState;
|
||||
const codeBlock = findParentNode(isCode)(view.state.selection);
|
||||
|
||||
if (mermaidState?.editingId) {
|
||||
if (codeBlock && isMermaid(codeBlock.node)) {
|
||||
editor.commands.edit_mermaid();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
handleDOMEvents: {
|
||||
click(_view, event: MouseEvent) {
|
||||
const target = event.target as HTMLElement;
|
||||
|
||||
Reference in new issue
Block a user