caretPosition: Invert condition in getPosition() for readability

This commit is contained in:
Richard Hansen 2021-02-22 02:17:49 -05:00 committed by John McLear
parent 773959ec57
commit 02fd0048bf

View file

@ -4,12 +4,10 @@
// This function is useful to get the caret position of the line as
// is represented by the browser
exports.getPosition = () => {
let rect, line;
const range = getSelectionRange();
const isSelectionInsideTheEditor = range &&
$(range.endContainer).closest('body')[0].id === 'innerdocbody';
if (!range || $(range.endContainer).closest('body')[0].id !== 'innerdocbody') return null;
let rect, line;
if (isSelectionInsideTheEditor) {
// 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;
@ -34,7 +32,6 @@ exports.getPosition = () => {
clonedRange.detach();
shadowCaret.remove();
}
}
return line;
};