Macro: save the last cursor position

This commit is contained in:
Julia Radzhabova
2025-01-20 18:01:01 +03:00
parent 69f32b7bf2
commit 3123e1627a
5 changed files with 31 additions and 18 deletions

View File

@ -16,13 +16,14 @@
parentEl = document.getElementById(placeholderId),
iframe;
var _setValue = function(value, readonly) {
var _setValue = function(value, currentPos, readonly) {
_postMessage(iframe.contentWindow, {
command: 'setValue',
referer: 'ace-editor',
data: {
value: value,
readonly: readonly
readonly: readonly,
currentPos: currentPos
}
});
};

View File

@ -88,11 +88,13 @@ ace.config.loadModule('ace/ext/tern', function () {
});
});
var firstLineNumber = 1;
if (!window.isIE) {
ace.config.loadModule('ace/ext/language_tools', function () {
editor.setOptions({
enableBasicAutocompletion: false,
enableLiveAutocompletion: true
enableLiveAutocompletion: true,
firstLineNumber: firstLineNumber
});
});
}
@ -116,7 +118,7 @@ var _postMessage = function(msg) {
if (window.isDisable) return;
_postMessage({
command: 'changeValue',
data: editor.getValue(),
data: { value: editor.getValue(), pos: editor.getCursorPosition() },
referer: 'ace-editor'
});
});
@ -130,7 +132,8 @@ var _postMessage = function(msg) {
if (!data.readonly) {
editor.focus();
editor.selection.clearSelection();
editor.scrollToRow(0);
editor.moveCursorToPosition(data.currentPos ? data.currentPos : {row: 0, column : 0});
editor.scrollToLine((data.currentPos ? data.currentPos.row : 0) + firstLineNumber, true);
}
window.isDisable = false;
};

View File

@ -50,8 +50,8 @@
var aceEditor;
var onChangeValue = function (event) {
document.getElementById('editorLog').innerText = event.data;
console.log("onChangeValue");
document.getElementById('editorLog').innerText = event.data ? event.data.value : '';
console.log("onChangeValue at position(" + event.data.pos.row + ", " + event.data.pos.column + ")");
};
var onEditorReady = function (event) {