[occur] fixing recursive occurs
This commit is contained in:
parent
96bca7ed95
commit
d75845f3aa
2 changed files with 27 additions and 3 deletions
|
|
@ -37,8 +37,9 @@ var config = require("../config"),
|
||||||
var occurStartCommands = [{
|
var occurStartCommands = [{
|
||||||
name: "occur",
|
name: "occur",
|
||||||
exec: function(editor, options) {
|
exec: function(editor, options) {
|
||||||
|
var alreadyInOccur = !!editor.session.$occur;
|
||||||
var occurSessionActive = new Occur().enter(editor, options);
|
var occurSessionActive = new Occur().enter(editor, options);
|
||||||
if (occurSessionActive) OccurKeyboardHandler.installIn(editor);
|
if (occurSessionActive && !alreadyInOccur) OccurKeyboardHandler.installIn(editor);
|
||||||
},
|
},
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}];
|
}];
|
||||||
|
|
@ -50,7 +51,7 @@ var occurCommands = [{
|
||||||
var occur = editor.session.$occur;
|
var occur = editor.session.$occur;
|
||||||
if (!occur) return;
|
if (!occur) return;
|
||||||
occur.exit(editor, {});
|
occur.exit(editor, {});
|
||||||
OccurKeyboardHandler.uninstallFrom(editor);
|
if (!editor.session.$occur) OccurKeyboardHandler.uninstallFrom(editor);
|
||||||
},
|
},
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -60,7 +61,7 @@ var occurCommands = [{
|
||||||
var occur = editor.session.$occur;
|
var occur = editor.session.$occur;
|
||||||
if (!occur) return;
|
if (!occur) return;
|
||||||
occur.exit(editor, {translatePosition: true});
|
occur.exit(editor, {translatePosition: true});
|
||||||
OccurKeyboardHandler.uninstallFrom(editor);
|
if (!editor.session.$occur) OccurKeyboardHandler.uninstallFrom(editor);
|
||||||
},
|
},
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}];
|
}];
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,29 @@ module.exports = {
|
||||||
editor.execCommand('occuraccept');
|
editor.execCommand('occuraccept');
|
||||||
|
|
||||||
assert.position(editor.getCursorPosition(), 3, 1, 'occur -> original pos');
|
assert.position(editor.getCursorPosition(), 3, 1, 'occur -> original pos');
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: recursive occur" : function() {
|
||||||
|
// setup
|
||||||
|
var text = 'x\nabc1\nx\nabc2\n';
|
||||||
|
editor.session.insert({row: 0, column: 0}, text);
|
||||||
|
editor.commands.addCommands(occurCommands);
|
||||||
|
|
||||||
|
// orig -> occur1
|
||||||
|
editor.execCommand('occur', {needle: 'abc'});
|
||||||
|
assert.equal(editor.getValue(), 'abc1\nabc2', "orig -> occur1");
|
||||||
|
|
||||||
|
// occur1 -> occur2
|
||||||
|
editor.execCommand('occur', {needle: '2'});
|
||||||
|
assert.equal(editor.getValue(), 'abc2', "occur1 -> occur2");
|
||||||
|
|
||||||
|
// occur2 -> occur1
|
||||||
|
editor.execCommand('occurexit');
|
||||||
|
assert.equal(editor.getValue(), 'abc1\nabc2', "occur2 -> occur1");
|
||||||
|
|
||||||
|
// occur1 -> orig
|
||||||
|
editor.execCommand('occurexit');
|
||||||
|
assert.equal(editor.getValue(), text, "occur1 -> orig");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue