- # Control+UpArrow steps up through the history.
- elif key == WXK_UP and event.ControlDown() \
- and self.historyPos < len(self.history) - 1:
- # Move to the end of the buffer.
- endpos = self.GetTextLength()
- self.SetCurrentPos(endpos)
- # The first Control+Up stores the current command;
- # Control+Down brings it back.
- if self.historyPos == -1:
- self.tempCommand = self.getCommand()
- # Now replace the current line with the next one from the history.
- self.historyPos = self.historyPos + 1
- self.SetSelection(stoppos, endpos)
- self.ReplaceSelection(self.history[self.historyPos])
- # Control+DownArrow steps down through the history.
- elif key == WXK_DOWN and event.ControlDown():
- # Move to the end of the buffer.
- endpos = self.GetTextLength()
- self.SetCurrentPos(endpos)
- # Are we at the bottom end of the history?
- if self.historyPos == -1:
- # Do we have a lastCommandRecalled stored?
- if self.lastCommandRecalled >= 0:
- # Replace the current line with the command after the
- # last-recalled command (you'd think there should be a +1
- # here but there isn't because the history was shuffled up
- # by 1 after the previous command was recalled).
- self.SetSelection(stoppos, endpos)
- self.ReplaceSelection(self.history[self.lastCommandRecalled])
- # We've now warped into middle of the history.
- self.historyPos = self.lastCommandRecalled
- self.lastCommandRecalled = -1
- else:
- # Fetch either the previous line from the history, or the saved
- # command if we're back at the start.
- self.historyPos = self.historyPos - 1
- if self.historyPos == -1:
- newText = self.tempCommand
- else:
- newText = self.history[self.historyPos]
- # Replace the current line with the new text.
- self.SetSelection(stoppos, endpos)
- self.ReplaceSelection(newText)
- # F8 on the last line does a search up the history for the text in
- # front of the cursor.
- elif key == WXK_F8 and self.GetCurrentLine() == self.GetLineCount()-1:
- tempCommand = self.getCommand()
- # The first F8 saves the current command, just like Control+Up.
- if self.historyPos == -1:
- self.tempCommand = tempCommand
- # The text up to the cursor is what we search for.
- searchText = tempCommand
- numCharsAfterCursor = self.GetTextLength() - self.GetCurrentPos()
- if numCharsAfterCursor > 0:
- searchText = searchText[:-numCharsAfterCursor]
- # Search upwards from the current history position and loop back
- # to the beginning if we don't find anything.
- for i in range(self.historyPos+1, len(self.history)) + \
- range(self.historyPos):
- command = self.history[i]
- if command[:len(searchText)] == searchText:
- # Replace the current line with the one we've found.
- endpos = self.GetTextLength()
- self.SetSelection(stoppos, endpos)
- self.ReplaceSelection(command)
- # Put the cursor back at the end of the search text.
- pos = self.GetTextLength() - len(command) + len(searchText)
- self.SetCurrentPos(pos)
- self.SetAnchor(pos)
- # We've now warped into middle of the history.
- self.historyPos = i
- self.lastCommandRecalled = -1
- break