pad_editor: Invert focusOnLine() conditions to improve readability

This commit is contained in:
Richard Hansen 2021-04-04 01:54:04 -04:00
parent 373d4fb0fb
commit e22639edac

View file

@ -165,15 +165,14 @@ exports.padeditor = padeditor;
exports.focusOnLine = (ace) => {
// If a number is in the URI IE #L124 go to that line number
const lineNumber = window.location.hash.substr(1);
if (lineNumber) {
if (lineNumber[0] === 'L') {
if (!lineNumber || lineNumber[0] !== 'L') return;
const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody');
const lineNumberInt = parseInt(lineNumber.substr(1));
if (lineNumberInt) {
if (!lineNumberInt) return;
const $inner = $('iframe[name="ace_outer"]').contents().find('iframe')
.contents().find('#innerdocbody');
const line = $inner.find(`div:nth-child(${lineNumberInt})`);
if (line.length !== 0) {
if (line.length === 0) return;
let offsetTop = line.offset().top;
offsetTop += parseInt($outerdoc.css('padding-top').replace('px', ''));
const hasMobileLayout = $('body').hasClass('mobile-layout');
@ -202,9 +201,5 @@ exports.focusOnLine = (ace) => {
};
ace.ace_setSelection(selection);
});
}
}
}
}
// End of setSelection / set Y position of editor
};