Skip to content
Snippets Groups Projects
Commit 22f7c0de authored by chris's avatar chris
Browse files

fix transform case text selection

parent 3852b6ba
No related branches found
No related tags found
1 merge request!290fix transform case text selection
......@@ -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: () => {
......
......@@ -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);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment