aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsecondlife2009-02-18 12:35:59 +0000
committersecondlife2009-02-18 12:35:59 +0000
commitc1124daa72659d8409eb524446c97f63dd92c1de (patch)
tree3068fb4b50d1c7c75c629f7daa62ccb673745081
parent71d9a2d32e5feaea2557a5ab1ee80b10a3f7f99c (diff)
downloadvimperator-plugins-c1124daa72659d8409eb524446c97f63dd92c1de.tar.bz2
wildeoptions=auto じゃなくてインクリメンタル検索するように
C-r でたどれるように git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@30236 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r--history-search-backward.js90
1 files changed, 61 insertions, 29 deletions
diff --git a/history-search-backward.js b/history-search-backward.js
index 17319d3..b7f863e 100644
--- a/history-search-backward.js
+++ b/history-search-backward.js
@@ -8,7 +8,7 @@ var PLUGIN_INFO =
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/history-search-backward.js</updateURL>
<author mail="hotchpotch@gmail.com" homepage="http://d.hatena.ne.jp/secondlife/">Yuichi Tateno</author>
<license>MIT</license>
-<version>0.1</version>
+<version>0.2</version>
<detail><![CDATA[
UNIX シェルのように、コマンドラインで C-r でヒストリ検索を行うプラグインです。map の変更設定は以下のように行えます。
>||
@@ -23,35 +23,67 @@ liberator.globalVariables.history_search_backward_map = ['<C-r>'];
Application.console.log(''+msg);
}
- const FAKE_TAB_EVENT = {
- type: 'keypress',
- liberatorString: '<Tab>',
- preventDefault: function() true,
- stopPropagation: function() true,
- };
-
- mappings.addUserMap([modes.COMMAND_LINE], liberator.globalVariables.history_search_backward_map || ['<C-r>'], 'History search backward.',
- function()
- {
- let command = commandline.command || '';
- commandline.input(options.get('wildoptions').has('auto') ? 'bck-i-search: ' : 'bck-search: ', function(str) {
- try {
- liberator.echo(liberator.execute(str));
- } catch(e) {};
- this.close();
- return;
- }, {
- completer: function(context) {
- context.title = ['CommandLine History', 'INDEX'];
- context.completions = [[key, i] for ([i, key] in storage['history-command'])].filter(function([key, i]) key).reverse();
- },
- onChange: function() {
- // this.onEvent(FAKE_TAB_EVENT);
- },
- default: command,
- });
- });
+ let evalWithContext = function(func, context) {
+ let str;
+ let fstr = func.toString();
+ if (fstr.indexOf('function () {') == 0) {
+ str = fstr.replace(/.*?{([\s\S]+)}.*?/m, "$1");
+ } else {
+ str = '(' + fstr + ')()';
+ }
+ return liberator.eval(str, context);
+ }
+
+ let showCompletions = function() {
+ if (!options.get('wildoptions').has('auto')) {
+ evalWithContext(function() {
+ completions.complete(true, false);
+ completions.itemList.show();
+ }, commandline.input);
+ }
+ }
+
+ let next = function() {
+ evalWithContext(function() completions.tab(false), commandline.input);
+ }
+
+ let prev = function() {
+ evalWithContext(function() completions.tab(true), commandline.input);
+ }
+
+ const commandlineWidget = document.getElementById("liberator-commandline");
+
+ mappings.addUserMap([modes.COMMAND_LINE],
+ liberator.globalVariables.history_search_backward_map || ['<C-r>'],
+ 'History incremental search backward.',
+ function()
+ {
+ if (evalWithContext(function() completions.itemList.visible(), commandline.input)) {
+ next();
+ return;
+ }
+ let command = commandline.command || '';
+ commandline.input('bck-i-search: ', function(str) {
+ try {
+ liberator.echo(liberator.execute(str));
+ } catch(e) {};
+ this.close();
+ return;
+ }, {
+ completer: function(context) {
+ context.title = ['CommandLine History', 'INDEX'];
+ context.completions = [[key, i] for ([i, key] in storage['history-command'])].
+ filter(function([key, i]) key).reverse();
+ },
+ onChange: function() {
+ showCompletions();
+ },
+ default: command,
+ });
+ showCompletions();
+ }
+ );
})();