mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 01:16:15 -04:00
pad_editor: Invert focusOnLine()
conditions to improve readability
This commit is contained in:
parent
373d4fb0fb
commit
e22639edac
1 changed files with 35 additions and 40 deletions
|
@ -165,46 +165,41 @@ exports.padeditor = padeditor;
|
||||||
exports.focusOnLine = (ace) => {
|
exports.focusOnLine = (ace) => {
|
||||||
// If a number is in the URI IE #L124 go to that line number
|
// If a number is in the URI IE #L124 go to that line number
|
||||||
const lineNumber = window.location.hash.substr(1);
|
const lineNumber = window.location.hash.substr(1);
|
||||||
if (lineNumber) {
|
if (!lineNumber || lineNumber[0] !== 'L') return;
|
||||||
if (lineNumber[0] === 'L') {
|
const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody');
|
||||||
const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody');
|
const lineNumberInt = parseInt(lineNumber.substr(1));
|
||||||
const lineNumberInt = parseInt(lineNumber.substr(1));
|
if (!lineNumberInt) return;
|
||||||
if (lineNumberInt) {
|
const $inner = $('iframe[name="ace_outer"]').contents().find('iframe')
|
||||||
const $inner = $('iframe[name="ace_outer"]').contents().find('iframe')
|
.contents().find('#innerdocbody');
|
||||||
.contents().find('#innerdocbody');
|
const line = $inner.find(`div:nth-child(${lineNumberInt})`);
|
||||||
const line = $inner.find(`div:nth-child(${lineNumberInt})`);
|
if (line.length === 0) return;
|
||||||
if (line.length !== 0) {
|
let offsetTop = line.offset().top;
|
||||||
let offsetTop = line.offset().top;
|
offsetTop += parseInt($outerdoc.css('padding-top').replace('px', ''));
|
||||||
offsetTop += parseInt($outerdoc.css('padding-top').replace('px', ''));
|
const hasMobileLayout = $('body').hasClass('mobile-layout');
|
||||||
const hasMobileLayout = $('body').hasClass('mobile-layout');
|
if (!hasMobileLayout) {
|
||||||
if (!hasMobileLayout) {
|
offsetTop += parseInt($inner.css('padding-top').replace('px', ''));
|
||||||
offsetTop += parseInt($inner.css('padding-top').replace('px', ''));
|
|
||||||
}
|
|
||||||
const $outerdocHTML = $('iframe[name="ace_outer"]').contents()
|
|
||||||
.find('#outerdocbody').parent();
|
|
||||||
$outerdoc.css({top: `${offsetTop}px`}); // Chrome
|
|
||||||
$outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF
|
|
||||||
const node = line[0];
|
|
||||||
ace.callWithAce((ace) => {
|
|
||||||
const selection = {
|
|
||||||
startPoint: {
|
|
||||||
index: 0,
|
|
||||||
focusAtStart: true,
|
|
||||||
maxIndex: 1,
|
|
||||||
node,
|
|
||||||
},
|
|
||||||
endPoint: {
|
|
||||||
index: 0,
|
|
||||||
focusAtStart: true,
|
|
||||||
maxIndex: 1,
|
|
||||||
node,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
ace.ace_setSelection(selection);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const $outerdocHTML = $('iframe[name="ace_outer"]').contents()
|
||||||
|
.find('#outerdocbody').parent();
|
||||||
|
$outerdoc.css({top: `${offsetTop}px`}); // Chrome
|
||||||
|
$outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF
|
||||||
|
const node = line[0];
|
||||||
|
ace.callWithAce((ace) => {
|
||||||
|
const selection = {
|
||||||
|
startPoint: {
|
||||||
|
index: 0,
|
||||||
|
focusAtStart: true,
|
||||||
|
maxIndex: 1,
|
||||||
|
node,
|
||||||
|
},
|
||||||
|
endPoint: {
|
||||||
|
index: 0,
|
||||||
|
focusAtStart: true,
|
||||||
|
maxIndex: 1,
|
||||||
|
node,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ace.ace_setSelection(selection);
|
||||||
|
});
|
||||||
// End of setSelection / set Y position of editor
|
// End of setSelection / set Y position of editor
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue