bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
1 |
define('ace/ext/spellcheck', ['require', 'exports', 'module' , 'ace/lib/event', 'ace/editor', 'ace/config'], function(require, exports, module) { |
2 |
||
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 + 1, w.length + 1); |
|
21 |
text.setSelectionRange(0, 0); |
|
22 |
|
|
23 |
var afterKeydown = false; |
|
24 |
event.addListener(text, "keydown", function onKeydown() { |
|
25 |
event.removeListener(text, "keydown", onKeydown); |
|
26 |
afterKeydown = true; |
|
27 |
}); |
|
28 |
||
29 |
host.textInput.setInputHandler(function(newVal) { |
|
30 |
console.log(newVal , value, text.selectionStart, text.selectionEnd) |
|
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 |
});
|
|
67 |