diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js index 243a0ed5e7385dd89a509b74e7b65315e128b186..e0f812867b9c535ddf25d849fc7fc8efb0da91ee 100644 --- a/wax-prosemirror-services/src/NoteService/Editor.js +++ b/wax-prosemirror-services/src/NoteService/Editor.js @@ -39,11 +39,15 @@ export default ({ node, view }) => { dispatchTransaction, handleDOMEvents: { blur: () => { - context.view[noteId].dispatch( - context.view[noteId].state.tr.setSelection( - new TextSelection(context.view[noteId].state.tr.doc.resolve(0)), - ), - ); + if (context.view[noteId]) { + context.view[noteId].dispatch( + context.view[noteId].state.tr.setSelection( + new TextSelection( + context.view[noteId].state.tr.doc.resolve(0), + ), + ), + ); + } }, mousedown: () => { diff --git a/wax-prosemirror-services/src/TransformService/TransformTool.js b/wax-prosemirror-services/src/TransformService/TransformTool.js index d5e0ea90cdde1f89e95e26d60389a4101d5a289e..6c9525f308f7a0e22933c79e9626befa7ffa9f11 100644 --- a/wax-prosemirror-services/src/TransformService/TransformTool.js +++ b/wax-prosemirror-services/src/TransformService/TransformTool.js @@ -37,8 +37,9 @@ const upperLowerCase = (state, dispatch, casing) => { // grab the content const substringFrom = Math.max(0, selection.from - position - 1); const substringTo = Math.max(0, selection.to - position - 1); - const updatedText = node.textContent.substring(substringFrom, substringTo); - + const updatedText = node.textBetween(substringFrom, substringTo); + console.log(node.textBetween(substringFrom, substringTo)); + console.log(node.textContent.substring(substringFrom - 1, substringTo - 1)); // set the casing const textNode = casing === 'upperCase' @@ -107,10 +108,8 @@ class TransformTool extends Tools { const substringFrom = Math.max(0, $from.pos - position - 1); const substringTo = Math.max(0, selection.to - position - 1); - const updatedText = node.textContent.substring( - substringFrom, - substringTo, - ); + const updatedText = node.textBetween(substringFrom, substringTo); + if (updatedText.length > 0) { const rg = /(^\w{1}|\.\s*\w{1})/gi; @@ -159,10 +158,8 @@ class TransformTool extends Tools { const substringFrom = Math.max(0, $from.pos - position - 1); const substringTo = Math.max(0, selection.to - position - 1); - const updatedText = node.textContent.substring( - substringFrom, - substringTo, - ); + const updatedText = node.textBetween(substringFrom, substringTo); + if (updatedText.length > 0) { const textNode = state.schema.text(updatedText.toTitleCase()); tr.replaceWith(startPosition, endPosition, textNode);