when updating the highlight also update cursor position

This commit is contained in:
Axel Kohlmeyer
2023-08-25 17:35:29 -04:00
parent 6759a20cfc
commit 6cc021bcaf
2 changed files with 13 additions and 2 deletions

View File

@ -96,7 +96,18 @@ void CodeEditor::setFont(const QFont &newfont)
void CodeEditor::setHighlight(int block) void CodeEditor::setHighlight(int block)
{ {
highlight = block; highlight = block;
// also move cursor to current position
auto cursor = textCursor();
int moves = block - cursor.blockNumber();
if (moves < 0)
cursor.movePosition(QTextCursor::Up, QTextCursor::MoveAnchor, -moves);
else
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, moves);
setTextCursor(cursor);
// update graphics
repaint(); repaint();
} }

View File

@ -922,7 +922,7 @@ void LammpsGui::do_run(bool use_buffer)
logupdater = new QTimer(this); logupdater = new QTimer(this);
connect(logupdater, &QTimer::timeout, this, &LammpsGui::logupdate); connect(logupdater, &QTimer::timeout, this, &LammpsGui::logupdate);
logupdater->start(50); logupdater->start(100);
} }
void LammpsGui::render_image() void LammpsGui::render_image()