Skip to content

Commit

Permalink
feat(EditorView): add selectable nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
whiteformed committed Dec 20, 2024
1 parent 89c9881 commit d25bc11
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/extensions/additional/Math/MathSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const MathSpecs: ExtensionAuto = (builder) => {
code: true,
toDOM: () => ['div', {class: 'math-block'}, 0],
parseDOM: [{tag: 'div.math-block', priority: 200}],
selectable: true,
},
fromMd: {
tokenName: 'math_block',
Expand Down
1 change: 1 addition & 0 deletions src/extensions/base/BaseSchema/BaseSchemaSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder,
0,
];
},
selectable: true,
placeholder: opts.paragraphPlaceholder
? {
content: opts.paragraphPlaceholder,
Expand Down
12 changes: 5 additions & 7 deletions src/extensions/behavior/Selection/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,16 @@ const getTopLevelNodesFromSelection = (selection: Selection, doc: Node) => {
const nodes: {node: Node; pos: number}[] = [];
if (selection.from !== selection.to) {
const {from, to} = selection;

doc.nodesBetween(from, to, (node, pos) => {
const withinSelection = from <= pos && pos + node.nodeSize <= to;
if (
node &&
node.type.name !== 'paragraph' &&
!node.isText &&
node.type.spec.selectable &&
withinSelection
) {

if (node && !node.isText && node.type.spec.selectable && withinSelection) {
nodes.push({node, pos});

return false;
}

return true;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const BlockquoteSpecs: ExtensionAuto = (builder) => {
toDOM() {
return ['blockquote', 0];
},
selectable: true,
},
fromMd: {tokenSpec: {name: blockquoteNodeName, type: 'block'}},
toMd: (state, node) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const HorizontalRuleSpecs: ExtensionAuto = (builder) => {
toDOM() {
return ['div', ['hr']];
},
selectable: true,
},
fromMd: {
tokenName: 'hr',
Expand Down
1 change: 1 addition & 0 deletions src/extensions/yfm/YfmTabs/YfmTabsSpecs/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const getSchemaSpecs: (
toDOM(node) {
return ['div', node.attrs, 0];
},
selectable: true,
complex: 'root',
},

Expand Down

0 comments on commit d25bc11

Please sign in to comment.