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.
This commit is contained in:
Richard Hansen 2021-02-22 02:24:04 -05:00 committed by John McLear
parent 1dbdaf93d7
commit 91955609af

View file

@ -6,15 +6,6 @@
exports.getPosition = () => { exports.getPosition = () => {
const range = getSelectionRange(); const range = getSelectionRange();
if (!range || $(range.endContainer).closest('body')[0].id !== 'innerdocbody') return null; 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 <br>,
// 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 <br> or any element that has no height, we can't get // when there's a <br> or any element that has no height, we can't get
// the dimension of the element where the caret is // the dimension of the element where the caret is
@ -26,7 +17,7 @@ exports.getPosition = () => {
clonedRange.insertNode(shadowCaret[0]); clonedRange.insertNode(shadowCaret[0]);
clonedRange.selectNode(shadowCaret[0]); clonedRange.selectNode(shadowCaret[0]);
line = getPositionOfElementOrSelection(clonedRange); const line = getPositionOfElementOrSelection(clonedRange);
shadowCaret.remove(); shadowCaret.remove();
return line; return line;
}; };