diff --git a/renderer/src/components/EditorPage/TextEditor/Editor.jsx b/renderer/src/components/EditorPage/TextEditor/Editor.jsx
index 03c1ad86e..ed9587b29 100644
--- a/renderer/src/components/EditorPage/TextEditor/Editor.jsx
+++ b/renderer/src/components/EditorPage/TextEditor/Editor.jsx
@@ -1,5 +1,5 @@
import React, {
- useContext, useEffect, useLayoutEffect, useRef,
+ useContext, useEffect, useLayoutEffect, useRef,
} from 'react';
import { HtmlPerfEditor } from '@xelah/type-perf-html';
@@ -123,7 +123,7 @@ export default function Editor(props) {
function onReferenceSelected({ chapter, verse }) {
chapter && setChapterNumber(chapter);
verse && setVerseNumber(verse);
- scrollReference(chapter);
+ scrollReference(chapter, verse);
}
const observer = new IntersectionObserver((entries) => onIntersection({
diff --git a/renderer/src/components/EditorPage/TextEditor/RecursiveBlock.jsx b/renderer/src/components/EditorPage/TextEditor/RecursiveBlock.jsx
index 17e7f36f3..3d31b40e9 100644
--- a/renderer/src/components/EditorPage/TextEditor/RecursiveBlock.jsx
+++ b/renderer/src/components/EditorPage/TextEditor/RecursiveBlock.jsx
@@ -40,27 +40,6 @@ export default function RecursiveBlock({
setCaretPosition(cursorPosition);
};
- const checkReturnKeyPress = (event) => {
- const activeTextArea = document.activeElement;
- if (event.key === 'Enter') {
- if (activeTextArea.children.length > 1) {
- const lineBreak = activeTextArea.children[1]?.outerHTML;
- activeTextArea.children[1].outerHTML = lineBreak.replace(/
/gi, ' ');
- }
- }
- // BACKSPACE DISABLE
- if (event.keyCode === 8) {
- const range = document.getSelection().getRangeAt(0);
- const selectedNode = range.startContainer;
- const prevNode = selectedNode.previousSibling;
- if (prevNode && prevNode.dataset.attsNumber !== currentVerse) {
- event.preventDefault();
- }
- prevNode ? setCurrentVerse(prevNode.dataset.attsNumber) : {};
- }
- updateCursorPosition();
- };
-
function handleSelection() {
let selectedText = '';
if (window.getSelection) {
@@ -85,6 +64,29 @@ export default function RecursiveBlock({
handleSelection();
};
+ const keyStrokeHandler = (event) => {
+ const activeTextArea = document.activeElement;
+ // Replace line break with space
+ if (event.key === 'Enter') {
+ if (activeTextArea.children.length > 1) {
+ const lineBreak = activeTextArea.children[1]?.outerHTML;
+ activeTextArea.children[1].outerHTML = lineBreak.replace(/
/gi, ' ');
+ }
+ }
+ // Disable backspace if the previous node is not the same verse
+ if (event.keyCode === 8) {
+ const range = document.getSelection().getRangeAt(0);
+ const selectedNode = range.startContainer;
+ const prevNode = selectedNode.previousSibling;
+ if (prevNode && prevNode.dataset.attsNumber !== currentVerse) {
+ event.preventDefault();
+ }
+ prevNode ? setCurrentVerse(prevNode.dataset.attsNumber) : {};
+ }
+ checkCurrentVerse();
+ updateCursorPosition();
+ };
+
function onPasteHandler(event) {
const cursorPosition = getCurrentCursorPosition('editor');
const paste = (event.clipboardData || window.clipboardData).getData('text');
@@ -101,11 +103,11 @@ export default function RecursiveBlock({