From 3f7fa149e690dde24b0ea69c7d3e39d6eee2965c Mon Sep 17 00:00:00 2001 From: hogelog Date: Tue, 27 Jan 2009 10:08:33 +0000 Subject: * change hintchar labeling algorithm * remove let g:hintsio setting * add let g:hintinput setting git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@29124 d0d07461-0603-4401-acd4-de1884942a52 --- char-hints-mod2.js | 140 ++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/char-hints-mod2.js b/char-hints-mod2.js index c44b40e..248aa58 100644 --- a/char-hints-mod2.js +++ b/char-hints-mod2.js @@ -4,10 +4,10 @@ var PLUGIN_INFO = {NAME} character hint mode. hogelog - 0.1.1 + 0.2.0 2.0pre 2008/12/12 2.0a1 - 2008/12/22 14:57:34 + 2009/1/27 18:56 http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/char-hints-mod2.js @@ -39,18 +37,16 @@ let g:hintsio: 大文字は文字ラベルの選択に使います。 == SETTING == -let g:hinstchars: +let g:hintchars: set character used by char-hint. e.g.) - let g:hinstchars="hjkl" -let g:hintsio: + let g:hintchars="hjkl" +let g:hintinput: - "i" setting char-hint input lowercase. - "I" setting char-hint input uppercase. - - "o" setting char-hint show lowercase. - - "O" setting char-hint show uppercase. - Default setting is "IO". + Default setting is "I". e.g.) - let g:histsio="i" + let g:hintinput="i" == TODO == ]]> @@ -65,7 +61,6 @@ let g:hintsio: let hintchars = DEFAULT_HINTCHARS; let inputCase = function(str) str.toUpperCase(); let inputRegex = /[A-Z]/; - let showCase = function(str) str.toUpperCase(); function chars2num(chars) //{{{ { @@ -89,33 +84,67 @@ let g:hintsio: return chars; } //}}} - function showCharHints() //{{{ + function getStartNum(base, count) //{{{ { - function showHints(win) - { - for(let elem in buffer.evaluateXPath("//*[@liberator:highlight and @number]", win.document)) - { - let num = elem.getAttribute("number"); - let hintchar = num2chars(parseInt(num, 10)); - elem.setAttribute("hintchar", showCase(hintchar)); - if(isValidHint(hintchar)) - validHints.push(elem); - } - Array.forEach(win.frames, showHints); + let figure = 1; + while((count/=base) >= 1.0) { + ++figure; + } + return Math.pow(base, figure-1) - 1; + } //}}} + function getCharHints(win) //{{{ + { + let hints = []; + (function (win) { + let elems = [elem for(elem in buffer.evaluateXPath("//*[@liberator:highlight and @number]", win.document))]; + hints = hints.concat(elems); + Array.forEach(win.frames, arguments.callee); + })(win); + return hints; + } //}}} + function showCharHints(hints) //{{{ + { + let start = getStartNum(hintchars.length, hints.length); + for(let i=0,len=hints.length;i0) { - let numstr = String(chars2num(hintInput)); - // no setTimeout, don't run nice - setTimeout(function () { - for(let i=0,l=numstr.length;i0) processHintInput(hintInput, hints); }, //}}} onEvent: function (event) //{{{ { @@ -200,10 +208,10 @@ let g:hintsio: hints.onEvent = charhints.onEvent; liberator.eval("onInput = plugins.charhints.onInput", hintContext); - liberator.execute(":hi Hint::after content: attr(hintchar)"); - if(liberator.globalVariables.hintsio) { - let hintsio = liberator.globalVariables.hintsio; - for(let i=hintsio.length;i-->0;setIOType(hintsio[i])); + liberator.execute(":hi Hint::after content: attr(hintchar)", true, true); + if(liberator.globalVariables.hintsinput) { + let hintsinput = liberator.globalVariables.hintsinput; + setInputCase(liberator.globalVariables.hintsinput); } if(liberator.globalVariables.hintchars) { hintchars = liberator.globalVariables.hintchars; -- cgit v1.2.3