Skip to content

Commit

Permalink
Fix for weirdness when pasting sefaria links into an empty spacer node
Browse files Browse the repository at this point in the history
  • Loading branch information
rneiss committed Apr 25, 2022
1 parent 77dcf6b commit d8c67a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion static/js/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,12 @@ const withSefariaSheet = editor => {
return
}
const link = editor.createLinkNode(url.href, matches[1])
Transforms.insertText(editor, " ") // this is start of dance that's required to ensure that link gets inserted properly
const initLoc = editor.selection
Transforms.insertNodes(editor, link);
Transforms.select(editor, initLoc); // dance ii
Transforms.move(editor, { distance: 1, unit: 'character', reverse: true }) // dance dance dance
Transforms.delete(editor); // end of dance
},
error: function (e) {
Transforms.insertText(editor, url.href)
Expand All @@ -1419,12 +1424,12 @@ const withSefariaSheet = editor => {
}

else {
console.log('not sef link')
insertData(data)
}

} catch {
insertData(data)
return false;
}
}

Expand Down Expand Up @@ -1554,6 +1559,7 @@ const withSefariaSheet = editor => {
editor.convertEmptyParagraphToSpacer = (node, path) => {
if (node.type === "paragraph") {
if (Node.string(node) === "" && node.children.length <= 1) {
console.log('spacer?')
Transforms.setNodes(editor, {type: "spacer"}, {at: path});
}
}
Expand Down

0 comments on commit d8c67a8

Please sign in to comment.