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 05833f1c6b..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 @@ -1191,10 +1192,20 @@ define(function (require, exports, module) { } function handleUndo() { + const focusedEditor = EditorManager.getFocusedEditor(); + const codeMirror = focusedEditor && focusedEditor._codeMirror; + if(ChangeHelper._onBeforeUndo(focusedEditor, codeMirror, null)){ + return; + } return handleUndoRedo("undo"); } function handleRedo() { + const focusedEditor = EditorManager.getFocusedEditor(); + const codeMirror = focusedEditor && focusedEditor._codeMirror; + if(ChangeHelper._onBeforeRedo(focusedEditor, codeMirror, null)){ + return; + } return handleUndoRedo("redo"); } diff --git a/src/editor/EditorHelper/ChangeHelper.js b/src/editor/EditorHelper/ChangeHelper.js index 3f9d50ba4d..f010e4b030 100644 --- a/src/editor/EditorHelper/ChangeHelper.js +++ b/src/editor/EditorHelper/ChangeHelper.js @@ -314,10 +314,42 @@ 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) { + _undoInterceptor = 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) { + _redoInterceptor = 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 +357,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 +365,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 +373,20 @@ 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; + // private exports + exports._onBeforeUndo =_onBeforeUndo; + exports._onBeforeRedo = _onBeforeRedo; + + // public exports + exports.addHelpers = addHelpers; + exports.setUndoInterceptor = setUndoInterceptor; + exports.setRedoInterceptor = setRedoInterceptor; exports.setCutInterceptor = setCutInterceptor; exports.setCopyInterceptor = setCopyInterceptor; exports.setPasteInterceptor = setPasteInterceptor; 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" } }