From bf39b5676353a39687903602579b2795eeacab61 Mon Sep 17 00:00:00 2001 From: abose Date: Wed, 7 Jan 2026 20:40:27 +0530 Subject: [PATCH 1/3] feat: undo redo interceptor and change helper --- src/editor/EditorCommandHandlers.js | 37 +++++++++++++++++++++++++ src/editor/EditorHelper/ChangeHelper.js | 33 ++++++++++++++++------ 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index 05833f1c6b..1f7604c9f0 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -1190,11 +1190,45 @@ define(function (require, exports, module) { return result.promise(); } + let _undoInterceptor = null; + let _redoInterceptor = null; + + /** + * Use require("editor/EditorHelper/ChangeHelper") to intercept. this for internal use only + * @private + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault + */ + function _setUndoInterceptor(interceptor) { + _undoInterceptor = interceptor; + } + + /** + * Use require("editor/EditorHelper/ChangeHelper") to intercept. this for internal use only + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault + */ + function _setRedoInterceptor(interceptor) { + _redoInterceptor = interceptor; + } + function handleUndo() { + if(_undoInterceptor){ + const focusedEditor = EditorManager.getFocusedEditor(); + const codeMirror = focusedEditor && focusedEditor._codeMirror; + if(_undoInterceptor(focusedEditor, codeMirror, null)){ + return; + } + } return handleUndoRedo("undo"); } function handleRedo() { + if(_redoInterceptor){ + const focusedEditor = EditorManager.getFocusedEditor(); + const codeMirror = focusedEditor && focusedEditor._codeMirror; + if(_redoInterceptor(focusedEditor, codeMirror, null)){ + return; + } + } return handleUndoRedo("redo"); } @@ -1273,4 +1307,7 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, _execCommandCopy); CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, _execCommandPaste); CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll); + + exports._setUndoInterceptor = _setUndoInterceptor; + exports._setRedoInterceptor = _setRedoInterceptor; }); diff --git a/src/editor/EditorHelper/ChangeHelper.js b/src/editor/EditorHelper/ChangeHelper.js index 3f9d50ba4d..41d8c92ff5 100644 --- a/src/editor/EditorHelper/ChangeHelper.js +++ b/src/editor/EditorHelper/ChangeHelper.js @@ -31,7 +31,8 @@ define(function (require, exports, module) { let _keyEventInterceptor = null; const CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"), - Menus = require("command/Menus"); + Menus = require("command/Menus"), + EditorCommandHandlers = require("editor/EditorCommandHandlers"); function _applyChanges(changeList) { // eslint-disable-next-line no-invalid-this @@ -314,10 +315,25 @@ define(function (require, exports, module) { Editor.prototype._dontDismissPopupOnScroll = _dontDismissPopupOnScroll; } + /** + * Sets the undo interceptor function in before it goes to codemirror + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault + */ + function setUndoInterceptor(interceptor) { + EditorCommandHandlers._setUndoInterceptor(interceptor); + } + + /** + * Sets the redo interceptor function in before it goes to codemirror + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault + */ + function setRedoInterceptor(interceptor) { + EditorCommandHandlers._setRedoInterceptor(interceptor); + } + /** * Sets the cut interceptor function in codemirror - * @param {Function} interceptor - Function(editor, cm, event) that returns true to - preventDefault + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault */ function setCutInterceptor(interceptor) { _cutInterceptor = interceptor; @@ -325,8 +341,7 @@ define(function (require, exports, module) { /** * Sets the copy interceptor function in codemirror - * @param {Function} interceptor - Function(editor, cm, event) that returns true to - preventDefault + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault */ function setCopyInterceptor(interceptor) { _copyInterceptor = interceptor; @@ -334,8 +349,7 @@ define(function (require, exports, module) { /** * Sets the paste interceptor function in codemirror - * @param {Function} interceptor - Function(editor, cm, event) that returns true to - preventDefault + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault */ function setPasteInterceptor(interceptor) { _pasteInterceptor = interceptor; @@ -343,14 +357,15 @@ define(function (require, exports, module) { /** * Sets the key down/up/press interceptor function in codemirror - * @param {Function} interceptor - Function(editor, cm, event) that returns true to - preventDefault + * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault */ function setKeyEventInterceptor(interceptor) { _keyEventInterceptor = interceptor; } exports.addHelpers =addHelpers; + exports.setUndoInterceptor = setUndoInterceptor; + exports.setRedoInterceptor = setRedoInterceptor; exports.setCutInterceptor = setCutInterceptor; exports.setCopyInterceptor = setCopyInterceptor; exports.setPasteInterceptor = setPasteInterceptor; From 2d6145283581836cd7f397745c73ff9d5d06d50f Mon Sep 17 00:00:00 2001 From: abose Date: Wed, 7 Jan 2026 22:44:24 +0530 Subject: [PATCH 2/3] fix: ut failures --- src/document/DocumentCommandHandlers.js | 1 + src/editor/EditorCommandHandlers.js | 46 ++++++------------------- src/editor/EditorHelper/ChangeHelper.js | 31 ++++++++++++++--- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 953a189692..3943af04d1 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -1243,6 +1243,7 @@ define(function (require, exports, module) { * USER_CANCELED object). */ function handleFileSave(commandData) { + // todo save interceptor var activeEditor = EditorManager.getActiveEditor(), activeDoc = activeEditor && activeEditor.document, doc = (commandData && commandData.doc) || activeDoc, diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index 1f7604c9f0..2f4a025271 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -36,7 +36,8 @@ define(function (require, exports, module) { StringUtils = require("utils/StringUtils"), TokenUtils = require("utils/TokenUtils"), CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"), - _ = require("thirdparty/lodash"); + _ = require("thirdparty/lodash"), + ChangeHelper = require("editor/EditorHelper/ChangeHelper"); /** * List of constants @@ -1190,44 +1191,20 @@ define(function (require, exports, module) { return result.promise(); } - let _undoInterceptor = null; - let _redoInterceptor = null; - - /** - * Use require("editor/EditorHelper/ChangeHelper") to intercept. this for internal use only - * @private - * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault - */ - function _setUndoInterceptor(interceptor) { - _undoInterceptor = interceptor; - } - - /** - * Use require("editor/EditorHelper/ChangeHelper") to intercept. this for internal use only - * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault - */ - function _setRedoInterceptor(interceptor) { - _redoInterceptor = interceptor; - } - function handleUndo() { - if(_undoInterceptor){ - const focusedEditor = EditorManager.getFocusedEditor(); - const codeMirror = focusedEditor && focusedEditor._codeMirror; - if(_undoInterceptor(focusedEditor, codeMirror, null)){ - return; - } + const focusedEditor = EditorManager.getFocusedEditor(); + const codeMirror = focusedEditor && focusedEditor._codeMirror; + if(ChangeHelper._onBeforeUndo(focusedEditor, codeMirror, null)){ + return; } return handleUndoRedo("undo"); } function handleRedo() { - if(_redoInterceptor){ - const focusedEditor = EditorManager.getFocusedEditor(); - const codeMirror = focusedEditor && focusedEditor._codeMirror; - if(_redoInterceptor(focusedEditor, codeMirror, null)){ - return; - } + const focusedEditor = EditorManager.getFocusedEditor(); + const codeMirror = focusedEditor && focusedEditor._codeMirror; + if(ChangeHelper._onBeforeRedo(focusedEditor, codeMirror, null)){ + return; } return handleUndoRedo("redo"); } @@ -1307,7 +1284,4 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, _execCommandCopy); CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, _execCommandPaste); CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll); - - exports._setUndoInterceptor = _setUndoInterceptor; - exports._setRedoInterceptor = _setRedoInterceptor; }); diff --git a/src/editor/EditorHelper/ChangeHelper.js b/src/editor/EditorHelper/ChangeHelper.js index 41d8c92ff5..f010e4b030 100644 --- a/src/editor/EditorHelper/ChangeHelper.js +++ b/src/editor/EditorHelper/ChangeHelper.js @@ -31,8 +31,7 @@ define(function (require, exports, module) { let _keyEventInterceptor = null; const CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"), - Menus = require("command/Menus"), - EditorCommandHandlers = require("editor/EditorCommandHandlers"); + Menus = require("command/Menus"); function _applyChanges(changeList) { // eslint-disable-next-line no-invalid-this @@ -315,12 +314,29 @@ define(function (require, exports, module) { Editor.prototype._dontDismissPopupOnScroll = _dontDismissPopupOnScroll; } + let _undoInterceptor = null; + let _redoInterceptor = null; + + function _onBeforeUndo(editor, codeMirror, event) { + if(!_undoInterceptor){ + return false; + } + return _undoInterceptor(editor, codeMirror, event); + } + + function _onBeforeRedo(editor, codeMirror, event) { + if(!_redoInterceptor){ + return false; + } + return _redoInterceptor(editor, codeMirror, event); + } + /** * Sets the undo interceptor function in before it goes to codemirror * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault */ function setUndoInterceptor(interceptor) { - EditorCommandHandlers._setUndoInterceptor(interceptor); + _undoInterceptor = interceptor; } /** @@ -328,7 +344,7 @@ define(function (require, exports, module) { * @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault */ function setRedoInterceptor(interceptor) { - EditorCommandHandlers._setRedoInterceptor(interceptor); + _redoInterceptor = interceptor; } /** @@ -363,7 +379,12 @@ define(function (require, exports, module) { _keyEventInterceptor = interceptor; } - exports.addHelpers =addHelpers; + // private exports + exports._onBeforeUndo =_onBeforeUndo; + exports._onBeforeRedo = _onBeforeRedo; + + // public exports + exports.addHelpers = addHelpers; exports.setUndoInterceptor = setUndoInterceptor; exports.setRedoInterceptor = setRedoInterceptor; exports.setCutInterceptor = setCutInterceptor; From 123577eea35ad805840ae10e0d37bb9422a5df31 Mon Sep 17 00:00:00 2001 From: abose Date: Wed, 7 Jan 2026 23:27:46 +0530 Subject: [PATCH 3/3] chore: update pro dep --- tracking-repos.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracking-repos.json b/tracking-repos.json index e08c7c9e31..1f8dc3cab7 100644 --- a/tracking-repos.json +++ b/tracking-repos.json @@ -1,5 +1,5 @@ { "phoenixPro": { - "commitID": "7b64452de658a6f482c24605056cf94f068d12c4" + "commitID": "19d997d0aa98acb3507b3cb19b81c286ebcfd474" } }