work save: redo done
This commit is contained in:
parent
655f0bf83e
commit
39dd7e3abb
|
@ -463,7 +463,7 @@ void MainWindow::updateEditorActions()
|
||||||
ui->actionConvert_to_UTF_8_BOM->setEnabled(e->encodingOption()!=ENCODING_UTF8_BOM && e->fileEncoding()!=ENCODING_UTF8_BOM);
|
ui->actionConvert_to_UTF_8_BOM->setEnabled(e->encodingOption()!=ENCODING_UTF8_BOM && e->fileEncoding()!=ENCODING_UTF8_BOM);
|
||||||
|
|
||||||
ui->actionCopy->setEnabled(e->selAvail());
|
ui->actionCopy->setEnabled(e->selAvail());
|
||||||
ui->actionCut->setEnabled(e->selAvail());
|
ui->actionCut->setEnabled(true);
|
||||||
ui->actionFoldAll->setEnabled(e->document()->count()>0);
|
ui->actionFoldAll->setEnabled(e->document()->count()>0);
|
||||||
ui->actionIndent->setEnabled(!e->readOnly());
|
ui->actionIndent->setEnabled(!e->readOnly());
|
||||||
|
|
||||||
|
|
|
@ -664,3 +664,8 @@ QStringList splitStrings(const QString &text)
|
||||||
list.append(text.mid(start,i));
|
list.append(text.mid(start,i));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int calSpanLines(const BufferCoord &startPos, const BufferCoord &endPos)
|
||||||
|
{
|
||||||
|
return std::abs(endPos.Line - startPos.Line+1);
|
||||||
|
}
|
||||||
|
|
|
@ -83,6 +83,8 @@ int CountLines(const QString& Line, int start);
|
||||||
|
|
||||||
QStringList splitStrings(const QString& text);
|
QStringList splitStrings(const QString& text);
|
||||||
|
|
||||||
|
int calSpanLines(const BufferCoord& startPos, const BufferCoord& endPos);
|
||||||
|
|
||||||
// Remove all '/' characters from string by changing them into '\.'.
|
// Remove all '/' characters from string by changing them into '\.'.
|
||||||
// Change all '\' characters into '\\' to allow for unique decoding.
|
// Change all '\' characters into '\\' to allow for unique decoding.
|
||||||
QString EncodeString(const QString & s);
|
QString EncodeString(const QString & s);
|
||||||
|
|
|
@ -2012,6 +2012,7 @@ void SynEdit::doDeleteLastChar()
|
||||||
setSelectedTextEmpty();
|
setSelectedTextEmpty();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
bool shouldAddGroupBreak=false;
|
||||||
QString Temp = lineText();
|
QString Temp = lineText();
|
||||||
int Len = Temp.length();
|
int Len = Temp.length();
|
||||||
BufferCoord Caret = caretXY();
|
BufferCoord Caret = caretXY();
|
||||||
|
@ -2031,6 +2032,7 @@ void SynEdit::doDeleteLastChar()
|
||||||
setLineText(lineText() + Temp);
|
setLineText(lineText() + Temp);
|
||||||
helper.append("");
|
helper.append("");
|
||||||
helper.append("");
|
helper.append("");
|
||||||
|
shouldAddGroupBreak=true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// delete text before the caret
|
// delete text before the caret
|
||||||
|
@ -2053,14 +2055,19 @@ void SynEdit::doDeleteLastChar()
|
||||||
} else {
|
} else {
|
||||||
// delete char
|
// delete char
|
||||||
internalSetCaretX(mCaretX - 1);
|
internalSetCaretX(mCaretX - 1);
|
||||||
helper.append(QString(Temp[mCaretX-1]));
|
QChar ch=Temp[mCaretX-1];
|
||||||
|
if (ch==' ' || ch=='\t')
|
||||||
|
shouldAddGroupBreak=true;
|
||||||
|
helper.append(QString(ch));
|
||||||
Temp.remove(mCaretX-1,1);
|
Temp.remove(mCaretX-1,1);
|
||||||
properSetLine(mCaretY - 1, Temp);
|
properSetLine(mCaretY - 1, Temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((Caret.Char != mCaretX) || (Caret.Line != mCaretY)) {
|
if ((Caret.Char != mCaretX) || (Caret.Line != mCaretY)) {
|
||||||
mUndoList->AddChange(SynChangeReason::crDelete, caretXY(), Caret, helper,
|
mUndoList->AddChange(SynChangeReason::crDelete, caretXY(), Caret, helper,
|
||||||
SynSelectionMode::smNormal);
|
mActiveSelectionMode);
|
||||||
|
if (shouldAddGroupBreak)
|
||||||
|
mUndoList->AddGroupBreak();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2068,8 +2075,14 @@ void SynEdit::doDeleteCurrentChar()
|
||||||
{
|
{
|
||||||
QStringList helper;
|
QStringList helper;
|
||||||
BufferCoord Caret;
|
BufferCoord Caret;
|
||||||
if (!mReadOnly) {
|
if (mReadOnly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
doOnPaintTransient(SynTransientType::ttBefore);
|
doOnPaintTransient(SynTransientType::ttBefore);
|
||||||
|
auto action = finally([this]{
|
||||||
|
ensureCursorPosVisible();
|
||||||
|
doOnPaintTransient(SynTransientType::ttAfter);
|
||||||
|
});
|
||||||
|
|
||||||
if (mActiveSelectionMode==SynSelectionMode::smColumn) {
|
if (mActiveSelectionMode==SynSelectionMode::smColumn) {
|
||||||
BufferCoord start=blockBegin();
|
BufferCoord start=blockBegin();
|
||||||
|
@ -2080,18 +2093,23 @@ void SynEdit::doDeleteCurrentChar()
|
||||||
setBlockEnd(end);
|
setBlockEnd(end);
|
||||||
}
|
}
|
||||||
setSelectedTextEmpty();
|
setSelectedTextEmpty();
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
if (selAvail())
|
if (selAvail())
|
||||||
setSelectedTextEmpty();
|
setSelectedTextEmpty();
|
||||||
else {
|
else {
|
||||||
|
bool shouldAddGroupBreak=false;
|
||||||
// Call UpdateLastCaretX. Even though the caret doesn't move, the
|
// Call UpdateLastCaretX. Even though the caret doesn't move, the
|
||||||
// current caret position should "stick" whenever text is modified.
|
// current caret position should "stick" whenever text is modified.
|
||||||
updateLastCaretX();
|
updateLastCaretX();
|
||||||
QString Temp = lineText();
|
QString Temp = lineText();
|
||||||
int Len = Temp.length();
|
int Len = Temp.length();
|
||||||
if (mCaretX <= Len) {
|
if (mCaretX <= Len) {
|
||||||
|
QChar ch = Temp[mCaretX-1];
|
||||||
|
if (ch==' ' || ch=='\t')
|
||||||
|
shouldAddGroupBreak=true;
|
||||||
// delete char
|
// delete char
|
||||||
helper.append(Temp.mid(mCaretX-1, 1));
|
helper.append(QString(ch));
|
||||||
Caret.Char = mCaretX + 1;
|
Caret.Char = mCaretX + 1;
|
||||||
Caret.Line = mCaretY;
|
Caret.Line = mCaretY;
|
||||||
Temp.remove(mCaretX-1, 1);
|
Temp.remove(mCaretX-1, 1);
|
||||||
|
@ -2099,6 +2117,7 @@ void SynEdit::doDeleteCurrentChar()
|
||||||
} else {
|
} else {
|
||||||
// join line with the line after
|
// join line with the line after
|
||||||
if (mCaretY < mDocument->count()) {
|
if (mCaretY < mDocument->count()) {
|
||||||
|
shouldAddGroupBreak=true;
|
||||||
properSetLine(mCaretY - 1, Temp + mDocument->getString(mCaretY));
|
properSetLine(mCaretY - 1, Temp + mDocument->getString(mCaretY));
|
||||||
Caret.Char = 1;
|
Caret.Char = 1;
|
||||||
Caret.Line = mCaretY + 1;
|
Caret.Line = mCaretY + 1;
|
||||||
|
@ -2113,12 +2132,11 @@ void SynEdit::doDeleteCurrentChar()
|
||||||
}
|
}
|
||||||
if ((Caret.Char != mCaretX) || (Caret.Line != mCaretY)) {
|
if ((Caret.Char != mCaretX) || (Caret.Line != mCaretY)) {
|
||||||
mUndoList->AddChange(SynChangeReason::crDelete, caretXY(), Caret,
|
mUndoList->AddChange(SynChangeReason::crDelete, caretXY(), Caret,
|
||||||
helper, SynSelectionMode::smNormal);
|
helper, mActiveSelectionMode);
|
||||||
|
if (shouldAddGroupBreak)
|
||||||
|
mUndoList->AddGroupBreak();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
doOnPaintTransient(SynTransientType::ttAfter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::doDeleteWord()
|
void SynEdit::doDeleteWord()
|
||||||
|
@ -4234,7 +4252,7 @@ void SynEdit::doUndo()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Remove Group Break;
|
//Remove Group Break;
|
||||||
if (mUndoList->LastChangeReason() == SynChangeReason::crNothing) {
|
if (mUndoList->LastChangeReason() == SynChangeReason::crGroupBreak) {
|
||||||
int OldBlockNumber = mRedoList->blockChangeNumber();
|
int OldBlockNumber = mRedoList->blockChangeNumber();
|
||||||
auto action = finally([&,this]{
|
auto action = finally([&,this]{
|
||||||
mRedoList->setBlockChangeNumber(OldBlockNumber);
|
mRedoList->setBlockChangeNumber(OldBlockNumber);
|
||||||
|
@ -4254,8 +4272,8 @@ void SynEdit::doUndo()
|
||||||
mRedoList->setBlockChangeNumber(SaveChangeNumber);
|
mRedoList->setBlockChangeNumber(SaveChangeNumber);
|
||||||
});
|
});
|
||||||
//skip group chain breakers
|
//skip group chain breakers
|
||||||
if (mUndoList->LastChangeReason()==SynChangeReason::crNothing) {
|
if (mUndoList->LastChangeReason()==SynChangeReason::crGroupBreak) {
|
||||||
while (!mUndoList->isEmpty() && mUndoList->LastChangeReason()==SynChangeReason::crNothing) {
|
while (!mUndoList->isEmpty() && mUndoList->LastChangeReason()==SynChangeReason::crGroupBreak) {
|
||||||
doUndoItem();
|
doUndoItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4363,10 +4381,12 @@ void SynEdit::doUndoItem()
|
||||||
case SynChangeReason::crDelete: {
|
case SynChangeReason::crDelete: {
|
||||||
// If there's no selection, we have to set
|
// If there's no selection, we have to set
|
||||||
// the Caret's position manualy.
|
// the Caret's position manualy.
|
||||||
qDebug()<<"undo delete";
|
// qDebug()<<"undo delete";
|
||||||
qDebug()<<Item->changeText();
|
// qDebug()<<Item->changeText();
|
||||||
qDebug()<<Item->changeStartPos().Line<<Item->changeStartPos().Char;
|
// qDebug()<<Item->changeStartPos().Line<<Item->changeStartPos().Char;
|
||||||
doInsertText(Item->changeStartPos(),Item->changeText(),Item->changeSelMode());
|
doInsertText(Item->changeStartPos(),Item->changeText(),Item->changeSelMode(),
|
||||||
|
Item->changeStartPos().Line,
|
||||||
|
Item->changeEndPos().Line);
|
||||||
internalSetCaretXY(Item->changeEndPos());
|
internalSetCaretXY(Item->changeEndPos());
|
||||||
mRedoList->AddChange(
|
mRedoList->AddChange(
|
||||||
Item->changeReason(),
|
Item->changeReason(),
|
||||||
|
@ -4374,50 +4394,6 @@ void SynEdit::doUndoItem()
|
||||||
Item->changeEndPos(),
|
Item->changeEndPos(),
|
||||||
Item->changeText(),
|
Item->changeText(),
|
||||||
Item->changeSelMode());
|
Item->changeSelMode());
|
||||||
// BufferCoord TmpPos;
|
|
||||||
// if (Item->changeSelMode() == SynSelectionMode::smColumn) {
|
|
||||||
// BufferCoord BB = Item->changeStartPos();
|
|
||||||
// BufferCoord BE = Item->changeEndPos();
|
|
||||||
// int First = std::min(BB.Line,BE.Line);
|
|
||||||
// int ColFrom = charToColumn(BB.Line, BB.Char);
|
|
||||||
// int ColTo = charToColumn(BE.Line, BE.Char);
|
|
||||||
// if (ColFrom > ColTo)
|
|
||||||
// ColFrom = ColTo;
|
|
||||||
// TmpPos.Line = First;
|
|
||||||
// TmpPos.Char = columnToChar(First,ColFrom);
|
|
||||||
// } else {
|
|
||||||
// TmpPos = BufferCoord{
|
|
||||||
// minBufferCoord(
|
|
||||||
// Item->changeStartPos(),
|
|
||||||
// Item->changeEndPos())};
|
|
||||||
// }
|
|
||||||
// if ( (Item->changeReason() == SynChangeReason::crDeleteAfterCursor
|
|
||||||
// || Item->changeReason() == SynChangeReason::crSilentDeleteAfterCursor)
|
|
||||||
// && (TmpPos.Line > mDocument->count())) {
|
|
||||||
// internalSetCaretXY(BufferCoord{1, mDocument->count()});
|
|
||||||
// mDocument->add("");
|
|
||||||
// }
|
|
||||||
// setCaretXY(TmpPos);
|
|
||||||
// setSelTextPrimitiveEx(
|
|
||||||
// Item->changeSelMode(),
|
|
||||||
// Item->changeStr(),
|
|
||||||
// false);
|
|
||||||
// if ( (Item->changeReason() == SynChangeReason::crDeleteAfterCursor
|
|
||||||
// || Item->changeReason() == SynChangeReason::crSilentDeleteAfterCursor)) {
|
|
||||||
// TmpPos = Item->changeStartPos();
|
|
||||||
// internalSetCaretXY(TmpPos);
|
|
||||||
// } else {
|
|
||||||
// TmpPos = Item->changeEndPos();
|
|
||||||
// setCaretAndSelection(TmpPos,
|
|
||||||
// Item->changeStartPos(),
|
|
||||||
// Item->changeEndPos());
|
|
||||||
// }
|
|
||||||
mRedoList->AddChange(
|
|
||||||
Item->changeReason(),
|
|
||||||
Item->changeStartPos(),
|
|
||||||
Item->changeEndPos(),
|
|
||||||
QStringList(),
|
|
||||||
Item->changeSelMode());
|
|
||||||
ensureCursorPosVisible();
|
ensureCursorPosVisible();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4467,8 +4443,8 @@ void SynEdit::doRedo()
|
||||||
mUndoList->setBlockChangeNumber(SaveChangeNumber);
|
mUndoList->setBlockChangeNumber(SaveChangeNumber);
|
||||||
});
|
});
|
||||||
//skip group chain breakers
|
//skip group chain breakers
|
||||||
if (mRedoList->LastChangeReason()==SynChangeReason::crNothing) {
|
if (mRedoList->LastChangeReason()==SynChangeReason::crGroupBreak) {
|
||||||
while (!mRedoList->isEmpty() && mRedoList->LastChangeReason()==SynChangeReason::crNothing) {
|
while (!mRedoList->isEmpty() && mRedoList->LastChangeReason()==SynChangeReason::crGroupBreak) {
|
||||||
doRedoItem();
|
doRedoItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4492,7 +4468,7 @@ void SynEdit::doRedo()
|
||||||
|
|
||||||
}
|
}
|
||||||
//Remove Group Break
|
//Remove Group Break
|
||||||
if (mRedoList->LastChangeReason() == SynChangeReason::crNothing) {
|
if (mRedoList->LastChangeReason() == SynChangeReason::crGroupBreak) {
|
||||||
int OldBlockNumber = mUndoList->blockChangeNumber();
|
int OldBlockNumber = mUndoList->blockChangeNumber();
|
||||||
Item = mRedoList->PopItem();
|
Item = mRedoList->PopItem();
|
||||||
{
|
{
|
||||||
|
@ -4584,7 +4560,9 @@ void SynEdit::doRedoItem()
|
||||||
Item->changeStartPos(),
|
Item->changeStartPos(),
|
||||||
Item->changeStartPos(),
|
Item->changeStartPos(),
|
||||||
Item->changeStartPos());
|
Item->changeStartPos());
|
||||||
doInsertText(Item->changeStartPos(),Item->changeText(), Item->changeSelMode());
|
doInsertText(Item->changeStartPos(),Item->changeText(), Item->changeSelMode(),
|
||||||
|
Item->changeStartPos().Line,
|
||||||
|
Item->changeEndPos().Line);
|
||||||
internalSetCaretXY(Item->changeEndPos());
|
internalSetCaretXY(Item->changeEndPos());
|
||||||
mUndoList->AddChange(Item->changeReason(),
|
mUndoList->AddChange(Item->changeReason(),
|
||||||
Item->changeStartPos(),
|
Item->changeStartPos(),
|
||||||
|
@ -4889,6 +4867,9 @@ void SynEdit::moveCaretHorz(int DX, bool isSelection)
|
||||||
bool bChangeY=true;
|
bool bChangeY=true;
|
||||||
if (bChangeY && (DX == -1) && (ptO.Char == 1) && (ptO.Line > 1)) {
|
if (bChangeY && (DX == -1) && (ptO.Char == 1) && (ptO.Line > 1)) {
|
||||||
// end of previous line
|
// end of previous line
|
||||||
|
if (mActiveSelectionMode==SynSelectionMode::smColumn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int row = lineToRow(ptDst.Line);
|
int row = lineToRow(ptDst.Line);
|
||||||
row--;
|
row--;
|
||||||
int line = rowToLine(row);
|
int line = rowToLine(row);
|
||||||
|
@ -4898,6 +4879,9 @@ void SynEdit::moveCaretHorz(int DX, bool isSelection)
|
||||||
}
|
}
|
||||||
} else if (bChangeY && (DX == 1) && (ptO.Char > nLineLen) && (ptO.Line < mDocument->count())) {
|
} else if (bChangeY && (DX == 1) && (ptO.Char > nLineLen) && (ptO.Line < mDocument->count())) {
|
||||||
// start of next line
|
// start of next line
|
||||||
|
if (mActiveSelectionMode==SynSelectionMode::smColumn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int row = lineToRow(ptDst.Line);
|
int row = lineToRow(ptDst.Line);
|
||||||
row++;
|
row++;
|
||||||
int line = rowToLine(row);
|
int line = rowToLine(row);
|
||||||
|
@ -4930,6 +4914,7 @@ void SynEdit::moveCaretVert(int DY, bool isSelection)
|
||||||
DisplayCoord ptO = displayXY();
|
DisplayCoord ptO = displayXY();
|
||||||
DisplayCoord ptDst = ptO;
|
DisplayCoord ptDst = ptO;
|
||||||
|
|
||||||
|
|
||||||
ptDst.Row+=DY;
|
ptDst.Row+=DY;
|
||||||
if (DY >= 0) {
|
if (DY >= 0) {
|
||||||
if (rowToLine(ptDst.Row) > mDocument->count())
|
if (rowToLine(ptDst.Row) > mDocument->count())
|
||||||
|
@ -4944,6 +4929,14 @@ void SynEdit::moveCaretVert(int DY, bool isSelection)
|
||||||
ptDst.Column = mLastCaretColumn;
|
ptDst.Column = mLastCaretColumn;
|
||||||
}
|
}
|
||||||
BufferCoord vDstLineChar = displayToBufferPos(ptDst);
|
BufferCoord vDstLineChar = displayToBufferPos(ptDst);
|
||||||
|
|
||||||
|
if (mActiveSelectionMode==SynSelectionMode::smColumn) {
|
||||||
|
QString s=mDocument->getString(vDstLineChar.Line-1);
|
||||||
|
int cols=stringColumns(s,0);
|
||||||
|
if (cols+1<ptO.Column)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int SaveLastCaretX = mLastCaretColumn;
|
int SaveLastCaretX = mLastCaretColumn;
|
||||||
|
|
||||||
// set caret and block begin / end
|
// set caret and block begin / end
|
||||||
|
@ -5042,7 +5035,7 @@ void SynEdit::setSelTextPrimitive(const QStringList &text)
|
||||||
void SynEdit::setSelTextPrimitiveEx(SynSelectionMode mode, const QStringList &text)
|
void SynEdit::setSelTextPrimitiveEx(SynSelectionMode mode, const QStringList &text)
|
||||||
{
|
{
|
||||||
incPaintLock();
|
incPaintLock();
|
||||||
bool groupUndo;
|
bool groupUndo=false;
|
||||||
BufferCoord startPos = blockBegin();
|
BufferCoord startPos = blockBegin();
|
||||||
BufferCoord endPos = blockEnd();
|
BufferCoord endPos = blockEnd();
|
||||||
if (mode==SynSelectionMode::smNormal) {
|
if (mode==SynSelectionMode::smNormal) {
|
||||||
|
@ -5099,7 +5092,7 @@ void SynEdit::setSelTextPrimitiveEx(SynSelectionMode mode, const QStringList &te
|
||||||
internalSetCaretXY(startPos);
|
internalSetCaretXY(startPos);
|
||||||
}
|
}
|
||||||
if (!text.isEmpty()) {
|
if (!text.isEmpty()) {
|
||||||
doInsertText(caretXY(),text,mode);
|
doInsertText(caretXY(),text,mode,mBlockBegin.Line,mBlockEnd.Line);
|
||||||
}
|
}
|
||||||
if (groupUndo) {
|
if (groupUndo) {
|
||||||
mUndoList->EndBlock();
|
mUndoList->EndBlock();
|
||||||
|
@ -5363,8 +5356,6 @@ void SynEdit::doDeleteText(const BufferCoord &startPos, const BufferCoord &endPo
|
||||||
bool UpdateMarks = false;
|
bool UpdateMarks = false;
|
||||||
int MarkOffset = 0;
|
int MarkOffset = 0;
|
||||||
QStringList deleted=getContent(startPos,endPos,mode);
|
QStringList deleted=getContent(startPos,endPos,mode);
|
||||||
qDebug()<<"D----";
|
|
||||||
qDebug()<<deleted;
|
|
||||||
|
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case SynSelectionMode::smNormal:
|
case SynSelectionMode::smNormal:
|
||||||
|
@ -5437,9 +5428,11 @@ void SynEdit::doDeleteText(const BufferCoord &startPos, const BufferCoord &endPo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::doInsertText(const BufferCoord& pos, const QStringList& text, SynSelectionMode mode) {
|
void SynEdit::doInsertText(const BufferCoord& pos, const QStringList& text, SynSelectionMode mode, int startLine, int endLine) {
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
if (startLine>endLine)
|
||||||
|
std::swap(startLine,endLine);
|
||||||
|
|
||||||
int insertedLines = 0;
|
int insertedLines = 0;
|
||||||
BufferCoord newPos;
|
BufferCoord newPos;
|
||||||
|
@ -5449,8 +5442,8 @@ void SynEdit::doInsertText(const BufferCoord& pos, const QStringList& text, SynS
|
||||||
doLinesInserted(pos.Line+1, insertedLines);
|
doLinesInserted(pos.Line+1, insertedLines);
|
||||||
break;
|
break;
|
||||||
case SynSelectionMode::smColumn:
|
case SynSelectionMode::smColumn:
|
||||||
insertedLines = doInsertTextByColumnMode(pos,text, newPos);
|
insertedLines = doInsertTextByColumnMode(pos,text, newPos, startLine,endLine);
|
||||||
doLinesInserted(pos.Line+text.length()-1-insertedLines,insertedLines);
|
doLinesInserted(endLine-insertedLines+1,insertedLines);
|
||||||
break;
|
break;
|
||||||
case SynSelectionMode::smLine:
|
case SynSelectionMode::smLine:
|
||||||
insertedLines = doInsertTextByLineMode(pos,text, newPos);
|
insertedLines = doInsertTextByLineMode(pos,text, newPos);
|
||||||
|
@ -5557,26 +5550,23 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos)
|
int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos, int startLine, int endLine)
|
||||||
{
|
{
|
||||||
QString str;
|
QString str;
|
||||||
QString tempString;
|
QString tempString;
|
||||||
int insertCol;
|
|
||||||
int line;
|
int line;
|
||||||
int len;
|
int len;
|
||||||
BufferCoord lineBreakPos;
|
BufferCoord lineBreakPos;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
DisplayCoord insertCoord = bufferToDisplayPos(caretXY());
|
DisplayCoord insertCoord = bufferToDisplayPos(caretXY());
|
||||||
int startLine = pos.Line;
|
int insertCol = insertCoord.Column;
|
||||||
// Insert string at begin of the selection
|
|
||||||
insertCol = insertCoord.Column;
|
|
||||||
line = startLine;
|
line = startLine;
|
||||||
if (!mUndoing) {
|
if (!mUndoing) {
|
||||||
mUndoList->BeginBlock();
|
mUndoList->BeginBlock();
|
||||||
}
|
}
|
||||||
for (int i=0;i<text.length();i++){
|
int i=0;
|
||||||
|
while(line<=endLine) {
|
||||||
str = text[i];
|
str = text[i];
|
||||||
line=startLine+i;
|
|
||||||
int insertPos = 0;
|
int insertPos = 0;
|
||||||
if (line > mDocument->count()) {
|
if (line > mDocument->count()) {
|
||||||
result++;
|
result++;
|
||||||
|
@ -5589,7 +5579,7 @@ int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList&
|
||||||
mUndoList->AddChange(SynChangeReason::crLineBreak,
|
mUndoList->AddChange(SynChangeReason::crLineBreak,
|
||||||
lineBreakPos,
|
lineBreakPos,
|
||||||
lineBreakPos,
|
lineBreakPos,
|
||||||
QStringList(), SynSelectionMode::smColumn);
|
QStringList(), SynSelectionMode::smNormal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tempString = mDocument->getString(line - 1);
|
tempString = mDocument->getString(line - 1);
|
||||||
|
@ -5610,8 +5600,12 @@ int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList&
|
||||||
BufferCoord{insertPos, line},
|
BufferCoord{insertPos, line},
|
||||||
BufferCoord{insertPos+str.length(), line},
|
BufferCoord{insertPos+str.length(), line},
|
||||||
QStringList(),
|
QStringList(),
|
||||||
SynSelectionMode::smColumn);
|
SynSelectionMode::smNormal);
|
||||||
}
|
}
|
||||||
|
if (i<text.length()-1) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
line++;
|
||||||
}
|
}
|
||||||
newPos=pos;
|
newPos=pos;
|
||||||
if (!text[0].isEmpty()) {
|
if (!text[0].isEmpty()) {
|
||||||
|
@ -6231,7 +6225,7 @@ void SynEdit::mousePressEvent(QMouseEvent *event)
|
||||||
}else {
|
}else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (button == Qt::LeftButton) {
|
} else if (button == Qt::LeftButton && mActiveSelectionMode == SynSelectionMode::smNormal) {
|
||||||
if (selAvail()) {
|
if (selAvail()) {
|
||||||
//remember selection state, as it will be cleared later
|
//remember selection state, as it will be cleared later
|
||||||
bWasSel = true;
|
bWasSel = true;
|
||||||
|
@ -6442,16 +6436,16 @@ void SynEdit::dropEvent(QDropEvent *event)
|
||||||
internalSetCaretXY(coord);
|
internalSetCaretXY(coord);
|
||||||
if (event->proposedAction() == Qt::DropAction::CopyAction) {
|
if (event->proposedAction() == Qt::DropAction::CopyAction) {
|
||||||
//just copy it
|
//just copy it
|
||||||
doInsertText(coord,text,mActiveSelectionMode);
|
doInsertText(coord,text,mActiveSelectionMode,coord.Line,coord.Line+text.length()-1);
|
||||||
} else if (event->proposedAction() == Qt::DropAction::MoveAction) {
|
} else if (event->proposedAction() == Qt::DropAction::MoveAction) {
|
||||||
if (coord < mDragSelBeginSave ) {
|
if (coord < mDragSelBeginSave ) {
|
||||||
//delete old
|
//delete old
|
||||||
doDeleteText(mDragSelBeginSave,mDragSelEndSave,mActiveSelectionMode);
|
doDeleteText(mDragSelBeginSave,mDragSelEndSave,mActiveSelectionMode);
|
||||||
//paste to new position
|
//paste to new position
|
||||||
doInsertText(coord,text,mActiveSelectionMode);
|
doInsertText(coord,text,mActiveSelectionMode,coord.Line,coord.Line+text.length()-1);
|
||||||
} else {
|
} else {
|
||||||
//paste to new position
|
//paste to new position
|
||||||
doInsertText(coord,text,mActiveSelectionMode);
|
doInsertText(coord,text,mActiveSelectionMode,coord.Line,coord.Line+text.length()-1);
|
||||||
//delete old
|
//delete old
|
||||||
doDeleteText(mDragSelBeginSave,mDragSelEndSave,mActiveSelectionMode);
|
doDeleteText(mDragSelBeginSave,mDragSelEndSave,mActiveSelectionMode);
|
||||||
//set caret to right pos
|
//set caret to right pos
|
||||||
|
@ -6666,7 +6660,7 @@ void SynEdit::onUndoAdded()
|
||||||
// we have to clear the redo information, since adding undo info removes
|
// we have to clear the redo information, since adding undo info removes
|
||||||
// the necessary context to undo earlier edit actions
|
// the necessary context to undo earlier edit actions
|
||||||
if (! mUndoList->insideRedo() &&
|
if (! mUndoList->insideRedo() &&
|
||||||
mUndoList->PeekItem() && (mUndoList->PeekItem()->changeReason()!=SynChangeReason::crNothing))
|
mUndoList->PeekItem() && (mUndoList->PeekItem()->changeReason()!=SynChangeReason::crGroupBreak))
|
||||||
mRedoList->Clear();
|
mRedoList->Clear();
|
||||||
if (mUndoList->blockCount() == 0 )
|
if (mUndoList->blockCount() == 0 )
|
||||||
onChanged();
|
onChanged();
|
||||||
|
|
|
@ -560,13 +560,11 @@ private:
|
||||||
|
|
||||||
//primitive edit operations
|
//primitive edit operations
|
||||||
void doDeleteText(const BufferCoord& startPos, const BufferCoord& endPos, SynSelectionMode mode);
|
void doDeleteText(const BufferCoord& startPos, const BufferCoord& endPos, SynSelectionMode mode);
|
||||||
void doInsertText(const BufferCoord& pos, const QStringList& text, SynSelectionMode mode);
|
void doInsertText(const BufferCoord& pos, const QStringList& text, SynSelectionMode mode, int startLine, int endLine);
|
||||||
int doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
|
int doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
|
||||||
int doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
|
int doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos, int startLine, int endLine);
|
||||||
int doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
|
int doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void deleteFromTo(const BufferCoord& start, const BufferCoord& end);
|
void deleteFromTo(const BufferCoord& start, const BufferCoord& end);
|
||||||
void setSelWord();
|
void setSelWord();
|
||||||
void setWordBlock(BufferCoord Value);
|
void setWordBlock(BufferCoord Value);
|
||||||
|
|
|
@ -874,8 +874,8 @@ void SynEditUndoList::AddGroupBreak()
|
||||||
{
|
{
|
||||||
//Add the GroupBreak even if ItemCount = 0. Since items are stored in
|
//Add the GroupBreak even if ItemCount = 0. Since items are stored in
|
||||||
//reverse order in TCustomSynEdit.fRedoList, a GroupBreak could be lost.
|
//reverse order in TCustomSynEdit.fRedoList, a GroupBreak could be lost.
|
||||||
if (LastChangeReason() != SynChangeReason::crNothing) {
|
if (LastChangeReason() != SynChangeReason::crGroupBreak) {
|
||||||
AddChange(SynChangeReason::crNothing, {0,0}, {0,0}, QStringList(), SynSelectionMode::smNormal);
|
AddChange(SynChangeReason::crGroupBreak, {0,0}, {0,0}, QStringList(), SynSelectionMode::smNormal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -958,7 +958,7 @@ void SynEditUndoList::PushItem(PSynEditUndoItem Item)
|
||||||
return;
|
return;
|
||||||
mItems.append(Item);
|
mItems.append(Item);
|
||||||
ensureMaxEntries();
|
ensureMaxEntries();
|
||||||
if (Item->changeReason()!= SynChangeReason::crNothing)
|
if (Item->changeReason()!= SynChangeReason::crGroupBreak)
|
||||||
emit addedUndo();
|
emit addedUndo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,24 +165,12 @@ enum class SynChangeReason {
|
||||||
crDelete,
|
crDelete,
|
||||||
crCaret, //just restore the Caret, allowing better Undo behavior
|
crCaret, //just restore the Caret, allowing better Undo behavior
|
||||||
crSelection, //restore Selection
|
crSelection, //restore Selection
|
||||||
crNothing,
|
crGroupBreak,
|
||||||
crLeftTop,
|
crLeftTop,
|
||||||
crLineBreak,
|
crLineBreak,
|
||||||
crMoveSelectionUp,
|
crMoveSelectionUp,
|
||||||
crMoveSelectionDown
|
crMoveSelectionDown,
|
||||||
//several undo entries can be chained together via the ChangeNumber
|
crNothing
|
||||||
//see also TCustomSynEdit.[Begin|End]UndoBlock methods
|
|
||||||
// crDeleteAfterCursor,
|
|
||||||
// crLineBreak, crIndent, crUnindent,
|
|
||||||
// crSilentDelete, crSilentDeleteAfterCursor,
|
|
||||||
// crAutoCompleteBegin, crAutoCompleteEnd,
|
|
||||||
// crPasteBegin, crPasteEnd, //for pasting, since it might do a lot of operations
|
|
||||||
// crSpecial1Begin, crSpecial1End,
|
|
||||||
// crSpecial2Begin, crSpecial2End,
|
|
||||||
|
|
||||||
// crNothing,
|
|
||||||
// crDeleteAll,
|
|
||||||
|
|
||||||
};
|
};
|
||||||
class SynEditUndoItem {
|
class SynEditUndoItem {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -28,3 +28,5 @@ DELETE/BACKSPACE
|
||||||
報炎溶廡
|
報炎溶廡
|
||||||
|
|
||||||
双庁塀
|
双庁塀
|
||||||
|
|
||||||
|
4. 列模式移动光标选择时,检查是否可选
|
Loading…
Reference in New Issue