Skip to content

Commit 2813b7b

Browse files
committed
PythonInterpreter: Browse through the command history in the code entry window using Ctrl + up or down arrow
1 parent c54cbc1 commit 2813b7b

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

PythonInterpreter/PythonInterpCtrl.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,37 @@ void PythonCodeCtrl::OnUserInput(wxKeyEvent& ke)
115115
m_pyctrl->DispatchCode(GetValue());
116116
return;
117117
}
118+
if(ke.GetKeyCode()==WXK_UP) //TODO: If the text is ever changed, set m_history_position to -1
119+
{
120+
if (m_history_position < 0)
121+
m_history_working = GetValue();
122+
m_history_position--;
123+
if (m_history_position < -1)
124+
m_history_position = m_history_commands.GetCount()-1;
125+
if (m_history_position >= 0)
126+
SetValue(m_history_commands[m_history_position]);
127+
else
128+
SetValue(m_history_working);
129+
int pos = GetLastPosition();
130+
SetSelection(pos,pos);
131+
return;
132+
}
133+
if(ke.GetKeyCode()==WXK_DOWN)
134+
{
135+
if (m_history_position < 0)
136+
m_history_working = GetValue();
137+
m_history_position++;
138+
if (m_history_position >= int(m_history_commands.GetCount()))
139+
m_history_position = -1;
140+
if (m_history_position >= 0)
141+
SetValue(m_history_commands[m_history_position]);
142+
else
143+
SetValue(m_history_working);
144+
int pos = GetLastPosition();
145+
SetSelection(pos,pos);
146+
return;
147+
}
148+
118149
}
119150
if(ke.GetModifiers()==wxMOD_NONE && ke.GetKeyCode()==WXK_RETURN)
120151
{
@@ -244,6 +275,8 @@ bool PythonInterpCtrl::DispatchCode(const wxString &code)
244275
if(m_pyinterp->IsJobRunning())
245276
return false;
246277
m_code=code;
278+
m_codectrl->m_history_commands.Add(code);
279+
m_codectrl->m_history_position = -1;
247280
if (RunCode(wxString(code.c_str())))
248281
{
249282
m_codectrl->Enable(false);

PythonInterpreter/PythonInterpCtrl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class PythonCodeCtrl: public wxTextCtrl
3838
PythonCodeCtrl(wxWindow *parent, PythonInterpCtrl *py);
3939
void OnUserInput(wxKeyEvent& ke);
4040
PythonInterpCtrl *m_pyctrl;
41+
wxArrayString m_history_commands;
42+
wxString m_history_working;
43+
int m_history_position;
4144
DECLARE_EVENT_TABLE()
4245
};
4346

0 commit comments

Comments
 (0)