- enhancement: Press left/right arrow will move caret to the begin/end of the selection.

- enhancement: Press up/down arrow will move caret up/down from the begin/end of the selection.
This commit is contained in:
Roy Qu 2023-08-03 15:11:46 +08:00
parent 9be257e8e8
commit d3760db7ec
3 changed files with 63 additions and 48 deletions

View File

@ -7,6 +7,9 @@ Red Panda C++ Version 2.24
- fix: Goto definition/declaration may choose wrong symbol is multiple files are opened and symbols have the same name. - fix: Goto definition/declaration may choose wrong symbol is multiple files are opened and symbols have the same name.
- fix: "UTF-8 BOM" can't be correctly loaded as project file's encoding. - fix: "UTF-8 BOM" can't be correctly loaded as project file's encoding.
- fix: Project file's encoding is not correctly updated after converted manually. - fix: Project file's encoding is not correctly updated after converted manually.
- enhancement: Press left/right arrow will move caret to the begin/end of the selection.
- enhancement: Press up/down arrow will move caret up/down from the begin/end of the selection.
Red Panda C++ Version 2.23 Red Panda C++ Version 2.23

View File

@ -4739,13 +4739,18 @@ void QSynEdit::processCommand(EditCommand Command, QChar AChar, void *pData)
onCommandProcessed(Command, AChar, pData); onCommandProcessed(Command, AChar, pData);
} }
void QSynEdit::moveCaretHorz(int DX, bool isSelection) void QSynEdit::moveCaretHorz(int deltaX, bool isSelection)
{ {
BufferCoord ptO = caretXY(); BufferCoord ptO = caretXY();
BufferCoord ptDst = ptO; BufferCoord ptDst = ptO;
QString s = displayLineText(); QString s = displayLineText();
int nLineLen = s.length(); int nLineLen = s.length();
if (!isSelection && selAvail() && (deltaX!=0)) {
if (deltaX<0)
ptDst = blockBegin();
else
ptDst = blockEnd();
} else {
if (mOptions.testFlag(eoAltSetsColumnMode) && if (mOptions.testFlag(eoAltSetsColumnMode) &&
(mActiveSelectionMode != SelectionMode::Line)) { (mActiveSelectionMode != SelectionMode::Line)) {
if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) { if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) {
@ -4757,7 +4762,7 @@ void QSynEdit::moveCaretHorz(int DX, bool isSelection)
// only moving or selecting one char can change the line // only moving or selecting one char can change the line
//bool bChangeY = !mOptions.testFlag(SynEditorOption::eoScrollPastEol); //bool bChangeY = !mOptions.testFlag(SynEditorOption::eoScrollPastEol);
bool bChangeY=true; bool bChangeY=true;
if (bChangeY && (DX == -1) && (ptO.ch == 1) && (ptO.line > 1)) { if (bChangeY && (deltaX == -1) && (ptO.ch == 1) && (ptO.line > 1)) {
// end of previous line // end of previous line
if (mActiveSelectionMode==SelectionMode::Column) { if (mActiveSelectionMode==SelectionMode::Column) {
return; return;
@ -4769,7 +4774,7 @@ void QSynEdit::moveCaretHorz(int DX, bool isSelection)
ptDst.line = line; ptDst.line = line;
ptDst.ch = getDisplayStringAtLine(ptDst.line).length() + 1; ptDst.ch = getDisplayStringAtLine(ptDst.line).length() + 1;
} }
} else if (bChangeY && (DX == 1) && (ptO.ch > nLineLen) && (ptO.line < mDocument->count())) { } else if (bChangeY && (deltaX == 1) && (ptO.ch > nLineLen) && (ptO.line < mDocument->count())) {
// start of next line // start of next line
if (mActiveSelectionMode==SelectionMode::Column) { if (mActiveSelectionMode==SelectionMode::Column) {
return; return;
@ -4783,11 +4788,12 @@ void QSynEdit::moveCaretHorz(int DX, bool isSelection)
ptDst.ch = 1; ptDst.ch = 1;
} }
} else { } else {
ptDst.ch = std::max(1, ptDst.ch + DX); ptDst.ch = std::max(1, ptDst.ch + deltaX);
// don't go past last char when ScrollPastEol option not set // don't go past last char when ScrollPastEol option not set
if ((DX > 0) && bChangeY) if ((deltaX > 0) && bChangeY)
ptDst.ch = std::min(ptDst.ch, nLineLen + 1); ptDst.ch = std::min(ptDst.ch, nLineLen + 1);
} }
}
// set caret and block begin / end // set caret and block begin / end
incPaintLock(); incPaintLock();
@ -4795,13 +4801,19 @@ void QSynEdit::moveCaretHorz(int DX, bool isSelection)
decPaintLock(); decPaintLock();
} }
void QSynEdit::moveCaretVert(int DY, bool isSelection) void QSynEdit::moveCaretVert(int deltaY, bool isSelection)
{ {
DisplayCoord ptO = displayXY(); DisplayCoord ptO = displayXY();
DisplayCoord ptDst = ptO; DisplayCoord ptDst = ptO;
ptDst.Row+=DY; if (!isSelection && selAvail()) {
if (deltaY<0)
ptDst = bufferToDisplayPos(blockBegin());
else
ptDst = bufferToDisplayPos(blockEnd());
}
ptDst.Row+=deltaY;
if (DY >= 0) { if (deltaY >= 0) {
if (rowToLine(ptDst.Row) > mDocument->count()) { if (rowToLine(ptDst.Row) > mDocument->count()) {
ptDst.Row = std::max(1, displayLineCount()); ptDst.Row = std::max(1, displayLineCount());
} }
@ -4824,7 +4836,7 @@ void QSynEdit::moveCaretVert(int DY, bool isSelection)
} }
BufferCoord vDstLineChar; BufferCoord vDstLineChar;
if (ptDst.Row == ptO.Row && isSelection && DY!=0) { if (ptDst.Row == ptO.Row && isSelection && deltaY!=0) {
if (ptDst.Row==1) { if (ptDst.Row==1) {
vDstLineChar.ch=1; vDstLineChar.ch=1;
vDstLineChar.line=1; vDstLineChar.line=1;

View File

@ -536,8 +536,8 @@ private:
* @param DX * @param DX
* @param SelectionCommand * @param SelectionCommand
*/ */
void moveCaretHorz(int DX, bool isSelection); void moveCaretHorz(int deltaX, bool isSelection);
void moveCaretVert(int DY, bool isSelection); void moveCaretVert(int deltaY, bool isSelection);
void moveCaretAndSelection(const BufferCoord& ptBefore, const BufferCoord& ptAfter, void moveCaretAndSelection(const BufferCoord& ptBefore, const BufferCoord& ptAfter,
bool isSelection); bool isSelection);
void moveCaretToLineStart(bool isSelection); void moveCaretToLineStart(bool isSelection);