@@ -217,11 +217,6 @@ LuaConsoleDock::LuaConsoleDock(LuaState *l, QWidget *parent) :
217217 input->braceHighlight (INVALID_POSITION, INVALID_POSITION);
218218 }
219219 });
220-
221- connect (input, &ScintillaNext::linesAdded, [=](int linesAdded) {
222- if (input->lineCount () > 0 )
223- qInfo (" lines added %d" , linesAdded);
224- });
225220}
226221
227222LuaConsoleDock::~LuaConsoleDock ()
@@ -262,6 +257,50 @@ void LuaConsoleDock::writeErrorToOutput(const char *s)
262257 output->documentEnd ();
263258}
264259
260+ void LuaConsoleDock::historyNext ()
261+ {
262+ if (history.isEmpty ()) return ;
263+
264+ if (currentHistoryIndex < history.size () - 1 ) {
265+ currentHistoryIndex++;
266+ input->setText (history[currentHistoryIndex].toLatin1 ().constData ());
267+ }
268+
269+ input->documentEnd ();
270+ input->emptyUndoBuffer ();
271+ input->scrollToEnd ();
272+ }
273+
274+ void LuaConsoleDock::historyPrevious ()
275+ {
276+ if (currentHistoryIndex == 0 ) return ;
277+
278+ currentHistoryIndex--;
279+
280+ input->setText (history[currentHistoryIndex].toLatin1 ().constData ());
281+ input->documentEnd ();
282+ input->emptyUndoBuffer ();
283+ input->scrollToEnd ();
284+ }
285+
286+ void LuaConsoleDock::historyAdd (QString line)
287+ {
288+ if (!line.isEmpty ()) {
289+ if (history.isEmpty () || history.last () != line) {
290+ history.append (line);
291+ }
292+ }
293+
294+ currentHistoryIndex = history.size ();
295+ }
296+
297+ void LuaConsoleDock::historyEnd ()
298+ {
299+ currentHistoryIndex = history.size ();
300+ input->emptyUndoBuffer (); // Empty first in case it was a mistake
301+ input->setText (" " );
302+ }
303+
265304void LuaConsoleDock::runCurrentCommand ()
266305{
267306 int prevLastLine = output->lineCount ();
@@ -289,7 +328,7 @@ void LuaConsoleDock::runCurrentCommand()
289328 }
290329
291330 QString text ((const char *)input->characterPointer ());
292- // historyAdd(GUI::StringFromUTF8( text).c_str() );
331+ historyAdd (text);
293332
294333 input->clearAll ();
295334 input->emptyUndoBuffer ();
@@ -307,11 +346,32 @@ bool LuaConsoleDock::eventFilter(QObject *obj, QEvent *event)
307346 runCurrentCommand ();
308347 return true ;
309348 }
349+
350+ if (keyEvent->key () == Qt::Key_Up)
351+ {
352+ if (input->lineCount () == 1 || input->currentPos () == input->length ()) {
353+ historyPrevious ();
354+ return true ;
355+ }
356+ }
357+
358+ if (keyEvent->key () == Qt::Key_Down) {
359+ if (input->lineCount () == 1 || input->currentPos () == 0 ) {
360+ historyNext ();
361+ return true ;
362+ }
363+ }
364+
365+ if (keyEvent->key () == Qt::Key_Escape) {
366+ historyEnd ();
367+ return true ;
368+ }
310369 }
311370 else {
312371 // standard event processing
313372 return QObject::eventFilter (obj, event);
314373 }
374+
315375 return false ;
316376}
317377
0 commit comments