diff --git a/gui/console.cpp b/gui/console.cpp index 3c14ecc9a22..1d2f5f2100c 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -149,6 +149,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) _buffer[_promptEndPos % kBufferSize] = ' '; _promptEndPos--; } + scrollToCurrent(); draw(); // FIXME - not nice to redraw the full console just for one char! break; /* @@ -194,6 +195,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) _buffer[(i+1) % kBufferSize] = _buffer[i % kBufferSize]; _promptEndPos++; putchar((char)ascii); + scrollToCurrent(); } } } @@ -352,3 +354,16 @@ void ConsoleDialog::drawCaret(bool erase) _caretVisible = !erase; } + +void ConsoleDialog::scrollToCurrent() +{ + int line = _currentPos / _lineWidth; + int displayLine = line - _scrollLine + _linesPerPage - 1; + + if (displayLine < 0) { + // TODO - this should only occur for loong edit lines, though + } else if (displayLine >= _linesPerPage) { + _scrollLine = _currentPos / _lineWidth; + updateScrollBar(); + } +} diff --git a/gui/console.h b/gui/console.h index 52b6e0ab128..ad764aff5d6 100644 --- a/gui/console.h +++ b/gui/console.h @@ -77,6 +77,7 @@ protected: void print(const char *str); void nextLine(); void updateScrollBar(); + void scrollToCurrent(); inline int getBufferPos() const { return _currentPos % kBufferSize; } // Line editing