From c1124daa72659d8409eb524446c97f63dd92c1de Mon Sep 17 00:00:00 2001 From: secondlife Date: Wed, 18 Feb 2009 12:35:59 +0000 Subject: wildeoptions=auto じゃなくてインクリメンタル検索するように C-r でたどれるように git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@30236 d0d07461-0603-4401-acd4-de1884942a52 --- history-search-backward.js | 90 +++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 29 deletions(-) (limited to 'history-search-backward.js') 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 = http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/history-search-backward.js Yuichi Tateno MIT -0.1 +0.2 || @@ -23,35 +23,67 @@ liberator.globalVariables.history_search_backward_map = ['']; Application.console.log(''+msg); } - const FAKE_TAB_EVENT = { - type: 'keypress', - liberatorString: '', - preventDefault: function() true, - stopPropagation: function() true, - }; - - mappings.addUserMap([modes.COMMAND_LINE], liberator.globalVariables.history_search_backward_map || [''], '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 || [''], + '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(); + } + ); })(); -- cgit v1.2.3