[incremental search] polymorphic setup invocation for keyboard handlers
This commit is contained in:
parent
438e3c985c
commit
1daaeb3a79
2 changed files with 37 additions and 20 deletions
|
|
@ -34,7 +34,8 @@ define(function(require, exports, module) {
|
|||
var oop = require("./lib/oop");
|
||||
var Range = require("./range").Range;
|
||||
var Search = require("./search").Search;
|
||||
var ISearchKbd = require("./commands/incremental_search_commands").IncrementalSearchKeyboardHandler;
|
||||
var iSearchCommandModule = require("./commands/incremental_search_commands");
|
||||
var ISearchKbd = iSearchCommandModule.IncrementalSearchKeyboardHandler;
|
||||
|
||||
/**
|
||||
* @class IncrementalSearch
|
||||
|
|
@ -194,31 +195,43 @@ function patchHighlightMarkerStyling(options) {
|
|||
}
|
||||
|
||||
|
||||
// support for default keyboard handler
|
||||
var CommandManager = require("./commands/command_manager").CommandManager;
|
||||
(function() {
|
||||
this.setupIncrementalSearch = function(editor, val) {
|
||||
if (this.usesIncrementalSearch == val) return;
|
||||
this.usesIncrementalSearch = val;
|
||||
var iSearchCommands = iSearchCommandModule.iSearchStartCommands,
|
||||
method = val ? 'addCommands' : 'removeCommands';
|
||||
this[method](iSearchCommands);
|
||||
};
|
||||
}).call(CommandManager.prototype);
|
||||
|
||||
// support for emacskeyboard handler
|
||||
var emacs = require("./keyboard/emacs");
|
||||
emacs.handler.setupIncrementalSearch = function(editor, val) {
|
||||
if (this.usesIncrementalSearch == val) return;
|
||||
this.usesIncrementalSearch = val;
|
||||
if (val) {
|
||||
this.bindKey('C-s', 'iSearch');
|
||||
this.bindKey('C-r', 'iSearchBackwards');
|
||||
} else {
|
||||
this.bindKey('C-s', "findnext");
|
||||
this.bindKey('C-r', "findprevious");
|
||||
}
|
||||
}
|
||||
|
||||
// incremental search config option
|
||||
var Editor = require("./editor").Editor;
|
||||
require("./config").defineOptions(Editor.prototype, "editor", {
|
||||
useIncrementalSearch: {
|
||||
set: function(val) {
|
||||
var iSearchCommands = require("ace/commands/incremental_search_commands").iSearchStartCommands;
|
||||
var kbd = this.getKeyboardHandler();
|
||||
patchHighlightMarkerStyling({enable: val});
|
||||
if (val) {
|
||||
// enable for whole editor
|
||||
this.commands.addCommands(iSearchCommands);
|
||||
if (kbd.isEmacs) { // adapt emacs key handler if used
|
||||
kbd.oldSearchBindings = {
|
||||
'c-s': kbd.commmandKeyBinding['c-s'],
|
||||
'c-r': kbd.commmandKeyBinding['c-r']
|
||||
}
|
||||
kbd.bindKey('C-s', 'iSearch');
|
||||
kbd.bindKey('C-r', 'iSearchBackwards');
|
||||
this.keyBinding.$handlers.forEach(function(handler) {
|
||||
if (handler.setupIncrementalSearch) {
|
||||
handler.setupIncrementalSearch(this, val);
|
||||
}
|
||||
} else {
|
||||
this.commands.removeCommands(iSearchCommands);
|
||||
if (kbd.isEmacs && kbd.oldSearchBindings) {
|
||||
kbd.bindKey('C-s', kbd.oldSearchBindings['c-s']);
|
||||
kbd.bindKey('C-r', kbd.oldSearchBindings['c-r']);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -108,6 +108,10 @@ exports.handler.attach = function(editor) {
|
|||
editor.commands.addCommands(commands);
|
||||
exports.handler.platform = editor.commands.platform;
|
||||
editor.$emacsModeHandler = this;
|
||||
var hasISearch = editor.getOption('useIncrementalSearch');
|
||||
if (hasISearch != this.usesIncrementalSearch) {
|
||||
this.setupIncrementalSearch(editor, hasISearch);
|
||||
};
|
||||
};
|
||||
|
||||
exports.handler.detach = function(editor) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue