// PLUGIN_INFO//{{{
var PLUGIN_INFO =
    {NAME}
    character hint mode.
    hogelog
    0.1.1
    2.0pre 2008/12/12
    2.0a1
    2008/12/22 14:57:34
    http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/char-hints-mod2.js
    
    
;
//}}}
(function () {
    const DEFAULT_HINTCHARS = "HJKLASDFGYUIOPQWERTNMZXCVB";
    const hintContext = hints.addMode;
    let hintchars = DEFAULT_HINTCHARS;
    let inputCase = function(str) str.toUpperCase();
    let inputRegex = /[A-Z]/;
    let showCase = function(str) str.toUpperCase();
    function chars2num(chars) //{{{
    {
        let num = 0;
        hintchars = inputCase(hintchars);
        let base = hintchars.length;
        for(let i=0,l=chars.length;i0);
        return chars;
    } //}}}
    function showCharHints() //{{{
    {
        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);
        }
        validHints = [];
        showHints(window.content);
    } //}}}
    function isValidHint(hint) //{{{
    {
        if(hintInput.length == 0 ) return false;
        return inputCase(hint).indexOf(hintInput) == 0;
    } //}}}
    function setIOType(type) //{{{
    {
        switch (type)
        {
            case "I":
                inputCase = function(str) str.toUpperCase();
                inputRegex = /[A-Z]/;
                break;
            case "i":
                inputCase = function(str) str.toLowerCase();
                inputRegex = /[a-z]/;
                break;
            case "O":
                showCase = function(str) str.toUpperCase();
                break;
            case "o":
                showCase = function(str) str.toLowerCase();
                break;
        }
    } //}}}
    var hintInput = "";
    var validHints = [];
    var charhints = plugins.charhints = {
        show: function (minor, filter, win) //{{{
        {
            charhints.original.show(minor, filter, win);
            hintInput = "";
            showCharHints();
        }, //}}}
        onInput: function (event) //{{{
        {
            let eventkey = events.toString(event);
            if(/^\d$/.test(eventkey)) {
                commandline.command += eventkey;
            }
            let hintString = commandline.command;
            commandline.command = hintString.replace(inputRegex, "");
            charhints.original.onInput(event);
            for(let i=0,l=hintString.length;i0) {
                let numstr = String(chars2num(hintInput));
                // no setTimeout, don't run nice
                setTimeout(function () {
                    for(let i=0,l=numstr.length;i