corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 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 console.log(newVal , value, text.selectionStart, text.selectionEnd)
32 if (newVal == value)
33 return '';
34 if (newVal.lastIndexOf(value, 0) === 0)
35 return newVal.slice(value.length);
36 if (newVal.substr(text.selectionEnd) == value)
37 return newVal.slice(0, -value.length);
38 if (newVal.slice(-2) == PLACEHOLDER) {
39 var val = newVal.slice(0, -2);
40 if (val.slice(-1) == " ") {
41 if (afterKeydown)
42 return val.substring(0, text.selectionEnd);
43 val = val.slice(0, -1);
44 host.session.replace(r, val);
45 return "";
46 }
47 }
48  
49 return newVal;
50 });
51 };
52 var Editor = require("../editor").Editor;
53 require("../config").defineOptions(Editor.prototype, "editor", {
54 spellcheck: {
55 set: function(val) {
56 var text = this.textInput.getElement();
57 text.spellcheck = !!val;
58 if (!val)
59 this.removeListener("nativecontextmenu", exports.contextMenuHandler);
60 else
61 this.on("nativecontextmenu", exports.contextMenuHandler);
62 },
63 value: true
64 }
65 });
66  
67 });
68 (function() {
69 window.require(["ace/ext/spellcheck"], function() {});
70 })();
71