Skip to content

Commit

Permalink
Was doing too much (#6724)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzach83 authored and ilijabojanovic committed Feb 14, 2024
1 parent 41bf149 commit 7f4eba0
Showing 1 changed file with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,20 @@ export const useNotionPaste = (setContentDelta, contentDelta, editorRef) => {
event.preventDefault();
const editor = editorRef.current?.getEditor();
const pastedText = event.clipboardData.getData('text/plain');

if (pastedText) {
const lines = pastedText.split('\n');
const fixedLines = lines.map((line) => {
if (line.trim().startsWith('[ ]')) {
return `- ${line.trim()}`;
}
return line;
setContentDelta({
ops: [
{
insert: pastedText,
},
],
});
const fixedText = fixedLines.join('\n');

if (fixedText !== contentDelta.ops[0]?.insert) {
setContentDelta((prevDelta) => ({
...prevDelta,
ops: [
...prevDelta.ops,
{
insert: fixedText,
},
],
}));

//Setting a delay to reset cursor position
setTimeout(() => {
const newCursorPosition = editor.getLength();
editor.setSelection(newCursorPosition, newCursorPosition);
}, 10);
}
setTimeout(() => {
const newCursorPosition = editor.getLength();
editor.setSelection(newCursorPosition, newCursorPosition);
}, 10);
return;
}
};

Expand Down

0 comments on commit 7f4eba0

Please sign in to comment.