From d32e4e642da76a566c12f01a87df45d7a47da44d Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 21 Mar 2024 10:22:09 +0800 Subject: [PATCH] fix #294 - fix: Ctrl+Return insert linebreak shouldn't scroll unnecessarilly. - enhancement: Move caret to line begin would scroll to the begin if possible. --- NEWS.md | 2 ++ libs/qsynedit/qsynedit/qsynedit.cpp | 25 +++++++++++++++---------- libs/qsynedit/qsynedit/qsynedit.h | 6 +++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0691db07..f0b59c84 100644 --- a/NEWS.md +++ b/NEWS.md @@ -63,6 +63,8 @@ Red Panda C++ Version 2.27 - enhancement: Show type completion info after 'const' and 'volatile' - fix: Caret unseen when move to a long line end by press END. - fix: No icons for inherited class private members. + - fix: Ctrl+Return insert linebreak shouldn't scroll unnecessarilly. + - enhancement: Move caret to line begin would scroll to the begin if possible. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 73d57544..77152f60 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -3061,9 +3061,14 @@ void QSynEdit::ensureCursorPosVisibleEx(bool ForceToMiddle) }); // Make sure X is visible int visibleX = displayX(); - if (visibleX < leftPos()) - setLeftPos(visibleX); - else if (visibleX > viewWidth() + leftPos() && viewWidth()>0) + if (visibleX < leftPos()) { + if (viewWidth() / 3 >visibleX) + setLeftPos(0); + else if (viewWidth() > tabWidth() + mCharWidth) + setLeftPos(std::max(0,visibleX - tabWidth())); + else + setLeftPos(visibleX); + } else if (visibleX > viewWidth() + leftPos() && viewWidth()>0) if (viewWidth() >= 3*mCharWidth ) setLeftPos(visibleX - viewWidth() + 3*mCharWidth); else @@ -3100,9 +3105,9 @@ void QSynEdit::setInternalDisplayXY(const DisplayCoord &aPos) decPaintLock(); } -void QSynEdit::internalSetCaretXY(const BufferCoord &Value) +void QSynEdit::internalSetCaretXY(const BufferCoord &Value, bool ensureCaretVisible) { - setCaretXYEx(true, Value); + setCaretXYEx(ensureCaretVisible, Value); } void QSynEdit::internalSetCaretX(int Value) @@ -4871,7 +4876,7 @@ void QSynEdit::moveCaretVert(int deltaY, bool isSelection) mLastCaretColumn = SaveLastCaretX; } -void QSynEdit::moveCaretAndSelection(const BufferCoord &ptBefore, const BufferCoord &ptAfter, bool isSelection) +void QSynEdit::moveCaretAndSelection(const BufferCoord &ptBefore, const BufferCoord &ptAfter, bool isSelection, bool ensureCaretVisible) { if (mOptions.testFlag(EditorOption::eoGroupUndo)) { mUndoList->addGroupBreak(); @@ -4884,7 +4889,7 @@ void QSynEdit::moveCaretAndSelection(const BufferCoord &ptBefore, const BufferCo setBlockEnd(ptAfter); } else setBlockBegin(ptAfter); - internalSetCaretXY(ptAfter); + internalSetCaretXY(ptAfter,ensureCaretVisible); decPaintLock(); } @@ -4912,7 +4917,7 @@ void QSynEdit::moveCaretToLineStart(bool isSelection) moveCaretAndSelection(caretXY(), BufferCoord{newX, mCaretY}, isSelection); } -void QSynEdit::moveCaretToLineEnd(bool isSelection) +void QSynEdit::moveCaretToLineEnd(bool isSelection, bool ensureCaretVisible) { int vNewX; if (mOptions.testFlag(EditorOption::eoEnhanceEndKey)) { @@ -4930,7 +4935,7 @@ void QSynEdit::moveCaretToLineEnd(bool isSelection) } else vNewX = displayLineText().length() + 1; - moveCaretAndSelection(caretXY(), BufferCoord{vNewX, mCaretY}, isSelection); + moveCaretAndSelection(caretXY(), BufferCoord{vNewX, mCaretY}, isSelection, ensureCaretVisible); } void QSynEdit::doGotoBlockStart(bool isSelection) @@ -5765,7 +5770,7 @@ void QSynEdit::executeCommand(EditCommand command, QChar ch, void *pData) beginEditing(); addCaretToUndo(); addSelectionToUndo(); - moveCaretToLineEnd(false); + moveCaretToLineEnd(false, false); insertLine(true); endEditing(); break; diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 44c6a1ab..204c3c90 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -529,7 +529,7 @@ private: void ensureCursorPosVisibleEx(bool ForceToMiddle); void scrollWindow(int dx,int dy); void setInternalDisplayXY(const DisplayCoord& aPos); - void internalSetCaretXY(const BufferCoord& Value); + void internalSetCaretXY(const BufferCoord& Value, bool ensureCaretVisible = true); void internalSetCaretX(int Value); void internalSetCaretY(int Value); void setStatusChanged(StatusChanges changes); @@ -574,9 +574,9 @@ private: void moveCaretHorz(int deltaX, bool isSelection); void moveCaretVert(int deltaY, bool isSelection); void moveCaretAndSelection(const BufferCoord& ptBefore, const BufferCoord& ptAfter, - bool isSelection); + bool isSelection, bool ensureCaretVisible = true); void moveCaretToLineStart(bool isSelection); - void moveCaretToLineEnd(bool isSelection); + void moveCaretToLineEnd(bool isSelection, bool ensureCaretVisible = true); void doGotoBlockStart(bool isSelection); void doGotoBlockEnd(bool isSelection); void doGotoEditorStart(bool isSelection);