- fix: copy & paste in column mode not correctly handled

This commit is contained in:
Roy Qu 2022-05-19 12:32:33 +08:00
parent 67cd580539
commit 3090fab089
2 changed files with 29 additions and 15 deletions

View File

@ -12,6 +12,7 @@ Red Panda C++ Version 1.0.8
- fix: selection in column mode not correctly drawn when has wide chars in it - fix: selection in column mode not correctly drawn when has wide chars in it
- fix: delete & insert in column mode not correctly handled - fix: delete & insert in column mode not correctly handled
- fix: input with ime in column mode not correctly handled - fix: input with ime in column mode not correctly handled
- fix: copy & paste in column mode not correctly handled
Red Panda C++ Version 1.0.7 Red Panda C++ Version 1.0.7

View File

@ -2576,8 +2576,12 @@ QRect SynEdit::calculateCaretRect() const
+ lineText().mid(mCaretX-1); + lineText().mid(mCaretX-1);
coord.Column = charToColumn(sLine,mCaretX+mInputPreeditString.length()); coord.Column = charToColumn(sLine,mCaretX+mInputPreeditString.length());
} }
int rows=1;
if (mActiveSelectionMode == SynSelectionMode::smColumn) { if (mActiveSelectionMode == SynSelectionMode::smColumn) {
coord.Row = lineToRow(blockBegin().Line); int startRow = lineToRow(std::min(blockBegin().Line, blockEnd().Line));
int endRow = lineToRow(std::max(blockBegin().Line, blockEnd().Line));
coord.Row = startRow;
rows = endRow-startRow+1;
} }
QPoint caretPos = rowColumnToPixels(coord); QPoint caretPos = rowColumnToPixels(coord);
int caretWidth=mCharWidth; int caretWidth=mCharWidth;
@ -2586,9 +2590,7 @@ QRect SynEdit::calculateCaretRect() const
} }
if (mActiveSelectionMode == SynSelectionMode::smColumn) { if (mActiveSelectionMode == SynSelectionMode::smColumn) {
return QRect(caretPos.x(),caretPos.y(),caretWidth, return QRect(caretPos.x(),caretPos.y(),caretWidth,
mTextHeight*(lineToRow(blockEnd().Line)- mTextHeight*(rows));
lineToRow(blockBegin().Line)+1));
} else { } else {
return QRect(caretPos.x(),caretPos.y(),caretWidth, return QRect(caretPos.x(),caretPos.y(),caretWidth,
mTextHeight); mTextHeight);
@ -3036,7 +3038,16 @@ void SynEdit::doPasteFromClipboard()
mBlockBegin = vStartOfBlock; mBlockBegin = vStartOfBlock;
mBlockEnd = vEndOfBlock; mBlockEnd = vEndOfBlock;
setSelTextPrimitive(clipboard->text()); setSelTextPrimitive(clipboard->text());
if (mActiveSelectionMode != SynSelectionMode::smColumn) { if (mActiveSelectionMode == SynSelectionMode::smColumn) {
mUndoList->AddChange(
SynChangeReason::crPaste,
blockBegin(),
blockEnd(),
selText(),
mActiveSelectionMode);
} else {
// setBlockBegin(vStartOfBlock);
// setBlockEnd(caretXY());
mUndoList->AddChange( mUndoList->AddChange(
SynChangeReason::crPaste, SynChangeReason::crPaste,
vStartOfBlock, vStartOfBlock,
@ -4779,17 +4790,19 @@ QString SynEdit::selText()
} }
case SynSelectionMode::smColumn: case SynSelectionMode::smColumn:
{ {
First = blockBegin().Line-1; First = blockBegin().Line;
ColFrom = charToColumn(blockBegin().Line, blockBegin().Char); ColFrom = charToColumn(blockBegin().Line, blockBegin().Char);
Last = blockEnd().Line - 1; Last = blockEnd().Line;
ColTo = charToColumn(blockEnd().Line, blockEnd().Char); ColTo = charToColumn(blockEnd().Line, blockEnd().Char);
if (ColFrom > ColTo) if (ColFrom > ColTo)
std::swap(ColFrom, ColTo); std::swap(ColFrom, ColTo);
if (First>Last)
std::swap(First,Last);
QString result; QString result;
for (int i = First; i <= Last; i++) { for (int i = First; i <= Last; i++) {
int l = columnToChar(i+1,ColFrom); int l = columnToChar(i,ColFrom);
int r = columnToChar(i+1,ColTo-1)+1; int r = columnToChar(i,ColTo-1)+1;
QString s = mDocument->getString(i); QString s = mDocument->getString(i-1);
result += s.mid(l-1,r-l); result += s.mid(l-1,r-l);
if (i<Last) if (i<Last)
result+=lineBreak(); result+=lineBreak();