Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}

Expand Down
54 changes: 45 additions & 9 deletions src/editor/EditorHelper/ChangeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,43 +314,79 @@ 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;
}

/**
* 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;
}

/**
* 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;
}

/**
* 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;
Expand Down
2 changes: 1 addition & 1 deletion tracking-repos.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"phoenixPro": {
"commitID": "7b64452de658a6f482c24605056cf94f068d12c4"
"commitID": "19d997d0aa98acb3507b3cb19b81c286ebcfd474"
}
}
Loading