Work save:

This commit is contained in:
Roy Qu 2024-02-24 21:14:19 +08:00
parent 322c4bba4f
commit 3b28894d51
3 changed files with 53 additions and 69 deletions

View File

@ -1016,16 +1016,18 @@ int Document::xposToGlyphStartChar(int line, int xpos)
int Document::charToGlyphStartPosition(int line, const QString newStr, int charPos) int Document::charToGlyphStartPosition(int line, const QString newStr, int charPos)
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
QList<int> glyphStartCharList; if (mLines[line]->lineText() == newStr) {
if (mLines[line]->lineText() == newStr) return charToGlyphStartPosition(line,charPos);
glyphStartCharList = mLines[line]->glyphStartCharList(); } else {
else QList<int> glyphStartCharList = calcGlyphStartCharList(newStr);
glyphStartCharList = calcGlyphStartCharList(newStr); int glyphIdx = charToGlyphIndex(newStr, glyphStartCharList, charPos);
int glyphIdx = charToGlyphIndex(mLines[line]->lineText(), glyphStartCharList, charPos); int width;
QList<int> glyphStartPositionList = calcGlyphPositionList(newStr, width);
if (glyphIdx<glyphStartCharList.length()) if (glyphIdx<glyphStartCharList.length())
return glyphStartCharList[glyphIdx]; return glyphStartPositionList[glyphIdx];
else else
return newStr.length(); return width;
}
} }
int Document::xposToGlyphStartChar(int line, const QString newStr, int xpos) int Document::xposToGlyphStartChar(int line, const QString newStr, int xpos)
@ -1217,7 +1219,7 @@ int DocumentLine::glyphWidth(int i)
{ {
if (i<0 || i>=mGlyphPositionList.length()) if (i<0 || i>=mGlyphPositionList.length())
return 0; return 0;
if(mWidth<0) if( mWidth <0)
updateWidth(); updateWidth();
int start = glyphStartPosition(i); int start = glyphStartPosition(i);
int end; int end;

View File

@ -1885,7 +1885,7 @@ void QSynEdit::doDeleteLastChar()
bool shouldAddGroupBreak=false; bool shouldAddGroupBreak=false;
QString tempStr = lineText(); QString tempStr = lineText();
int tempStrLen = tempStr.length(); int tempStrLen = tempStr.length();
BufferCoord Caret = caretXY(); BufferCoord caretBackup = caretXY();
QStringList helper; QStringList helper;
if (mCaretX > tempStrLen + 1) { if (mCaretX > tempStrLen + 1) {
// only move caret one column // only move caret one column
@ -1902,31 +1902,13 @@ void QSynEdit::doDeleteLastChar()
helper.append(""); helper.append("");
shouldAddGroupBreak=true; shouldAddGroupBreak=true;
} }
} else {
// delete text before the caret
// int startChar = charTo
// int caretXPos = charToGlyph(mCaretY,mCaretX);
int SpaceCount1 = leftSpaces(tempStr);
int SpaceCount2 = 0;
int newCaretX;
if (SpaceCount1 == mCaretX - 1) {
//how much till the next tab column
int BackCounter = (mCaretX - 1) % tabSize();
if (BackCounter == 0)
BackCounter = tabSize();
SpaceCount2 = std::max(0,SpaceCount1 - tabSize());
newCaretX = xposToGlyphStartChar(mCaretY,SpaceCount2+1);
helper.append(tempStr.mid(newCaretX - 1, mCaretX - newCaretX));
tempStr.remove(newCaretX-1,mCaretX - newCaretX);
properSetLine(mCaretY - 1, tempStr);
internalSetCaretX(newCaretX);
} else { } else {
// delete char // delete char
int glyphIndex = mDocument->charToGlyphIndex(mCaretY-1,mCaretX-1); int glyphIndex = mDocument->charToGlyphIndex(mCaretY-1,mCaretX-1);
Q_ASSERT(glyphIndex>0); Q_ASSERT(glyphIndex>0);
int oldCaretX = mCaretX; int oldCaretX = mCaretX;
int newCaretX = mDocument->glyphStartChar(mCaretY-1, glyphIndex-1)+1; int newCaretX = mDocument->glyphStartChar(mCaretY-1, glyphIndex-1)+1;
qDebug()<<"delete last char:"<<oldCaretX<<newCaretX<<glyphIndex<<mCaretY;
QString s = tempStr.mid(newCaretX-1, oldCaretX-newCaretX); QString s = tempStr.mid(newCaretX-1, oldCaretX-newCaretX);
internalSetCaretX(newCaretX); internalSetCaretX(newCaretX);
if (s==' ' || s=='\t') if (s==' ' || s=='\t')
@ -1935,9 +1917,8 @@ void QSynEdit::doDeleteLastChar()
tempStr.remove(newCaretX-1, oldCaretX-newCaretX); tempStr.remove(newCaretX-1, oldCaretX-newCaretX);
properSetLine(mCaretY - 1, tempStr); properSetLine(mCaretY - 1, tempStr);
} }
} if ((caretBackup.ch != mCaretX) || (caretBackup.line != mCaretY)) {
if ((Caret.ch != mCaretX) || (Caret.line != mCaretY)) { mUndoList->addChange(ChangeReason::Delete, caretXY(), caretBackup, helper,
mUndoList->addChange(ChangeReason::Delete, caretXY(), Caret, helper,
mActiveSelectionMode); mActiveSelectionMode);
if (shouldAddGroupBreak) if (shouldAddGroupBreak)
mUndoList->addGroupBreak(); mUndoList->addGroupBreak();

View File

@ -95,11 +95,12 @@ enum EditorOption {
eoTabIndent = 0x00020000, //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected eoTabIndent = 0x00020000, //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected
eoTabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters eoTabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters
eoShowRainbowColor = 0x00080000, eoShowRainbowColor = 0x00080000,
eoSelectWordByDblClick= 0x00100000, eoSelectWordByDblClick = 0x00100000,
eoShowLeadingSpaces = 0x00200000, eoShowLeadingSpaces = 0x00200000,
eoShowTrailingSpaces = 0x00400000, eoShowTrailingSpaces = 0x00400000,
eoShowInnerSpaces= 0x00800000, eoShowInnerSpaces = 0x00800000,
eoShowLineBreaks = 0x01000000, eoShowLineBreaks = 0x01000000,
eoForceMonospace = 0x02000000,
}; };
Q_DECLARE_FLAGS(EditorOptions, EditorOption) Q_DECLARE_FLAGS(EditorOptions, EditorOption)