##// END OF EJS Templates
History is now working. + misc keybindings.
Gael Varoquaux -
Show More
@@ -141,7 +141,7 b' class IFrontEnd(Interface):'
141 141 pass
142 142
143 143
144 def get_history_previous(currentBlock):
144 def get_history_previous(current_block):
145 145 """Returns the block previous in the history. Saves currentBlock if
146 146 the history_cursor is currently at the end of the input history"""
147 147 pass
@@ -294,14 +294,14 b' class FrontEndBase(object):'
294 294 return result
295 295
296 296
297 def get_history_previous(self, currentBlock):
297 def get_history_previous(self, current_block):
298 298 """ Returns previous history string and decrement history cursor.
299 299 """
300 300 command = self.history.get_history_item(self.history_cursor - 1)
301 301
302 302 if command is not None:
303 if(self.history_cursor == len(self.history.input_cache)):
304 self.history.input_cache[self.history_cursor] = currentBlock
303 if(self.history_cursor+1 == len(self.history.input_cache)):
304 self.history.input_cache[self.history_cursor] = current_block
305 305 self.history_cursor -= 1
306 306 return command
307 307
@@ -31,11 +31,6 b' class LineFrontEndBase(FrontEndBase):'
31 31 # Are we entering multi line input?
32 32 multi_line_input = False
33 33
34 # The added tab stop to the string. It may, for instance, come from
35 # copy and pasting something with tabs.
36 tab_stop = 0
37 # FIXME: We still have to deal with this.
38
39 34 #--------------------------------------------------------------------------
40 35 # Public API
41 36 #--------------------------------------------------------------------------
@@ -81,7 +76,7 b' class LineFrontEndBase(FrontEndBase):'
81 76 return failure
82 77
83 78
84 def on_enter(self):
79 def _on_enter(self):
85 80 """ Called when the return key is pressed in a line editing
86 81 buffer.
87 82 """
@@ -93,11 +88,14 b' class LineFrontEndBase(FrontEndBase):'
93 88 if ( not self.multi_line_input
94 89 or re.findall(r"\n[\t ]*$", cleaned_buffer)):
95 90 if self.is_complete(cleaned_buffer):
96 self._add_history(None, cleaned_buffer.rstrip())
91 self.history.input_cache[-1] = \
92 current_buffer
97 93 result = self.shell.execute(cleaned_buffer)
98 94 self.render_result(result)
99 95 self.new_prompt(self.prompt % (result['number'] + 1))
100 96 self.multi_line_input = False
97 # Start a new empty history entry
98 self._add_history(None, '')
101 99 else:
102 100 if self.multi_line_input:
103 101 self.write('\n' + self._get_indent_string(current_buffer))
@@ -113,6 +113,7 b' class ConsoleWidget(editwindow.EditWindow):'
113 113 self.autocomplete_mode = autocomplete_mode
114 114
115 115 self.Bind(wx.EVT_KEY_DOWN, self._on_key_down)
116 self.Bind(wx.EVT_KEY_UP, self._on_key_up)
116 117
117 118
118 119 def configure_scintilla(self):
@@ -124,11 +125,11 b' class ConsoleWidget(editwindow.EditWindow):'
124 125 self.CmdKeyAssign(ord('='), stc.STC_SCMOD_CTRL|stc.STC_SCMOD_SHIFT,
125 126 stc.STC_CMD_ZOOMIN)
126 127
127 self.CmdKeyAssign(stc.STC_KEY_PRIOR, stc.STC_SCMOD_SHIFT,
128 stc.STC_CMD_PAGEUP)
128 #self.CmdKeyAssign(stc.STC_KEY_PRIOR, stc.STC_SCMOD_SHIFT,
129 # stc.STC_CMD_PAGEUP)
129 130
130 self.CmdKeyAssign(stc.STC_KEY_NEXT, stc.STC_SCMOD_SHIFT,
131 stc.STC_CMD_PAGEDOWN)
131 #self.CmdKeyAssign(stc.STC_KEY_NEXT, stc.STC_SCMOD_SHIFT,
132 # stc.STC_CMD_PAGEDOWN)
132 133
133 134 # Keys: we need to clear some of the keys the that don't play
134 135 # well with a console.
@@ -259,17 +260,6 b' class ConsoleWidget(editwindow.EditWindow):'
259 260 self.StyleSetSpec(style[0], "bold,fore:%s" % style[1])
260 261
261 262
262 def removeFromTo(self, from_pos, to_pos):
263 if from_pos < to_pos:
264 self.SetSelection(from_pos, to_pos)
265 self.DeleteBack()
266
267
268 def selectFromTo(self, from_pos, to_pos):
269 self.SetSelectionStart(from_pos)
270 self.SetSelectionEnd(to_pos)
271
272
273 263 def writeCompletion(self, possibilities):
274 264 if self.autocomplete_mode == 'IPYTHON':
275 265 max_len = len(max(possibilities, key=len))
@@ -310,6 +300,11 b' class ConsoleWidget(editwindow.EditWindow):'
310 300 maxrange = self.GetScrollRange(wx.VERTICAL)
311 301 self.ScrollLines(maxrange)
312 302
303 def on_enter(self):
304 """ Called when the return key is hit.
305 """
306 pass
307
313 308
314 309 def _on_key_down(self, event, skip=True):
315 310 """ Key press callback used for correcting behavior for
@@ -319,22 +314,35 b' class ConsoleWidget(editwindow.EditWindow):'
319 314 Return True if event as been catched.
320 315 """
321 316 catched = False
317 # Intercept some specific keys.
322 318 if event.KeyCode == ord('L') and event.ControlDown() :
323 skip = False
324 319 catched = True
325 320 self.scroll_to_bottom()
321 elif event.KeyCode == wx.WXK_PAGEUP and event.ShiftDown():
322 catched = True
323 self.ScrollPages(-1)
324 elif event.KeyCode == wx.WXK_PAGEDOWN and event.ShiftDown():
325 catched = True
326 self.ScrollPages(1)
326 327
327 328 if self.AutoCompActive():
328 329 event.Skip()
329 330 else:
330 if event.KeyCode == wx.WXK_HOME:
331 if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \
332 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
333 catched = True
334 self._on_enter()
335
336 elif event.KeyCode == wx.WXK_HOME:
331 337 if event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
332 338 self.GotoPos(self.current_prompt_pos)
333 339 catched = True
334 340
335 341 elif event.Modifiers in (wx.MOD_SHIFT, wx.MOD_WIN) :
336 self.selectFromTo(self.current_prompt_pos,
337 self.GetCurrentPos())
342 # FIXME: This behavior is not ideal: if the selection
343 # is already started, it will jump.
344 self.SetSelectionStart(self.current_prompt_pos)
345 self.SetSelectionEnd(self.GetCurrentPos())
338 346 catched = True
339 347
340 348 elif event.KeyCode == wx.WXK_UP:
@@ -355,14 +363,16 b' class ConsoleWidget(editwindow.EditWindow):'
355 363 if skip and not catched:
356 364 event.Skip()
357 365
358 if event.KeyCode not in (wx.WXK_PAGEUP, wx.WXK_PAGEDOWN)\
359 and event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN,
360 wx.MOD_SHIFT):
361 # If cursor is outside the editing region, put it back.
366 return catched
367
368
369 def _on_key_up(self, event, skip=True):
370 """ If cursor is outside the editing region, put it back.
371 """
372 event.Skip()
362 373 if self.GetCurrentPos() < self.current_prompt_pos:
363 374 self.GotoPos(self.current_prompt_pos)
364 375
365 return catched
366 376
367 377
368 378
@@ -63,12 +63,8 b' class IPythonWxController(LineFrontEndBase, ConsoleWidget):'
63 63 widget handle them, and put our logic afterward.
64 64 """
65 65 current_line_number = self.GetCurrentLine()
66 # Capture enter
67 if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \
68 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
69 self.on_enter()
70 66 # Up history
71 elif event.KeyCode == wx.WXK_UP and (
67 if event.KeyCode == wx.WXK_UP and (
72 68 ( current_line_number == self.current_prompt_line and
73 69 event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN) )
74 70 or event.ControlDown() ):
@@ -76,6 +72,9 b' class IPythonWxController(LineFrontEndBase, ConsoleWidget):'
76 72 self.get_current_edit_buffer())
77 73 if new_buffer is not None:
78 74 self.replace_current_edit_buffer(new_buffer)
75 if self.GetCurrentLine() > self.current_prompt_line:
76 # Go to first line, for seemless history up.
77 self.GotoPos(self.current_prompt_pos)
79 78 # Down history
80 79 elif event.KeyCode == wx.WXK_DOWN and (
81 80 ( current_line_number == self.LineCount -1 and
@@ -85,7 +84,7 b' class IPythonWxController(LineFrontEndBase, ConsoleWidget):'
85 84 if new_buffer is not None:
86 85 self.replace_current_edit_buffer(new_buffer)
87 86 else:
88 ConsoleWidget._on_key_down(self, event, skip=True)
87 ConsoleWidget._on_key_down(self, event, skip=skip)
89 88
90 89
91 90
@@ -56,7 +56,7 b' class History(object):'
56 56 """ Returns the history string at index, where index is the
57 57 distance from the end (positive).
58 58 """
59 if index>0 and index<len(self.input_cache):
59 if index>=0 and index<len(self.input_cache):
60 60 return self.input_cache[index]
61 61
62 62
General Comments 0
You need to be logged in to leave comments. Login now