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 // This function is useful to get the caret position of the line as
// is represented by the browser // is represented by the browser
exports.getPosition = () => { exports.getPosition = () => {
let rect, line;
const range = getSelectionRange(); const range = getSelectionRange();
const isSelectionInsideTheEditor = range && if (!range || $(range.endContainer).closest('body')[0].id !== 'innerdocbody') return null;
$(range.endContainer).closest('body')[0].id === 'innerdocbody'; let rect, line;
if (isSelectionInsideTheEditor) {
// when we have the caret in an empty line, e.g. a line with only a <br>, // when we have the caret in an empty line, e.g. a line with only a <br>,
// getBoundingClientRect() returns all dimensions value as 0 // getBoundingClientRect() returns all dimensions value as 0
const selectionIsInTheBeginningOfLine = range.endOffset > 0; const selectionIsInTheBeginningOfLine = range.endOffset > 0;
@ -34,7 +32,6 @@ exports.getPosition = () => {
clonedRange.detach(); clonedRange.detach();
shadowCaret.remove(); shadowCaret.remove();
} }
}
return line; return line;
}; };