summaryrefslogtreecommitdiffstats
path: root/vimfx/frame.js
blob: 7782fad3fc7c17555c71e9d6a78894120c8c6bfd (plain) (blame)
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
let {utils: Cu} = Components;
let {
    isEditableInput,
    insertAtCursor,
    killBackwardFromCursor,
    cleanTagName,
    lineEditingCallbacks,
} = Cu.import(`${__dirname}/shared.js`, {});

let findActiveElement = (document) => {
    let inner = (document) => {
        let active = document.activeElement;
        if (active) {
            let tag = cleanTagName(active);
            if (tag == "iframe") {
                return inner(active.contentDocument);
            }
            else {
                return active;
            }
        }
    };
    return inner(document);
};

let lineEditingBinding = (name) => {
    vimfx.listen(name, (data, cb) => {
        let active = findActiveElement(content.document);
        if (active && isEditableInput(active)) {
            lineEditingCallbacks[name](active, data);
        }
    });
};

lineEditingBinding('paste');
lineEditingBinding('kill_backward');
lineEditingBinding('start_of_line');
lineEditingBinding('end_of_line');

sendAsyncMessage('VimFx-config:tabCreated');