diff options
author | Ananya Sen | 2012-04-24 12:00:20 -0700 |
---|---|---|
committer | Ananya Sen | 2012-04-24 12:00:20 -0700 |
commit | eab872829c14af251578f95c6f57509acbed660c (patch) | |
tree | b123a0b6abc8af0f8e81da0783c384e4f62c8bad | |
parent | 78b87d056fd2f43e9e8801c859274a1b00b35c33 (diff) | |
download | ninja-eab872829c14af251578f95c6f57509acbed660c.tar.gz |
IKNINJA-1530 : turned off autocompletion and just kept the code hinting
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
-rwxr-xr-x | index.html | 3 | ||||
-rw-r--r-- | js/code-editor/codemirror-ninja-lib/ninja-simple-hint.js | 72 | ||||
-rw-r--r-- | js/controllers/code-editor-controller.js | 2 |
3 files changed, 74 insertions, 3 deletions
@@ -231,11 +231,10 @@ | |||
231 | <script type="text/javascript" src="imports/codemirror/mode/css/css.js"></script> | 231 | <script type="text/javascript" src="imports/codemirror/mode/css/css.js"></script> |
232 | <script type="text/javascript" src="imports/codemirror/lib/util/searchcursor.js"></script> | 232 | <script type="text/javascript" src="imports/codemirror/lib/util/searchcursor.js"></script> |
233 | <script type="text/javascript" src="imports/codemirror/lib/util/match-highlighter.js"></script> | 233 | <script type="text/javascript" src="imports/codemirror/lib/util/match-highlighter.js"></script> |
234 | <script type="text/javascript" src="imports/codemirror/lib/util/simple-hint.js"></script> | 234 | <script type="text/javascript" src="js/code-editor/codemirror-ninja-lib/ninja-simple-hint.js"></script> |
235 | <script type="text/javascript" src="imports/codemirror/lib/util/javascript-hint.js"></script> | 235 | <script type="text/javascript" src="imports/codemirror/lib/util/javascript-hint.js"></script> |
236 | <script type="text/javascript" src="imports/codemirror/lib/util/formatting.js"></script> | 236 | <script type="text/javascript" src="imports/codemirror/lib/util/formatting.js"></script> |
237 | 237 | ||
238 | |||
239 | <script type="text/javascript" src="node_modules/montage/montage.js"></script> | 238 | <script type="text/javascript" src="node_modules/montage/montage.js"></script> |
240 | 239 | ||
241 | <script type="text/montage-serialization"> | 240 | <script type="text/montage-serialization"> |
diff --git a/js/code-editor/codemirror-ninja-lib/ninja-simple-hint.js b/js/code-editor/codemirror-ninja-lib/ninja-simple-hint.js new file mode 100644 index 00000000..e2334a45 --- /dev/null +++ b/js/code-editor/codemirror-ninja-lib/ninja-simple-hint.js | |||
@@ -0,0 +1,72 @@ | |||
1 | (function() { | ||
2 | CodeMirror.simpleHint = function(editor, getHints) { | ||
3 | // We want a single cursor position. | ||
4 | if (editor.somethingSelected()) return; | ||
5 | var result = getHints(editor); | ||
6 | if (!result || !result.list.length) return; | ||
7 | var completions = result.list; | ||
8 | function insert(str) { | ||
9 | editor.replaceRange(str, result.from, result.to); | ||
10 | } | ||
11 | // Ninja override: don't autocomplete to reduce user's typing errors | ||
12 | // if (completions.length == 1) {insert(completions[0]); return true;} | ||
13 | |||
14 | // Build the select widget | ||
15 | var complete = document.createElement("div"); | ||
16 | complete.className = "CodeMirror-completions"; | ||
17 | var sel = complete.appendChild(document.createElement("select")); | ||
18 | // Opera doesn't move the selection when pressing up/down in a | ||
19 | // multi-select, but it does properly support the size property on | ||
20 | // single-selects, so no multi-select is necessary. | ||
21 | if (!window.opera) sel.multiple = true; | ||
22 | for (var i = 0; i < completions.length; ++i) { | ||
23 | var opt = sel.appendChild(document.createElement("option")); | ||
24 | opt.appendChild(document.createTextNode(completions[i])); | ||
25 | } | ||
26 | sel.firstChild.selected = true; | ||
27 | sel.size = Math.min(10, completions.length); | ||
28 | var pos = editor.cursorCoords(); | ||
29 | complete.style.left = pos.x + "px"; | ||
30 | complete.style.top = pos.yBot + "px"; | ||
31 | document.body.appendChild(complete); | ||
32 | // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor. | ||
33 | var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth); | ||
34 | if(winW - pos.x < sel.clientWidth) | ||
35 | complete.style.left = (pos.x - sel.clientWidth) + "px"; | ||
36 | // Hack to hide the scrollbar. | ||
37 | if (completions.length <= 10) | ||
38 | complete.style.width = (sel.clientWidth - 1) + "px"; | ||
39 | |||
40 | var done = false; | ||
41 | function close() { | ||
42 | if (done) return; | ||
43 | done = true; | ||
44 | complete.parentNode.removeChild(complete); | ||
45 | } | ||
46 | function pick() { | ||
47 | insert(completions[sel.selectedIndex]); | ||
48 | close(); | ||
49 | setTimeout(function(){editor.focus();}, 50); | ||
50 | } | ||
51 | CodeMirror.connect(sel, "blur", close); | ||
52 | CodeMirror.connect(sel, "keydown", function(event) { | ||
53 | var code = event.keyCode; | ||
54 | // Enter | ||
55 | if (code == 13) {CodeMirror.e_stop(event); pick();} | ||
56 | // Escape | ||
57 | else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();} | ||
58 | else if (code != 38 && code != 40) { | ||
59 | close(); editor.focus(); | ||
60 | // Pass the event to the CodeMirror instance so that it can handle things like backspace properly. | ||
61 | editor.triggerOnKeyDown(event); | ||
62 | setTimeout(function(){CodeMirror.simpleHint(editor, getHints);}, 50); | ||
63 | } | ||
64 | }); | ||
65 | CodeMirror.connect(sel, "dblclick", pick); | ||
66 | |||
67 | sel.focus(); | ||
68 | // Opera sometimes ignores focusing a freshly created node | ||
69 | if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100); | ||
70 | return true; | ||
71 | }; | ||
72 | })(); | ||
diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 683cbd94..8d7e3117 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js | |||
@@ -28,7 +28,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone | |||
28 | }, | 28 | }, |
29 | 29 | ||
30 | _automaticCodeComplete: { | 30 | _automaticCodeComplete: { |
31 | value:true | 31 | value:false |
32 | }, | 32 | }, |
33 | 33 | ||
34 | automaticCodeComplete:{ | 34 | automaticCodeComplete:{ |