From 91955609af92480d8dd74889d233982c2ca03f97 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 22 Feb 2021 02:24:04 -0500 Subject: [PATCH] caretPosition: Delete pointless logic in `getPosition()` The `line` variable is unconditionally overwritten later, and the function calls do not have side effects, so it is safe to delete this logic. --- src/static/js/caretPosition.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/static/js/caretPosition.js b/src/static/js/caretPosition.js index 2b80b9879..1149b54bb 100644 --- a/src/static/js/caretPosition.js +++ b/src/static/js/caretPosition.js @@ -6,15 +6,6 @@ exports.getPosition = () => { const range = getSelectionRange(); if (!range || $(range.endContainer).closest('body')[0].id !== 'innerdocbody') return null; - let line; - - // when we have the caret in an empty line, e.g. a line with only a
, - // getBoundingClientRect() returns all dimensions value as 0 - const selectionIsInTheBeginningOfLine = range.endOffset > 0; - if (selectionIsInTheBeginningOfLine) { - const clonedRange = createSelectionRange(range); - line = getPositionOfElementOrSelection(clonedRange); - } // when there's a
or any element that has no height, we can't get // the dimension of the element where the caret is @@ -26,7 +17,7 @@ exports.getPosition = () => { clonedRange.insertNode(shadowCaret[0]); clonedRange.selectNode(shadowCaret[0]); - line = getPositionOfElementOrSelection(clonedRange); + const line = getPositionOfElementOrSelection(clonedRange); shadowCaret.remove(); return line; };