From a2a7322226549668a1a74948342f328b4dfd2be1 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 10 Dec 2020 23:23:28 +0000 Subject: [PATCH] focus caret at line --- src/static/js/ace2_inner.js | 1 + src/static/js/pad_editor.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 06e8908e3..99fd9795e 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -682,6 +682,7 @@ function Ace2Inner() { editorInfo.ace_doReturnKey = doReturnKey; editorInfo.ace_isBlockElement = isBlockElement; editorInfo.ace_getLineListType = getLineListType; + editorInfo.ace_setSelection = setSelection; editorInfo.ace_callWithAce = function (fn, callStack, normalize) { let wrapper = function () { diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index 23ac931e3..e918ded6d 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -60,6 +60,24 @@ const padeditor = (function () { .find('#outerdocbody').parent(); $outerdoc.css({top: `${offsetTop}px`}); // Chrome $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF + const node = line[0]; + self.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); + }); } } }