feat: Cmd-A inside code block should select block contents, closes #6498

This commit is contained in:
Tom Moor
2024-02-06 20:44:38 -05:00
parent 7bf403356a
commit 68d4041b1c
4 changed files with 51 additions and 2 deletions

View File

@@ -0,0 +1,39 @@
import { NodeType } from "prosemirror-model";
import { Command, TextSelection } from "prosemirror-state";
import { findParentNode } from "../queries/findParentNode";
/**
* Selects all the content of the given node type.
*
* @param type The node type
* @returns A prosemirror command.
*/
export function selectAll(type: NodeType): Command {
return (state, dispatch) => {
const code = findParentNode((node) => node.type === type)(state.selection);
if (code) {
const start = code.pos;
const end = code.pos + code.node.nodeSize;
if (
start === state.selection.from - 1 &&
end === state.selection.to + 1
) {
return false;
}
dispatch?.(
state.tr.setSelection(
TextSelection.between(
state.doc.resolve(start),
state.doc.resolve(end)
)
)
);
return true;
}
return false;
};
}