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)
{
QMutexLocker locker(&mMutex);
QList<int> glyphStartCharList;
if (mLines[line]->lineText() == newStr)
glyphStartCharList = mLines[line]->glyphStartCharList();
else
glyphStartCharList = calcGlyphStartCharList(newStr);
int glyphIdx = charToGlyphIndex(mLines[line]->lineText(), glyphStartCharList, charPos);
if (glyphIdx<glyphStartCharList.length())
return glyphStartCharList[glyphIdx];
else
return newStr.length();
if (mLines[line]->lineText() == newStr) {
return charToGlyphStartPosition(line,charPos);
} else {
QList<int> glyphStartCharList = calcGlyphStartCharList(newStr);
int glyphIdx = charToGlyphIndex(newStr, glyphStartCharList, charPos);
int width;
QList<int> glyphStartPositionList = calcGlyphPositionList(newStr, width);
if (glyphIdx<glyphStartCharList.length())
return glyphStartPositionList[glyphIdx];
else
return width;
}
}
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())
return 0;
if(mWidth<0)
if( mWidth <0)
updateWidth();
int start = glyphStartPosition(i);
int end;

View File

@ -1885,7 +1885,7 @@ void QSynEdit::doDeleteLastChar()
bool shouldAddGroupBreak=false;
QString tempStr = lineText();
int tempStrLen = tempStr.length();
BufferCoord Caret = caretXY();
BufferCoord caretBackup = caretXY();
QStringList helper;
if (mCaretX > tempStrLen + 1) {
// only move caret one column
@ -1903,41 +1903,22 @@ void QSynEdit::doDeleteLastChar()
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 {
// delete char
int glyphIndex = mDocument->charToGlyphIndex(mCaretY-1,mCaretX-1);
Q_ASSERT(glyphIndex>0);
int oldCaretX = mCaretX;
int newCaretX = mDocument->glyphStartChar(mCaretY-1, glyphIndex-1)+1;
QString s = tempStr.mid(newCaretX-1, oldCaretX-newCaretX);
internalSetCaretX(newCaretX);
if (s==' ' || s=='\t')
shouldAddGroupBreak=true;
helper.append(s);
tempStr.remove(newCaretX-1, oldCaretX-newCaretX);
properSetLine(mCaretY - 1, tempStr);
}
// delete char
int glyphIndex = mDocument->charToGlyphIndex(mCaretY-1,mCaretX-1);
Q_ASSERT(glyphIndex>0);
int oldCaretX = mCaretX;
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);
internalSetCaretX(newCaretX);
if (s==' ' || s=='\t')
shouldAddGroupBreak=true;
helper.append(s);
tempStr.remove(newCaretX-1, oldCaretX-newCaretX);
properSetLine(mCaretY - 1, tempStr);
}
if ((Caret.ch != mCaretX) || (Caret.line != mCaretY)) {
mUndoList->addChange(ChangeReason::Delete, caretXY(), Caret, helper,
if ((caretBackup.ch != mCaretX) || (caretBackup.line != mCaretY)) {
mUndoList->addChange(ChangeReason::Delete, caretXY(), caretBackup, helper,
mActiveSelectionMode);
if (shouldAddGroupBreak)
mUndoList->addGroupBreak();

View File

@ -75,31 +75,32 @@ Q_DECLARE_FLAGS(StateFlags,StateFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(StateFlags)
enum EditorOption {
eoAltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format
eoAutoIndent = 0x00000002, //Will auto calculate the indent when input
eoLigatureSupport = 0x00000004, //Support ligaures in fonts like fira code
eoDragDropEditing = 0x00000008, //Allows you to select a block of text and drag it within the document to another location
eoDropFiles = 0x00000010, //Allows the editor accept OLE file drops
eoEnhanceHomeKey = 0x00000020, //enhances home key positioning, similar to visual studio
eoEnhanceEndKey = 0x00000040, //enhances End key positioning, similar to JDeveloper
eoGroupUndo = 0x00000080, //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately
eoHalfPageScroll = 0x00000100, //When scrolling with page-up and page-down commands, only scroll a half page at a time
eoHideShowScrollbars = 0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead)
eoKeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor
eoRightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location
eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less
eoScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker
eoScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line
eoAltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format
eoAutoIndent = 0x00000002, //Will auto calculate the indent when input
eoLigatureSupport = 0x00000004, //Support ligaures in fonts like fira code
eoDragDropEditing = 0x00000008, //Allows you to select a block of text and drag it within the document to another location
eoDropFiles = 0x00000010, //Allows the editor accept OLE file drops
eoEnhanceHomeKey = 0x00000020, //enhances home key positioning, similar to visual studio
eoEnhanceEndKey = 0x00000040, //enhances End key positioning, similar to JDeveloper
eoGroupUndo = 0x00000080, //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately
eoHalfPageScroll = 0x00000100, //When scrolling with page-up and page-down commands, only scroll a half page at a time
eoHideShowScrollbars = 0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead)
eoKeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor
eoRightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location
eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less
eoScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker
eoScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line
// eoShowSpecialChars = 0x00008000, //Shows the special Characters
// eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event
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
eoShowRainbowColor = 0x00080000,
eoSelectWordByDblClick= 0x00100000,
eoShowLeadingSpaces = 0x00200000,
eoShowTrailingSpaces = 0x00400000,
eoShowInnerSpaces= 0x00800000,
eoShowLineBreaks = 0x01000000,
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
eoShowRainbowColor = 0x00080000,
eoSelectWordByDblClick = 0x00100000,
eoShowLeadingSpaces = 0x00200000,
eoShowTrailingSpaces = 0x00400000,
eoShowInnerSpaces = 0x00800000,
eoShowLineBreaks = 0x01000000,
eoForceMonospace = 0x02000000,
};
Q_DECLARE_FLAGS(EditorOptions, EditorOption)