Projekt

Obecné

Profil

Stáhnout (2.47 KB) Statistiky
| Větev: | Tag: | Revize:
1
ace.define("ace/ext/spellcheck",["require","exports","module","ace/lib/event","ace/editor","ace/config"], function(require, exports, module) {
2
"use strict";
3
var event = require("../lib/event");
4

    
5
exports.contextMenuHandler = function(e){
6
    var host = e.target;
7
    var text = host.textInput.getElement();
8
    if (!host.selection.isEmpty())
9
        return;
10
    var c = host.getCursorPosition();
11
    var r = host.session.getWordRange(c.row, c.column);
12
    var w = host.session.getTextRange(r);
13

    
14
    host.session.tokenRe.lastIndex = 0;
15
    if (!host.session.tokenRe.test(w))
16
        return;
17
    var PLACEHOLDER = "\x01\x01";
18
    var value = w + " " + PLACEHOLDER;
19
    text.value = value;
20
    text.setSelectionRange(w.length, w.length + 1);
21
    text.setSelectionRange(0, 0);
22
    text.setSelectionRange(0, w.length);
23

    
24
    var afterKeydown = false;
25
    event.addListener(text, "keydown", function onKeydown() {
26
        event.removeListener(text, "keydown", onKeydown);
27
        afterKeydown = true;
28
    });
29

    
30
    host.textInput.setInputHandler(function(newVal) {
31
        if (newVal == value)
32
            return '';
33
        if (newVal.lastIndexOf(value, 0) === 0)
34
            return newVal.slice(value.length);
35
        if (newVal.substr(text.selectionEnd) == value)
36
            return newVal.slice(0, -value.length);
37
        if (newVal.slice(-2) == PLACEHOLDER) {
38
            var val = newVal.slice(0, -2);
39
            if (val.slice(-1) == " ") {
40
                if (afterKeydown)
41
                    return val.substring(0, text.selectionEnd);
42
                val = val.slice(0, -1);
43
                host.session.replace(r, val);
44
                return "";
45
            }
46
        }
47

    
48
        return newVal;
49
    });
50
};
51
var Editor = require("../editor").Editor;
52
require("../config").defineOptions(Editor.prototype, "editor", {
53
    spellcheck: {
54
        set: function(val) {
55
            var text = this.textInput.getElement();
56
            text.spellcheck = !!val;
57
            if (!val)
58
                this.removeListener("nativecontextmenu", exports.contextMenuHandler);
59
            else
60
                this.on("nativecontextmenu", exports.contextMenuHandler);
61
        },
62
        value: true
63
    }
64
});
65

    
66
});                (function() {
67
                    ace.require(["ace/ext/spellcheck"], function(m) {
68
                        if (typeof module == "object" && typeof exports == "object" && module) {
69
                            module.exports = m;
70
                        }
71
                    });
72
                })();
73
            
(16-16/244)