From 31aee0cfccda6c2051ebc36ccb844ae1982a5508 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 23 Mar 2024 21:58:45 +0800 Subject: [PATCH] tweak caret movement --- libs/qsynedit/qsynedit/qsynedit.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index be71c48f..2937ab10 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -2981,10 +2981,10 @@ void QSynEdit::ensureCaretVisibleEx(bool ForceToMiddle) if (vCaretRow < yposToRow(0) || vCaretRow>(yposToRow(0) + (mLinesInWindow - 2))) setTopPos( (vCaretRow - (mLinesInWindow - 1) / 2-1) * mTextHeight); } else { - if (vCaretRow < yposToRow(0)) + if ((vCaretRow-1) * mTextHeight < mTopPos) setTopPos( (vCaretRow - 1) * mTextHeight); - else if (vCaretRow > yposToRow(0) + (mLinesInWindow - 2) && mLinesInWindow > 2) { - setTopPos( (vCaretRow - (mLinesInWindow - 2) -1) * mTextHeight); + else if (vCaretRow * mTextHeight > mTopPos + clientHeight() ) { + setTopPos( vCaretRow * mTextHeight - clientHeight()); } else setTopPos(mTopPos); } @@ -5605,7 +5605,12 @@ void QSynEdit::executeCommand(EditCommand command, QChar ch, void *pData) if (command == EditCommand::PageUp || command == EditCommand::SelPageUp) { counter = -counter; } + int gap = (lineToRow(caretY())-1) * mTextHeight - topPos(); + incPaintLock(); + ensureCaretVisible(); moveCaretVert(counter, command == EditCommand::SelPageUp || command == EditCommand::SelPageDown); + setTopPos((lineToRow(caretY())-1) * mTextHeight - gap); + decPaintLock(); break; } case EditCommand::PageTop: