Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Selection): made all top-level nodes selectable #533

Merged
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
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 @@ -55,6 +55,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 !== false && 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
Loading