mirror of
https://github.com/ONLYOFFICE/web-apps.git
synced 2025-04-18 14:44:08 +03:00
Macro: save the last cursor position
This commit is contained in:
parent
69f32b7bf2
commit
3123e1627a
@ -111,7 +111,8 @@ define([], function () {
|
||||
if (cmd && cmd.referer == "ace-editor") {
|
||||
switch (cmd.command) {
|
||||
case 'changeValue':
|
||||
this.fireEvent('change', cmd.data);
|
||||
data = cmd.data || {};
|
||||
this.fireEvent('change', data.value, data.pos);
|
||||
break;
|
||||
case 'aceEditorReady':
|
||||
this.fireEvent('ready', cmd.data);
|
||||
@ -126,13 +127,14 @@ define([], function () {
|
||||
this.loadMask.hide();
|
||||
},
|
||||
|
||||
setValue: function(value, readonly) {
|
||||
setValue: function(value, currentPos, readonly) {
|
||||
this._postMessage(this.iframe.contentWindow, {
|
||||
command: 'setValue',
|
||||
referer: 'ace-editor',
|
||||
data: {
|
||||
value: value,
|
||||
readonly: readonly
|
||||
readonly: readonly,
|
||||
currentPos: currentPos
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -103,7 +103,8 @@ define([], function () {
|
||||
macrosItemMenuOpen: null,
|
||||
functionItemMenuOpen: null,
|
||||
currentElementMode: this.CurrentElementModeType.Macros,
|
||||
currentValue: ''
|
||||
currentValue: '',
|
||||
currentPos: {row: 2, column: 0}
|
||||
};
|
||||
|
||||
_options.tpl = _.template(this.template)({
|
||||
@ -259,19 +260,21 @@ define([], function () {
|
||||
this.codeEditor = new Common.UI.AceEditor({parentEl: '#code-editor'});
|
||||
this.codeEditor.on('ready', function() {
|
||||
me.codeEditor.updateTheme();
|
||||
me.codeEditor.setValue(me._state.currentValue);
|
||||
me.codeEditor.setValue(me._state.currentValue, me._state.currentPos);
|
||||
setTimeout(function() {
|
||||
me.aceContainer.removeClass('invisible');
|
||||
}, 10);
|
||||
// me.loadMask.hide();
|
||||
});
|
||||
this.codeEditor.on('change', function(value) {
|
||||
this.codeEditor.on('change', function(value, pos) {
|
||||
var selectedItem = me._state.currentElementMode === me.CurrentElementModeType.Macros
|
||||
? me.listMacros.getSelectedRec()
|
||||
: me.listFunctions.getSelectedRec();
|
||||
if(selectedItem) {
|
||||
me._state.currentValue = value;
|
||||
me._state.currentPos = pos;
|
||||
selectedItem.set('value', value);
|
||||
selectedItem.set('currentPos', pos);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -313,6 +316,7 @@ define([], function () {
|
||||
if(macrosList.length > 0) {
|
||||
macrosList.forEach(function (macros) {
|
||||
macros.autostart = !!macros.autostart;
|
||||
macros.currentPos = {row: 2, column: 0};
|
||||
});
|
||||
this.listMacros.store.reset(macrosList);
|
||||
var selectItem = this.listMacros.store.at(data.current);
|
||||
@ -631,8 +635,9 @@ define([], function () {
|
||||
this.listMacros.store.add({
|
||||
guid: this.createGuid(),
|
||||
name : (macrosTextTranslate + " " + indexMax),
|
||||
value : "(function()\n{\n})();",
|
||||
autostart: false
|
||||
value : "(function()\n{\n\n})();",
|
||||
autostart: false,
|
||||
currentPos: {row: 2, column: 0}
|
||||
});
|
||||
this.listMacros.selectRecord(this.listMacros.store.at(-1));
|
||||
},
|
||||
@ -654,8 +659,9 @@ define([], function () {
|
||||
},
|
||||
onSelectListMacrosItem: function(listView, itemView, record) {
|
||||
this._state.currentElementMode = this.CurrentElementModeType.Macros;
|
||||
this.codeEditor.setValue(record.get('value'));
|
||||
this.codeEditor.setValue(record.get('value'), record.get('currentPos')!==undefined ? record.get('currentPos') : {row: 2, column: 0});
|
||||
this._state.currentValue = record.get('value');
|
||||
this._state.currentPos = record.get('currentPos');
|
||||
|
||||
this.btnMacrosRun.setDisabled(false);
|
||||
this.listFunctions && this.listFunctions.deselectAll();
|
||||
@ -747,7 +753,8 @@ define([], function () {
|
||||
this.listFunctions.store.add({
|
||||
guid: this.createGuid(),
|
||||
name : (macrosTextTranslate + " " + indexMax),
|
||||
value : "(function()\n{\n\t/**\n\t * Function that returns the argument\n\t * @customfunction\n\t * @param {any} arg Any data.\n * @returns {any} The argumet of the function.\n\t*/\n\tfunction myFunction(arg) {\n\t return arg;\n\t}\n\tApi.AddCustomFunction(myFunction);\n})();"
|
||||
value : "(function()\n{\n\t/**\n\t * Function that returns the argument\n\t * @customfunction\n\t * @param {any} arg Any data.\n * @returns {any} The argumet of the function.\n\t*/\n\tfunction myFunction(arg) {\n\t\t\n\t return arg;\n\t}\n\tApi.AddCustomFunction(myFunction);\n})();",
|
||||
currentPos: {row: 9, column: 2}
|
||||
});
|
||||
this.listFunctions.selectRecord(this.listFunctions.store.at(-1));
|
||||
},
|
||||
@ -769,7 +776,7 @@ define([], function () {
|
||||
},
|
||||
onSelectListFunctionItem: function(listView, itemView, record) {
|
||||
this._state.currentElementMode = this.CurrentElementModeType.CustomFunction;
|
||||
this.codeEditor.setValue(record.get('value'));
|
||||
this.codeEditor.setValue(record.get('value'), record.get('currentPos')!==undefined ? record.get('currentPos') : {row: 2, column: 0});
|
||||
|
||||
this.btnMacrosRun.setDisabled(true);
|
||||
|
||||
|
5
vendor/ace/component/AceEditor.js
vendored
5
vendor/ace/component/AceEditor.js
vendored
@ -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
|
||||
}
|
||||
});
|
||||
};
|
||||
|
9
vendor/ace/component/AceEditorCode.js
vendored
9
vendor/ace/component/AceEditorCode.js
vendored
@ -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;
|
||||
};
|
||||
|
4
vendor/ace/component/example.html
vendored
4
vendor/ace/component/example.html
vendored
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user