[occur] make occur doc react to keyboard evts / highlight it
This commit is contained in:
parent
8102b6579f
commit
0aee413754
3 changed files with 17 additions and 2 deletions
|
|
@ -41,6 +41,7 @@ var occurStartCommands = [{
|
||||||
var handler = new OccurKeyboardHandler();
|
var handler = new OccurKeyboardHandler();
|
||||||
editor.keyBinding.addKeyboardHandler(handler);
|
editor.keyBinding.addKeyboardHandler(handler);
|
||||||
editor.commands.addCommands(occurCommands);
|
editor.commands.addCommands(occurCommands);
|
||||||
|
editor.setReadOnly(true);
|
||||||
var occur = new Occur();
|
var occur = new Occur();
|
||||||
occur.display(editor.session, options);
|
occur.display(editor.session, options);
|
||||||
},
|
},
|
||||||
|
|
@ -55,6 +56,7 @@ var occurCommands = [{
|
||||||
var session = editor.session, occur = session.doc.$occur;
|
var session = editor.session, occur = session.doc.$occur;
|
||||||
if (occur) occur.displayOriginal(session);
|
if (occur) occur.displayOriginal(session);
|
||||||
editor.commands.removeCommands(occurCommands);
|
editor.commands.removeCommands(occurCommands);
|
||||||
|
editor.setReadOnly(false);
|
||||||
var handler = editor.getKeyboardHandler();
|
var handler = editor.getKeyboardHandler();
|
||||||
if (handler.isOccurHandler) editor.keyBinding.removeKeyboardHandler(handler);
|
if (handler.isOccurHandler) editor.keyBinding.removeKeyboardHandler(handler);
|
||||||
},
|
},
|
||||||
|
|
@ -82,7 +84,7 @@ oop.inherits(OccurKeyboardHandler, HashHandler);
|
||||||
var handleKeyboard$super = this.handleKeyboard;
|
var handleKeyboard$super = this.handleKeyboard;
|
||||||
this.handleKeyboard = function(data, hashId, key, keyCode) {
|
this.handleKeyboard = function(data, hashId, key, keyCode) {
|
||||||
var cmd = handleKeyboard$super.call(this, data, hashId, key, keyCode);
|
var cmd = handleKeyboard$super.call(this, data, hashId, key, keyCode);
|
||||||
return (cmd && cmd.command) ? cmd : {command: "null"};
|
return (cmd && cmd.command) ? cmd : {command: "null", passEvent: true};
|
||||||
}
|
}
|
||||||
|
|
||||||
}).call(OccurKeyboardHandler.prototype);
|
}).call(OccurKeyboardHandler.prototype);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ oop.inherits(Occur, Search);
|
||||||
|
|
||||||
this.displayOriginal = function(session) {
|
this.displayOriginal = function(session) {
|
||||||
session.setDocument(this.$originalDoc);
|
session.setDocument(this.$originalDoc);
|
||||||
|
session.highlight(null);
|
||||||
|
session._emit('changeBackMarker');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.matchingLines = function(session, options) {
|
this.matchingLines = function(session, options) {
|
||||||
|
|
|
||||||
|
|
@ -71,17 +71,28 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: occur command" : function() {
|
"test: occur command" : function() {
|
||||||
|
// setup
|
||||||
var lines = ['hel', 'lo', '', 'wo', 'rld'];
|
var lines = ['hel', 'lo', '', 'wo', 'rld'];
|
||||||
session.doc.insertLines(0, lines);
|
session.doc.insertLines(0, lines);
|
||||||
editor.commands.addCommands(occurCommands);
|
editor.commands.addCommands(occurCommands);
|
||||||
|
|
||||||
|
// run occur for lines including 'o'
|
||||||
editor.execCommand('occur', {needle: 'o'});
|
editor.execCommand('occur', {needle: 'o'});
|
||||||
assert.equal(session.getValue(), 'lo\nwo');
|
assert.equal(session.getValue(), 'lo\nwo');
|
||||||
|
|
||||||
|
// command install OK?
|
||||||
|
assert.ok(editor.getReadOnly(), 'occur doc not marked as read only');
|
||||||
assert.ok(editor.getKeyboardHandler().isOccurHandler, 'no occur handler installed');
|
assert.ok(editor.getKeyboardHandler().isOccurHandler, 'no occur handler installed');
|
||||||
assert.ok(editor.commands.byName.occurexit, 'no exitoccur command installed');
|
assert.ok(editor.commands.byName.occurexit, 'no exitoccur command installed');
|
||||||
|
|
||||||
|
// exit occur
|
||||||
editor.execCommand('occurexit');
|
editor.execCommand('occurexit');
|
||||||
|
assert.equal(session.getValue(), lines.join('\n') + '\n');
|
||||||
|
|
||||||
|
// editor state cleaned up?
|
||||||
|
assert.ok(!editor.getReadOnly(), 'original doc is marked as read only');
|
||||||
assert.ok(!editor.getKeyboardHandler().isOccurHandler, 'occur handler installed after detach');
|
assert.ok(!editor.getKeyboardHandler().isOccurHandler, 'occur handler installed after detach');
|
||||||
assert.ok(!editor.commands.byName.occurexit, 'exitoccur installed after exiting occur');
|
assert.ok(!editor.commands.byName.occurexit, 'exitoccur installed after exiting occur');
|
||||||
assert.equal(session.getValue(), lines.join('\n') + '\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue