diff --git a/NEWS.md b/NEWS.md index 1ae87a39..63d1a984 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ Red Panda C++ Version 2.25 - fix: Symbol completion of '(' before selection may fail, if cursor is at the beginning of the selection. - change: Symbol completion of '{' won't insert extra new lines. + - fix: "move selection up/down" of whole lines selection are no correctly handled. Red Panda C++ Version 2.24 diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 70c3b568..073a27f3 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -2161,9 +2161,12 @@ void QSynEdit::doMoveSelUp() addCaretToUndo(); addSelectionToUndo(); } + int origBlockBeginLine = selectionBeginLine(); + int origBlockEndLine = selectionEndLine(); BufferCoord origBlockBegin = blockBegin(); BufferCoord origBlockEnd = blockEnd(); - PCodeFoldingRange foldRange=foldStartAtLine(origBlockEnd.line); + + PCodeFoldingRange foldRange=foldStartAtLine(origBlockEndLine); if (foldRange && foldRange->collapsed) return; // for (int line=origBlockBegin.Line;line<=origBlockEnd.Line;line++) { @@ -2173,16 +2176,16 @@ void QSynEdit::doMoveSelUp() // } // Delete line above selection - QString s = mDocument->getLine(origBlockBegin.line - 2); // before start, 0 based - mDocument->deleteAt(origBlockBegin.line - 2); // before start, 0 based - doLinesDeleted(origBlockBegin.line - 1, 1); // before start, 1 based + QString s = mDocument->getLine(origBlockBeginLine - 2); // before start, 0 based + mDocument->deleteAt(origBlockBeginLine - 2); // before start, 0 based + doLinesDeleted(origBlockBeginLine - 1, 1); // before start, 1 based // Insert line below selection - mDocument->insertLine(origBlockEnd.line - 1, s); - doLinesInserted(origBlockEnd.line, 1); + mDocument->insertLine(origBlockEndLine - 1, s); + doLinesInserted(origBlockEndLine, 1); // Restore caret and selection setCaretAndSelection( - BufferCoord{mCaretX, origBlockBegin.line - 1}, + BufferCoord{mCaretX, origBlockBeginLine - 1}, BufferCoord{origBlockBegin.ch, origBlockBegin.line - 1}, BufferCoord{origBlockEnd.ch, origBlockEnd.line - 1} ); @@ -2207,21 +2210,23 @@ void QSynEdit::doMoveSelDown() addCaretToUndo(); addSelectionToUndo(); } + int origBlockBeginLine = selectionBeginLine(); + int origBlockEndLine = selectionEndLine(); BufferCoord origBlockBegin = blockBegin(); BufferCoord origBlockEnd = blockEnd(); - PCodeFoldingRange foldRange=foldStartAtLine(origBlockEnd.line); + PCodeFoldingRange foldRange=foldStartAtLine(origBlockEndLine); if (foldRange && foldRange->collapsed) return; // Delete line below selection - QString s = mDocument->getLine(origBlockEnd.line); // after end, 0 based - mDocument->deleteAt(origBlockEnd.line); // after end, 0 based - doLinesDeleted(origBlockEnd.line, 1); // before start, 1 based + QString s = mDocument->getLine(origBlockEndLine); // after end, 0 based + mDocument->deleteAt(origBlockEndLine); // after end, 0 based + doLinesDeleted(origBlockEndLine, 1); // before start, 1 based // Insert line above selection - mDocument->insertLine(origBlockBegin.line - 1, s); - doLinesInserted(origBlockBegin.line, 1); + mDocument->insertLine(origBlockBeginLine - 1, s); + doLinesInserted(origBlockBeginLine , 1); // Restore caret and selection setCaretAndSelection( @@ -6743,6 +6748,30 @@ BufferCoord QSynEdit::blockEnd() const return mBlockEnd; } +int QSynEdit::selectionBeginLine() const +{ + if (mActiveSelectionMode == SelectionMode::Column) { + return (mBlockBegin.line < mBlockEnd.line)? mBlockBegin.line : mBlockEnd.line; + } else { + return (mBlockBegin.line < mBlockEnd.line)? mBlockBegin.line : mBlockEnd.line; + } +} + +int QSynEdit::selectionEndLine() const +{ + if (mActiveSelectionMode == SelectionMode::Column) { + return (mBlockBegin.line < mBlockEnd.line)? mBlockEnd.line : mBlockBegin.line; + } else { + if (mBlockBegin.line < mBlockEnd.line) { + return (mBlockEnd.ch==1)?mBlockEnd.line-1 : mBlockEnd.line; + } else if (mBlockBegin.line == mBlockEnd.line){ + return mBlockBegin.line; + } else { + return (mBlockBegin.ch==1)?mBlockBegin.line-1 : mBlockBegin.line; + } + } +} + void QSynEdit::clearSelection() { setActiveSelectionMode(SelectionMode::Normal); diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 250b2578..ef0e17f7 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -320,6 +320,8 @@ public: BufferCoord blockBegin() const; BufferCoord blockEnd() const; + int selectionBeginLine() const; + int selectionEndLine() const; void clearSelection(); void setBlockBegin(BufferCoord value);