aboutsummaryrefslogtreecommitdiffstats
path: root/ime_controller.js
blob: bc8588c67aa587a12af54c0496b3c1f503328eb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
 * ==VimperatorPlugin==
 * @name              IME Controller Lite
 * @description       control imput method at into commandline-mode
 * @description-ja    コマンドラインモード移行時にIMEの制御を行う
 * @author            teramako teramako@gmail.com
 * @namespace         http://d.hatena.ne.jp/teramako/
 * @maxVersion        0.6pre
 * @minVersion        0.6pre
 * ==/VimperatorPlugin==
 *
 *  Please set g:ex_ime_mode and g:textarea_ime_mode value.
 *  
 *  g:ex_ime_mode:
 *   used at into EX mode
 *  
 *  g:textarea_ime_mode:
 *   used at into TEXTAREA mode from INSERT mode and "noinsertmode" is set.
 *  
 *  ex).
 *  :let g:ex_ime_mode = "inactive"
 *  :let g:textarea_ime_mode = "inactive"
 *
 *  following values are available:
 *      "auto"     : No change
 *      "active"   : Initially IME on
 *      "inactive" : Initially IME off
 *      "disabled"  : Disable IME
 *
 *  more details: see http://developer.mozilla.org/en/docs/CSS:ime-mode
 *
 *  if these values are null, "inactive" is used
 *
 */

if(!liberator.plugins) vimperator.plugins = {}; 
liberator.plugins.imeController = (function(){
    var inputElement = document.getAnonymousElementByAttribute(
        document.getElementById('liberator-commandline-command'),'anonid','input'
    );  
    function getMode(name){
        return globalVariables[name] ? globalVariables[name] : 'inactive';
    }   
    function preExec(target,name,func){
        var original = target[name];
        target[name] = function(){
            func.apply(this,arguments);
            return original.apply(target,arguments);
        }   
    }   
    preExec(commandline,'open',function(){
        liberator.plugins.imeController.set(inputElement, getMode('ex_ime_mode'));
    }); 
    preExec(events,'onEscape',function(){
        if (liberator.mode == liberator.modes.INSERT && (liberator.modes.extended & liberator.modes.TEXTAREA) && !liberator.options.insertmode){
            var inputField = liberator.buffer.lastInputField;
            if (liberator.plugins.imeController.set(inputField, getMode('textarea_ime_mode'))){
                inputField.blur();
                setTimeout(function(){inputField.focus();},0);
            }   
        }   
    }); 
    return {
        set: function(elem, mode){
            if (elem && mode) return elem.style.imeMode = mode;
            return false;
        },  
        reset: function(){
            delete globalVariables.ex_ime_mode;
            delete globalVariables.textarea_ime_mode;
        }   
    };  
})();
// vim: sw=4 ts=4 et: