mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
use the helper from scroll.js
This commit is contained in:
parent
7fe37cd49c
commit
b83589fc73
2 changed files with 22 additions and 45 deletions
|
@ -682,7 +682,7 @@ function Ace2Inner() {
|
||||||
editorInfo.ace_doReturnKey = doReturnKey;
|
editorInfo.ace_doReturnKey = doReturnKey;
|
||||||
editorInfo.ace_isBlockElement = isBlockElement;
|
editorInfo.ace_isBlockElement = isBlockElement;
|
||||||
editorInfo.ace_getLineListType = getLineListType;
|
editorInfo.ace_getLineListType = getLineListType;
|
||||||
editorInfo.ace_setSelection = setSelection;
|
editorInfo.ace_scroll = scroll;
|
||||||
|
|
||||||
editorInfo.ace_callWithAce = function (fn, callStack, normalize) {
|
editorInfo.ace_callWithAce = function (fn, callStack, normalize) {
|
||||||
let wrapper = function () {
|
let wrapper = function () {
|
||||||
|
|
|
@ -51,10 +51,9 @@ const padeditor = (function () {
|
||||||
window.location.hash = `L${targetLineNumber}`;
|
window.location.hash = `L${targetLineNumber}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.focusOnLine(self.ace);
|
setTimeout(() => exports.focusOnLine(self.ace), 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ace = new Ace2Editor();
|
self.ace = new Ace2Editor();
|
||||||
self.ace.init('editorcontainer', '', aceReady);
|
self.ace.init('editorcontainer', '', aceReady);
|
||||||
self.ace.setProperty('wraps', true);
|
self.ace.setProperty('wraps', true);
|
||||||
|
@ -175,47 +174,25 @@ 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);
|
let lineNumber = window.location.hash.substr(1);
|
||||||
if (lineNumber) {
|
if (lineNumber && lineNumber[0] === 'L' && (lineNumber = parseInt(lineNumber.substr(1)))) {
|
||||||
if (lineNumber[0] === 'L') {
|
ace.callWithAce((ace) => {
|
||||||
const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody');
|
const rep = ace.ace_getRep();
|
||||||
const lineNumberInt = parseInt(lineNumber.replace('L', ''));
|
if (lineNumber <= 0 || lineNumber - 1 > rep.lines.length()) return;
|
||||||
if (lineNumberInt) {
|
// we assume that rep.lines.atIndex is successful now
|
||||||
const $inner = $('iframe[name="ace_outer"]').contents().find('iframe')
|
|
||||||
.contents().find('#innerdocbody');
|
const lineNode = rep.lines.atIndex(lineNumber - 1).lineNode;
|
||||||
const line = $inner.find(`div:nth-child(${lineNumberInt})`);
|
// offset of the first line and editor space
|
||||||
if (line.length !== 0) {
|
// const editorTop = ace.ace_scroll._getEditorPositionTop();
|
||||||
let offsetTop = line.offset().top;
|
// const firstLineOffset = rep.lines.atIndex(0).lineNode.offsetTop;
|
||||||
offsetTop += parseInt($outerdoc.css('padding-top').replace('px', ''));
|
// ace.ace_scroll.setScrollY(lineNode.offsetTop + editorTop + firstLineOffset);
|
||||||
const hasMobileLayout = $('body').hasClass('mobile-layout');
|
ace.ace_scroll.setScrollY(lineNode.offsetTop);
|
||||||
if (!hasMobileLayout) {
|
|
||||||
offsetTop += parseInt($inner.css('padding-top').replace('px', ''));
|
// place the caret on the beginning of the new line
|
||||||
}
|
// rep.lines.atIndex(lineNumber-1).lineMarker)
|
||||||
const $outerdocHTML = $('iframe[name="ace_outer"]').contents()
|
rep.selEnd = [lineNumber - 1, 0];
|
||||||
.find('#outerdocbody').parent();
|
rep.selStart = [lineNumber - 1, 0];
|
||||||
$outerdoc.css({top: `${offsetTop}px`}); // Chrome
|
ace.ace_updateBrowserSelectionFromRep();
|
||||||
$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
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue