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)
{
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();
}