fix: ending glyph not correctly drawed after editing

This commit is contained in:
Roy Qu 2024-02-25 20:01:05 +08:00
parent 9672ebd079
commit fda9a424c4
3 changed files with 8 additions and 4 deletions

View File

@ -1756,6 +1756,8 @@ int Document::updateGlyphStartPositionList(
glyphStartPositionList[i] = right;
right += gWidth;
}
if (endGlyph<glyphStartPositionList.length())
glyphStartPositionList[endGlyph] = right;
return right-left;
}

View File

@ -369,7 +369,7 @@ void QSynEditPainter::paintToken(
bool fontInited = false;
int tokenRight = tokenWidth+tokenLeft;
//qDebug()<<"Paint token"<<lineText<<tokenWidth<<tokenLeft<<first<<last<<rcToken;
// qDebug()<<"Paint token"<<lineText<<tokenWidth<<tokenLeft<<first<<last<<rcToken;
// qDebug()<<glyphStartCharList;
// qDebug()<<glyphStartPositionList;
// qDebug()<<startGlyph<<endGlyph;
@ -389,7 +389,7 @@ void QSynEditPainter::paintToken(
int glyphLen = calcSegmentInterval(glyphStartCharList,lineText.length(),i);
QString glyph = lineText.mid(glyphStart,glyphLen);
int glyphWidth = calcSegmentInterval(glyphStartPositionList, tokenRight, i);
// qDebug()<<"painting:"<<glyph<<glyphWidth<<tokenWidth+glyphWidth<<first<<last;
// qDebug()<<"painting:"<<glyph<<glyphWidth<<tokenWidth+glyphWidth<<first<<last;
if (tokenWidth+glyphWidth>first) {
if (!startPaint ) {
nX-= (first - tokenWidth - 1) ;
@ -435,7 +435,7 @@ void QSynEditPainter::paintToken(
break;
}
i+=1;
glyphWidth += calcSegmentInterval(glyphStartPositionList, tokenLeft+tokenWidth, i);
glyphWidth += calcSegmentInterval(glyphStartPositionList, tokenRight, i);
textToPaint+=glyph2;
if (tokenWidth + glyphWidth > last )
break;

View File

@ -1908,7 +1908,7 @@ void QSynEdit::doDeleteLastChar()
Q_ASSERT(glyphIndex>0);
int oldCaretX = mCaretX;
int newCaretX = mDocument->glyphStartChar(mCaretY-1, glyphIndex-1)+1;
qDebug()<<"delete last char:"<<oldCaretX<<newCaretX<<glyphIndex<<mCaretY;
//qDebug()<<"delete last char:"<<oldCaretX<<newCaretX<<glyphIndex<<mCaretY;
QString s = tempStr.mid(newCaretX-1, oldCaretX-newCaretX);
internalSetCaretX(newCaretX);
if (s==' ' || s=='\t')
@ -6096,6 +6096,8 @@ void QSynEdit::paintEvent(QPaintEvent *event)
cacheRC.setWidth(rcClip.width()*dpr);
cacheRC.setHeight(rcClip.height()*dpr);
painter.drawImage(rcClip,*mContentImage,cacheRC);
//glyph positions may be updated while painting, so we need to recalc here.
rcCaret = calculateCaretRect();
}
paintCaret(painter, rcCaret);
}