Show More
@@ -3,7 +3,7 b' span.py-special {color: #666666;}' | |||||
3 |
|
3 | |||
4 | span.py-operator {color: #AA22FF; font-weight: bold;} |
|
4 | span.py-operator {color: #AA22FF; font-weight: bold;} | |
5 |
|
5 | |||
6 | span.py-error {background-color: #000000; color: #FF0000;} |
|
6 | /*span.py-error {background-color: #000000; color: #FF0000;}*/ | |
7 |
|
7 | |||
8 | span.py-keyword {color: #008000; font-weight: bold;} |
|
8 | span.py-keyword {color: #008000; font-weight: bold;} | |
9 |
|
9 | |||
@@ -20,4 +20,4 b' span.py-comment {color: #408080; font-style: italic;}' | |||||
20 | span.py-string, |
|
20 | span.py-string, | |
21 | span.py-bytes, |
|
21 | span.py-bytes, | |
22 | span.py-raw, |
|
22 | span.py-raw, | |
23 | span.py-unicode {color: #BA2121;} No newline at end of file |
|
23 | span.py-unicode {color: #BA2121;} |
@@ -353,6 +353,19 b' div.text_cell_render ol ol ol ol ol {list-style:lower-roman;}' | |||||
353 | .ansigrey {color: grey;} |
|
353 | .ansigrey {color: grey;} | |
354 | .ansibold {font-weight: bold;} |
|
354 | .ansibold {font-weight: bold;} | |
355 |
|
355 | |||
|
356 | .completions { | |||
|
357 | position: absolute; | |||
|
358 | z-index: 10; | |||
|
359 | overflow: auto; | |||
|
360 | border: 1px solid black; | |||
|
361 | } | |||
356 |
|
362 | |||
|
363 | .completions select { | |||
|
364 | background: white; | |||
|
365 | outline: none; | |||
|
366 | border: none; | |||
|
367 | padding: 0px; | |||
|
368 | margin: 0px; | |||
|
369 | font-family: monospace; | |||
|
370 | } | |||
357 |
|
371 | |||
358 | } No newline at end of file |
|
@@ -10,6 +10,8 b' var IPython = (function (IPython) {' | |||||
10 | var CodeCell = function (notebook) { |
|
10 | var CodeCell = function (notebook) { | |
11 | this.code_mirror = null; |
|
11 | this.code_mirror = null; | |
12 | this.input_prompt_number = ' '; |
|
12 | this.input_prompt_number = ' '; | |
|
13 | this.is_completing = false; | |||
|
14 | this.completion_cursor = null; | |||
13 | IPython.Cell.apply(this, arguments); |
|
15 | IPython.Cell.apply(this, arguments); | |
14 | }; |
|
16 | }; | |
15 |
|
17 | |||
@@ -43,11 +45,93 b' var IPython = (function (IPython) {' | |||||
43 | if (event.keyCode === 13 && event.shiftKey) { |
|
45 | if (event.keyCode === 13 && event.shiftKey) { | |
44 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
46 | // Always ignore shift-enter in CodeMirror as we handle it. | |
45 | return true; |
|
47 | return true; | |
|
48 | } else if (event.keyCode == 32 && (event.ctrlKey || event.metaKey) && !event.altKey) { | |||
|
49 | event.stop(); | |||
|
50 | var cur = editor.getCursor(); | |||
|
51 | var line = editor.getLine(cur.line); | |||
|
52 | this.is_completing = true; | |||
|
53 | this.completion_cursor = cur; | |||
|
54 | IPython.notebook.complete_cell(this, line, cur.ch); | |||
46 | } else { |
|
55 | } else { | |
|
56 | if (this.is_completing && this.completion_cursor !== editor.getCursor()) { | |||
|
57 | this.is_completing = false; | |||
|
58 | this.completion_cursor = null; | |||
|
59 | console.log("Stopped completing early"); | |||
|
60 | } | |||
47 | return false; |
|
61 | return false; | |
48 | }; |
|
62 | }; | |
49 | }; |
|
63 | }; | |
50 |
|
64 | |||
|
65 | ||||
|
66 | CodeCell.prototype.finish_completing = function (matched_text, matches) { | |||
|
67 | if (!this.is_completing || matches.length === 0) {return;} | |||
|
68 | // console.log("Got matches", matched_text, matches); | |||
|
69 | ||||
|
70 | var that = this; | |||
|
71 | var cur = this.completion_cursor; | |||
|
72 | var complete = $('<div/>').addClass('completions'); | |||
|
73 | var select = $('<select/>').attr('multiple','true'); | |||
|
74 | for (var i=0; i<matches.length; ++i) { | |||
|
75 | select.append($('<option/>').text(matches[i])); | |||
|
76 | } | |||
|
77 | select.children().first().attr('selected','true'); | |||
|
78 | select.attr('size',Math.min(10,matches.length)); | |||
|
79 | var pos = this.code_mirror.cursorCoords(); | |||
|
80 | complete.css('left',pos.x+'px'); | |||
|
81 | complete.css('top',pos.yBot+'px'); | |||
|
82 | complete.append(select); | |||
|
83 | ||||
|
84 | $('body').append(complete); | |||
|
85 | var done = false; | |||
|
86 | ||||
|
87 | var insert = function (selected_text) { | |||
|
88 | that.code_mirror.replaceRange( | |||
|
89 | selected_text, | |||
|
90 | {line: cur.line, ch: (cur.ch-matched_text.length)}, | |||
|
91 | {line: cur.line, ch: cur.ch} | |||
|
92 | ); | |||
|
93 | }; | |||
|
94 | ||||
|
95 | var close = function () { | |||
|
96 | if (done) return; | |||
|
97 | done = true; | |||
|
98 | complete.remove(); | |||
|
99 | that.is_completing = false; | |||
|
100 | that.completion_cursor = null; | |||
|
101 | }; | |||
|
102 | ||||
|
103 | var pick = function () { | |||
|
104 | insert(select.val()[0]); | |||
|
105 | close(); | |||
|
106 | setTimeout(function(){that.code_mirror.focus();}, 50); | |||
|
107 | }; | |||
|
108 | ||||
|
109 | select.blur(close); | |||
|
110 | select.keydown(function (event) { | |||
|
111 | var code = event.which; | |||
|
112 | if (code === 13 || code === 32) { | |||
|
113 | // Pressing SPACE or ENTER will cause a pick | |||
|
114 | event.stopPropagation(); | |||
|
115 | event.preventDefault(); | |||
|
116 | pick(); | |||
|
117 | } else if (code === 38 || code === 40) { | |||
|
118 | // We don't want the document keydown handler to handle UP/DOWN, | |||
|
119 | // but we want the default action. | |||
|
120 | event.stopPropagation(); | |||
|
121 | } else { | |||
|
122 | // All other key presses simple exit completion. | |||
|
123 | event.stopPropagation(); | |||
|
124 | event.preventDefault(); | |||
|
125 | close(); | |||
|
126 | that.code_mirror.focus(); | |||
|
127 | } | |||
|
128 | }); | |||
|
129 | // Double click also causes a pick. | |||
|
130 | select.dblclick(pick); | |||
|
131 | select.focus(); | |||
|
132 | }; | |||
|
133 | ||||
|
134 | ||||
51 | CodeCell.prototype.select = function () { |
|
135 | CodeCell.prototype.select = function () { | |
52 | IPython.Cell.prototype.select.apply(this); |
|
136 | IPython.Cell.prototype.select.apply(this); | |
53 | this.code_mirror.focus(); |
|
137 | this.code_mirror.focus(); |
@@ -18,7 +18,7 b' var IPython = (function (IPython) {' | |||||
18 | var msg = { |
|
18 | var msg = { | |
19 | header : { |
|
19 | header : { | |
20 | msg_id : utils.uuid(), |
|
20 | msg_id : utils.uuid(), | |
21 |
username : " |
|
21 | username : "username", | |
22 | session: this.session_id, |
|
22 | session: this.session_id, | |
23 | msg_type : msg_type |
|
23 | msg_type : msg_type | |
24 | }, |
|
24 | }, |
@@ -403,7 +403,7 b' var IPython = (function (IPython) {' | |||||
403 | if (msg_type === "execute_reply") { |
|
403 | if (msg_type === "execute_reply") { | |
404 | cell.set_input_prompt(content.execution_count); |
|
404 | cell.set_input_prompt(content.execution_count); | |
405 | } else if (msg_type === "complete_reply") { |
|
405 | } else if (msg_type === "complete_reply") { | |
406 | console.log(content); |
|
406 | cell.finish_completing(content.matched_text, content.matches); | |
407 | }; |
|
407 | }; | |
408 | var payload = content.payload || []; |
|
408 | var payload = content.payload || []; | |
409 | this.handle_payload(payload); |
|
409 | this.handle_payload(payload); | |
@@ -505,6 +505,12 b' var IPython = (function (IPython) {' | |||||
505 | this.scroll_to_bottom(); |
|
505 | this.scroll_to_bottom(); | |
506 | }; |
|
506 | }; | |
507 |
|
507 | |||
|
508 | ||||
|
509 | Notebook.prototype.complete_cell = function (cell, line, cursor_pos) { | |||
|
510 | var msg_id = this.kernel.complete(line, cursor_pos); | |||
|
511 | this.msg_cell_map[msg_id] = cell.cell_id; | |||
|
512 | }; | |||
|
513 | ||||
508 | // Persistance and loading |
|
514 | // Persistance and loading | |
509 |
|
515 | |||
510 |
|
516 |
General Comments 0
You need to be logged in to leave comments.
Login now