From 281f04d3983af074dc144f6f23c0d22bb1e6dc50 Mon Sep 17 00:00:00 2001 From: anekos Date: Wed, 29 Oct 2008 06:00:31 +0000 Subject: hint の変更に対応。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@22313 d0d07461-0603-4401-acd4-de1884942a52 --- asdfghjkl.js | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'asdfghjkl.js') diff --git a/asdfghjkl.js b/asdfghjkl.js index 4218e09..2eafdde 100644 --- a/asdfghjkl.js +++ b/asdfghjkl.js @@ -3,7 +3,7 @@ // @description Inputting numbers by asdfghjkl; keys in hint mode. // @description-ja Hintモードで、asdfghjkl;キーを使って数字入力をする。 // @license Creative Commons 2.1 (Attribution + Share Alike) -// @version 1.0 +// @version 1.1 // @author anekos (anekos@snca.net) // ==/VimperatorPlugin== // @@ -15,38 +15,49 @@ // ヒントモードで、 を押すと asdfghjkl; モード(?)に入ります。 // 出たい場合は、もう一度押します。 // +// 切り替えキーを変更したい場合は、以下のように設定できます。 +// let g:asdfghjkl_mode_change_key = "" +// +// // Links: // http://d.hatena.ne.jp/nokturnalmortum/20081021#1224543467 // { - let asdfghjkl_default = eval(liberator.globalVariables.asdfghjkl_default || "false"); + let asdfghjkl_default = eval(liberator.globalVariables.asdfghjkl_default || 'false'); + let mode_change_key = liberator.globalVariables.asdfghjkl_mode_change_key || ''; let active = false; let original = { show: hints.show, - onEvent: hints.onEvent, + onKeyPress: events.onKeyPress, }; - hints.show = function () { - active = asdfghjkl_default; - return original.show.apply(this, arguments); - }; - - hints.onEvent = function (event) { - let key = events.toString(event); - if (key == "") { - active = !active; - return; - } - if (active && key.length == 1) { - let n = ";asdfghjkl".indexOf(key); - if (n >= 0) { - events.feedkeys(n.toString(), true); + events.onKeyPress = function (event) { + if (modes.extended & modes.HINTS) { + let key = events.toString(event); + if (key == mode_change_key) { + active = !active; + event.preventDefault(); + event.stopPropagation(); return; } + if (active && key.length == 1) { + let n = ';asdfghjkl'.indexOf(key); + if (n >= 0) { + events.feedkeys(n.toString(), true); + event.preventDefault(); + event.stopPropagation(); + return; + } + } } - return original.onEvent.call(this, event); + return original.onKeyPress.call(this, event); + }; + + hints.show = function () { + active = asdfghjkl_default; + return original.show.apply(this, arguments); }; } -- cgit v1.2.3