Done:
- Caret move - Delete current char / last char Fix: - Selection not correctly drawn
This commit is contained in:
parent
06b8850970
commit
cb2b119e46
|
@ -893,6 +893,14 @@ int Document::stringWidth(const QString &str, int left) const
|
||||||
return right - left;
|
return right - left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Document::glyphCount(int line)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mMutex);
|
||||||
|
if (line<0 || line>=count())
|
||||||
|
return 0;
|
||||||
|
return mLines[line]->glyphsCount();
|
||||||
|
}
|
||||||
|
|
||||||
int Document::glyphStartChar(int line, int glyphIdx)
|
int Document::glyphStartChar(int line, int glyphIdx)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mMutex);
|
QMutexLocker locker(&mMutex);
|
||||||
|
@ -1234,7 +1242,7 @@ void DocumentLine::updateWidth()
|
||||||
{
|
{
|
||||||
Q_ASSERT(mUpdateWidthFunc!=nullptr);
|
Q_ASSERT(mUpdateWidthFunc!=nullptr);
|
||||||
mGlyphPositionList = mUpdateWidthFunc(mLineText, mGlyphStartCharList, mWidth);
|
mGlyphPositionList = mUpdateWidthFunc(mLineText, mGlyphStartCharList, mWidth);
|
||||||
qDebug()<<mLineText<<mWidth<<mGlyphPositionList;
|
// qDebug()<<"Update Width"<<mLineText<<mWidth<<mGlyphPositionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<int> &DocumentLine::glyphPositionList()
|
const QList<int> &DocumentLine::glyphPositionList()
|
||||||
|
|
|
@ -439,6 +439,7 @@ public:
|
||||||
*/
|
*/
|
||||||
int stringWidth(const QString &str, int left) const;
|
int stringWidth(const QString &str, int left) const;
|
||||||
|
|
||||||
|
int glyphCount(int line);
|
||||||
/**
|
/**
|
||||||
* @brief get start index of the chars representing the specified glyph in the specified line.
|
* @brief get start index of the chars representing the specified glyph in the specified line.
|
||||||
*
|
*
|
||||||
|
|
|
@ -382,7 +382,7 @@ void QSynEditPainter::paintToken(
|
||||||
QString glyph = token.mid(glyphStart,glyphEnd-glyphStart);
|
QString glyph = token.mid(glyphStart,glyphEnd-glyphStart);
|
||||||
int glyphWidth = mEdit->document()->glyphWidth(glyph, tokenLeft+tokenWidth);
|
int glyphWidth = mEdit->document()->glyphWidth(glyph, tokenLeft+tokenWidth);
|
||||||
// qDebug()<<glyph<<charCols;
|
// qDebug()<<glyph<<charCols;
|
||||||
if (tokenWidth+glyphWidth>=first) {
|
if (tokenWidth+glyphWidth>first) {
|
||||||
if (!startPaint ) {
|
if (!startPaint ) {
|
||||||
nX-= (first - tokenWidth - 1) ;
|
nX-= (first - tokenWidth - 1) ;
|
||||||
startPaint = true;
|
startPaint = true;
|
||||||
|
|
|
@ -726,12 +726,18 @@ DisplayCoord QSynEdit::pixelsToNearestGlyphPos(int aX, int aY) const
|
||||||
line = 1;
|
line = 1;
|
||||||
if (line>mDocument->count())
|
if (line>mDocument->count())
|
||||||
line = mDocument->count();
|
line = mDocument->count();
|
||||||
if (xpos<0)
|
if (xpos<0) {
|
||||||
xpos=0;
|
xpos=0;
|
||||||
if (xpos>mDocument->lineWidth(line-1))
|
} else if (xpos>mDocument->lineWidth(line-1)) {
|
||||||
xpos=mDocument->lineWidth(line-1)+1;
|
xpos=mDocument->lineWidth(line-1)+1;
|
||||||
|
} else {
|
||||||
int glyphIndex = mDocument->xposToGlyphIndex(line-1, xpos);
|
int glyphIndex = mDocument->xposToGlyphIndex(line-1, xpos);
|
||||||
|
int nextGlyphPos = mDocument->glyphStartPostion(line-1, glyphIndex+1);
|
||||||
|
if (nextGlyphPos - xpos < mCharWidth / 2)
|
||||||
|
xpos = nextGlyphPos;
|
||||||
|
else
|
||||||
xpos = mDocument->glyphStartPostion(line-1, glyphIndex);
|
xpos = mDocument->glyphStartPostion(line-1, glyphIndex);
|
||||||
|
}
|
||||||
return DisplayCoord{xpos, row};
|
return DisplayCoord{xpos, row};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1873,11 +1879,11 @@ void QSynEdit::doDeleteLastChar()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool shouldAddGroupBreak=false;
|
bool shouldAddGroupBreak=false;
|
||||||
QString Temp = lineText();
|
QString tempStr = lineText();
|
||||||
int Len = Temp.length();
|
int tempStrLen = tempStr.length();
|
||||||
BufferCoord Caret = caretXY();
|
BufferCoord Caret = caretXY();
|
||||||
QStringList helper;
|
QStringList helper;
|
||||||
if (mCaretX > Len + 1) {
|
if (mCaretX > tempStrLen + 1) {
|
||||||
// only move caret one column
|
// only move caret one column
|
||||||
return;
|
return;
|
||||||
} else if (mCaretX == 1) {
|
} else if (mCaretX == 1) {
|
||||||
|
@ -1887,7 +1893,7 @@ void QSynEdit::doDeleteLastChar()
|
||||||
internalSetCaretX(mDocument->getLine(mCaretY - 1).length() + 1);
|
internalSetCaretX(mDocument->getLine(mCaretY - 1).length() + 1);
|
||||||
mDocument->deleteAt(mCaretY);
|
mDocument->deleteAt(mCaretY);
|
||||||
doLinesDeleted(mCaretY+1, 1);
|
doLinesDeleted(mCaretY+1, 1);
|
||||||
setLineText(lineText() + Temp);
|
setLineText(lineText() + tempStr);
|
||||||
helper.append("");
|
helper.append("");
|
||||||
helper.append("");
|
helper.append("");
|
||||||
shouldAddGroupBreak=true;
|
shouldAddGroupBreak=true;
|
||||||
|
@ -1896,7 +1902,7 @@ void QSynEdit::doDeleteLastChar()
|
||||||
// delete text before the caret
|
// delete text before the caret
|
||||||
// int startChar = charTo
|
// int startChar = charTo
|
||||||
// int caretXPos = charToGlyph(mCaretY,mCaretX);
|
// int caretXPos = charToGlyph(mCaretY,mCaretX);
|
||||||
int SpaceCount1 = leftSpaces(Temp);
|
int SpaceCount1 = leftSpaces(tempStr);
|
||||||
int SpaceCount2 = 0;
|
int SpaceCount2 = 0;
|
||||||
int newCaretX;
|
int newCaretX;
|
||||||
|
|
||||||
|
@ -1907,19 +1913,23 @@ void QSynEdit::doDeleteLastChar()
|
||||||
BackCounter = tabSize();
|
BackCounter = tabSize();
|
||||||
SpaceCount2 = std::max(0,SpaceCount1 - tabSize());
|
SpaceCount2 = std::max(0,SpaceCount1 - tabSize());
|
||||||
newCaretX = xposToGlyphStartChar(mCaretY,SpaceCount2+1);
|
newCaretX = xposToGlyphStartChar(mCaretY,SpaceCount2+1);
|
||||||
helper.append(Temp.mid(newCaretX - 1, mCaretX - newCaretX));
|
helper.append(tempStr.mid(newCaretX - 1, mCaretX - newCaretX));
|
||||||
Temp.remove(newCaretX-1,mCaretX - newCaretX);
|
tempStr.remove(newCaretX-1,mCaretX - newCaretX);
|
||||||
properSetLine(mCaretY - 1, Temp);
|
properSetLine(mCaretY - 1, tempStr);
|
||||||
internalSetCaretX(newCaretX);
|
internalSetCaretX(newCaretX);
|
||||||
} else {
|
} else {
|
||||||
// delete char
|
// delete char
|
||||||
internalSetCaretX(mCaretX - 1);
|
int glyphIndex = mDocument->charToGlyphIndex(mCaretY-1,mCaretX-1);
|
||||||
QChar ch=Temp[mCaretX-1];
|
Q_ASSERT(glyphIndex>0);
|
||||||
if (ch==' ' || ch=='\t')
|
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;
|
shouldAddGroupBreak=true;
|
||||||
helper.append(QString(ch));
|
helper.append(s);
|
||||||
Temp.remove(mCaretX-1,1);
|
tempStr.remove(newCaretX-1, oldCaretX-newCaretX);
|
||||||
properSetLine(mCaretY - 1, Temp);
|
properSetLine(mCaretY - 1, tempStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((Caret.ch != mCaretX) || (Caret.line != mCaretY)) {
|
if ((Caret.ch != mCaretX) || (Caret.line != mCaretY)) {
|
||||||
|
@ -1933,7 +1943,7 @@ void QSynEdit::doDeleteLastChar()
|
||||||
void QSynEdit::doDeleteCurrentChar()
|
void QSynEdit::doDeleteCurrentChar()
|
||||||
{
|
{
|
||||||
QStringList helper;
|
QStringList helper;
|
||||||
BufferCoord Caret;
|
BufferCoord newCaret;
|
||||||
if (mReadOnly) {
|
if (mReadOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1959,27 +1969,29 @@ void QSynEdit::doDeleteCurrentChar()
|
||||||
// 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 tempStr = lineText();
|
||||||
int Len = Temp.length();
|
int tempStrLen = tempStr.length();
|
||||||
if (mCaretX>Len+1) {
|
if (mCaretX>tempStrLen+1) {
|
||||||
return;
|
return;
|
||||||
} else if (mCaretX <= Len) {
|
} else if (mCaretX <= tempStrLen) {
|
||||||
QChar ch = Temp[mCaretX-1];
|
int glyphIndex = mDocument->charToGlyphIndex(mCaretY-1,mCaretX-1);
|
||||||
if (ch==' ' || ch=='\t')
|
int glyphLen = mDocument->glyphLength(mCaretY-1,glyphIndex);
|
||||||
|
QString s = tempStr.mid(mCaretX-1,glyphLen);
|
||||||
|
if (s==' ' || s=='\t')
|
||||||
shouldAddGroupBreak=true;
|
shouldAddGroupBreak=true;
|
||||||
// delete char
|
// delete char
|
||||||
helper.append(QString(ch));
|
helper.append(s);
|
||||||
Caret.ch = mCaretX + 1;
|
newCaret.ch = mCaretX + glyphLen;
|
||||||
Caret.line = mCaretY;
|
newCaret.line = mCaretY;
|
||||||
Temp.remove(mCaretX-1, 1);
|
tempStr.remove(mCaretX-1, glyphLen);
|
||||||
properSetLine(mCaretY - 1, Temp);
|
properSetLine(mCaretY - 1, tempStr);
|
||||||
} else {
|
} else {
|
||||||
// join line with the line after
|
// join line with the line after
|
||||||
if (mCaretY < mDocument->count()) {
|
if (mCaretY < mDocument->count()) {
|
||||||
shouldAddGroupBreak=true;
|
shouldAddGroupBreak=true;
|
||||||
properSetLine(mCaretY - 1, Temp + mDocument->getLine(mCaretY));
|
properSetLine(mCaretY - 1, tempStr + mDocument->getLine(mCaretY));
|
||||||
Caret.ch = 1;
|
newCaret.ch = 1;
|
||||||
Caret.line = mCaretY + 1;
|
newCaret.line = mCaretY + 1;
|
||||||
helper.append("");
|
helper.append("");
|
||||||
helper.append("");
|
helper.append("");
|
||||||
mDocument->deleteAt(mCaretY);
|
mDocument->deleteAt(mCaretY);
|
||||||
|
@ -1989,8 +2001,8 @@ void QSynEdit::doDeleteCurrentChar()
|
||||||
doLinesDeleted(mCaretY + 1, 1);
|
doLinesDeleted(mCaretY + 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((Caret.ch != mCaretX) || (Caret.line != mCaretY)) {
|
if ((newCaret.ch != mCaretX) || (newCaret.line != mCaretY)) {
|
||||||
mUndoList->addChange(ChangeReason::Delete, caretXY(), Caret,
|
mUndoList->addChange(ChangeReason::Delete, caretXY(), newCaret,
|
||||||
helper, mActiveSelectionMode);
|
helper, mActiveSelectionMode);
|
||||||
if (shouldAddGroupBreak)
|
if (shouldAddGroupBreak)
|
||||||
mUndoList->addGroupBreak();
|
mUndoList->addGroupBreak();
|
||||||
|
@ -4760,8 +4772,7 @@ void QSynEdit::processCommand(EditCommand Command, QChar AChar, void *pData)
|
||||||
|
|
||||||
void QSynEdit::moveCaretHorz(int deltaX, bool isSelection)
|
void QSynEdit::moveCaretHorz(int deltaX, bool isSelection)
|
||||||
{
|
{
|
||||||
BufferCoord ptO = caretXY();
|
BufferCoord ptDst = caretXY();
|
||||||
BufferCoord ptDst = ptO;
|
|
||||||
QString s = displayLineText();
|
QString s = displayLineText();
|
||||||
int nLineLen = s.length();
|
int nLineLen = s.length();
|
||||||
if (!isSelection && selAvail() && (deltaX!=0)) {
|
if (!isSelection && selAvail() && (deltaX!=0)) {
|
||||||
|
@ -4781,7 +4792,8 @@ void QSynEdit::moveCaretHorz(int deltaX, 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 && (deltaX == -1) && (ptO.ch == 1) && (ptO.line > 1)) {
|
int glyphIndex = mDocument->charToGlyphIndex(ptDst.line-1,ptDst.ch-1);
|
||||||
|
if (bChangeY && (deltaX == -1) && (glyphIndex==0) && (ptDst.line > 1)) {
|
||||||
// end of previous line
|
// end of previous line
|
||||||
if (mActiveSelectionMode==SelectionMode::Column) {
|
if (mActiveSelectionMode==SelectionMode::Column) {
|
||||||
return;
|
return;
|
||||||
|
@ -4793,7 +4805,7 @@ void QSynEdit::moveCaretHorz(int deltaX, 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 && (deltaX == 1) && (ptO.ch > nLineLen) && (ptO.line < mDocument->count())) {
|
} else if (bChangeY && (deltaX == 1) && (glyphIndex >= mDocument->glyphCount(ptDst.line-1)) && (ptDst.line < mDocument->count())) {
|
||||||
// start of next line
|
// start of next line
|
||||||
if (mActiveSelectionMode==SelectionMode::Column) {
|
if (mActiveSelectionMode==SelectionMode::Column) {
|
||||||
return;
|
return;
|
||||||
|
@ -4807,7 +4819,9 @@ void QSynEdit::moveCaretHorz(int deltaX, bool isSelection)
|
||||||
ptDst.ch = 1;
|
ptDst.ch = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ptDst.ch = std::max(1, ptDst.ch + deltaX);
|
// qDebug()<<"Move caret horizontal"<<ptDst.line<<ptDst.ch<<glyphIndex<<deltaX;
|
||||||
|
ptDst.ch = std::max(1, mDocument->glyphStartChar(ptDst.line-1, glyphIndex + deltaX)+1);
|
||||||
|
qDebug()<<ptDst.ch;
|
||||||
// don't go past last char when ScrollPastEol option not set
|
// don't go past last char when ScrollPastEol option not set
|
||||||
if ((deltaX > 0) && bChangeY)
|
if ((deltaX > 0) && bChangeY)
|
||||||
ptDst.ch = std::min(ptDst.ch, nLineLen + 1);
|
ptDst.ch = std::min(ptDst.ch, nLineLen + 1);
|
||||||
|
|
Loading…
Reference in New Issue