Skip to content

Commit 0aca077

Browse files
committed
fix: ut failures
1 parent 59e6bef commit 0aca077

3 files changed

Lines changed: 37 additions & 41 deletions

File tree

src/document/DocumentCommandHandlers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ define(function (require, exports, module) {
12431243
* USER_CANCELED object).
12441244
*/
12451245
function handleFileSave(commandData) {
1246+
// todo save interceptor
12461247
var activeEditor = EditorManager.getActiveEditor(),
12471248
activeDoc = activeEditor && activeEditor.document,
12481249
doc = (commandData && commandData.doc) || activeDoc,

src/editor/EditorCommandHandlers.js

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ define(function (require, exports, module) {
3636
StringUtils = require("utils/StringUtils"),
3737
TokenUtils = require("utils/TokenUtils"),
3838
CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"),
39-
_ = require("thirdparty/lodash");
39+
_ = require("thirdparty/lodash"),
40+
ChangeHelper = require("editor/EditorHelper/ChangeHelper");
4041

4142
/**
4243
* List of constants
@@ -1190,44 +1191,20 @@ define(function (require, exports, module) {
11901191
return result.promise();
11911192
}
11921193

1193-
let _undoInterceptor = null;
1194-
let _redoInterceptor = null;
1195-
1196-
/**
1197-
* Use require("editor/EditorHelper/ChangeHelper") to intercept. this for internal use only
1198-
* @private
1199-
* @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault
1200-
*/
1201-
function _setUndoInterceptor(interceptor) {
1202-
_undoInterceptor = interceptor;
1203-
}
1204-
1205-
/**
1206-
* Use require("editor/EditorHelper/ChangeHelper") to intercept. this for internal use only
1207-
* @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault
1208-
*/
1209-
function _setRedoInterceptor(interceptor) {
1210-
_redoInterceptor = interceptor;
1211-
}
1212-
12131194
function handleUndo() {
1214-
if(_undoInterceptor){
1215-
const focusedEditor = EditorManager.getFocusedEditor();
1216-
const codeMirror = focusedEditor && focusedEditor._codeMirror;
1217-
if(_undoInterceptor(focusedEditor, codeMirror, null)){
1218-
return;
1219-
}
1195+
const focusedEditor = EditorManager.getFocusedEditor();
1196+
const codeMirror = focusedEditor && focusedEditor._codeMirror;
1197+
if(ChangeHelper._onBeforeUndo(focusedEditor, codeMirror, null)){
1198+
return;
12201199
}
12211200
return handleUndoRedo("undo");
12221201
}
12231202

12241203
function handleRedo() {
1225-
if(_redoInterceptor){
1226-
const focusedEditor = EditorManager.getFocusedEditor();
1227-
const codeMirror = focusedEditor && focusedEditor._codeMirror;
1228-
if(_redoInterceptor(focusedEditor, codeMirror, null)){
1229-
return;
1230-
}
1204+
const focusedEditor = EditorManager.getFocusedEditor();
1205+
const codeMirror = focusedEditor && focusedEditor._codeMirror;
1206+
if(ChangeHelper._onBeforeRedo(focusedEditor, codeMirror, null)){
1207+
return;
12311208
}
12321209
return handleUndoRedo("redo");
12331210
}
@@ -1307,7 +1284,4 @@ define(function (require, exports, module) {
13071284
CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, _execCommandCopy);
13081285
CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, _execCommandPaste);
13091286
CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll);
1310-
1311-
exports._setUndoInterceptor = _setUndoInterceptor;
1312-
exports._setRedoInterceptor = _setRedoInterceptor;
13131287
});

src/editor/EditorHelper/ChangeHelper.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ define(function (require, exports, module) {
3131
let _keyEventInterceptor = null;
3232

3333
const CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"),
34-
Menus = require("command/Menus"),
35-
EditorCommandHandlers = require("editor/EditorCommandHandlers");
34+
Menus = require("command/Menus");
3635

3736
function _applyChanges(changeList) {
3837
// eslint-disable-next-line no-invalid-this
@@ -315,20 +314,37 @@ define(function (require, exports, module) {
315314
Editor.prototype._dontDismissPopupOnScroll = _dontDismissPopupOnScroll;
316315
}
317316

317+
let _undoInterceptor = null;
318+
let _redoInterceptor = null;
319+
320+
function _onBeforeUndo(editor, codeMirror, event) {
321+
if(!_undoInterceptor){
322+
return false;
323+
}
324+
return _undoInterceptor(editor, codeMirror, event);
325+
}
326+
327+
function _onBeforeRedo(editor, codeMirror, event) {
328+
if(!_redoInterceptor){
329+
return false;
330+
}
331+
return _redoInterceptor(editor, codeMirror, event);
332+
}
333+
318334
/**
319335
* Sets the undo interceptor function in before it goes to codemirror
320336
* @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault
321337
*/
322338
function setUndoInterceptor(interceptor) {
323-
EditorCommandHandlers._setUndoInterceptor(interceptor);
339+
_undoInterceptor = interceptor;
324340
}
325341

326342
/**
327343
* Sets the redo interceptor function in before it goes to codemirror
328344
* @param {Function} interceptor - Function(editor, cm, event) that returns true to preventDefault
329345
*/
330346
function setRedoInterceptor(interceptor) {
331-
EditorCommandHandlers._setRedoInterceptor(interceptor);
347+
_redoInterceptor = interceptor;
332348
}
333349

334350
/**
@@ -363,7 +379,12 @@ define(function (require, exports, module) {
363379
_keyEventInterceptor = interceptor;
364380
}
365381

366-
exports.addHelpers =addHelpers;
382+
// private exports
383+
exports._onBeforeUndo =_onBeforeUndo;
384+
exports._onBeforeRedo = _onBeforeRedo;
385+
386+
// public exports
387+
exports.addHelpers = addHelpers;
367388
exports.setUndoInterceptor = setUndoInterceptor;
368389
exports.setRedoInterceptor = setRedoInterceptor;
369390
exports.setCutInterceptor = setCutInterceptor;

0 commit comments

Comments
 (0)