@@ -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 );
0 commit comments