fix: onGutterPaint not correctly called

fix: expand glyph char list is not work properly.
This commit is contained in:
Roy Qu 2024-02-26 08:59:01 +08:00
parent 6b1e4ff979
commit fd3a280708
6 changed files with 18 additions and 37 deletions

View File

@ -1149,8 +1149,8 @@ void Editor::onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList)
if (lst) {
for (const PSyntaxIssue& issue: *lst) {
QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>();
p->beginX = issue->col;
p->endX = issue->endCol;
p->beginX = issue->startChar;
p->endX = issue->endChar;
if (issue->issueType == CompileIssueType::Error) {
p->color = mSyntaxErrorColor;
} else {
@ -1640,8 +1640,6 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT
}
pError->startChar = start;
pError->endChar = start + token.length();
pError->col = pError->startChar;
pError->endCol = pError->endChar;
pError->hint = hint;
pError->token = token;
pError->issueType = errorType;

View File

@ -110,8 +110,6 @@ public:
};
struct SyntaxIssue {
int col;
int endCol;
int startChar;
int endChar;
CompileIssueType issueType;

View File

@ -1481,7 +1481,7 @@ void Settings::Editor::doLoad()
//Editor font
mFontName = stringValue("font_name",DEFAULT_MONO_FONT);
QString defaultCjkFontName = CJK_MONO_FONT_SC;
QString defaultCjkFontName = DEFAULT_MONO_FONT;
QString defaultLocaleName = QLocale::system().name();
if (defaultLocaleName == "zh_TW")
defaultCjkFontName = CJK_MONO_FONT_TC;
@ -1489,10 +1489,12 @@ void Settings::Editor::doLoad()
defaultCjkFontName = CJK_MONO_FONT_J;
else if (defaultLocaleName == "ko_KR")
defaultCjkFontName = CJK_MONO_FONT_K;
else if (defaultLocaleName == "zh_CN")
defaultCjkFontName = CJK_MONO_FONT_SC;
mNonAsciiFontName = stringValue("non_ascii_font_name",defaultCjkFontName);
mFontSize = intValue("font_size",12);
mFontOnlyMonospaced = boolValue("font_only_monospaced",true);
mLineSpacing = doubleValue("line_spacing",1.0);
mLineSpacing = doubleValue("line_spacing",1.1);
mEnableLigaturesSupport = boolValue("enable_ligatures_support", true);
mShowLeadingSpaces = boolValue("show_leading_spaces", false);

View File

@ -1218,16 +1218,7 @@ DocumentLine::DocumentLine(DocumentLine::UpdateWidthFunc updateWidthFunc):
int DocumentLine::glyphLength(int i) const
{
if (i<0 || i>=mGlyphStartCharList.length())
return 0;
int start = glyphStartChar(i);
int end;
if (i+1<mGlyphStartCharList.length()) {
end = mGlyphStartCharList[i+1];
} else {
end = mLineText.length();
}
return end-start;
return calcSegmentInterval(mGlyphStartCharList, mLineText.length(), i);
}
QString DocumentLine::glyph(int i) const
@ -1250,18 +1241,9 @@ int DocumentLine::glyphStartPosition(int i)
int DocumentLine::glyphWidth(int i)
{
if (i<0 || i>=mGlyphStartPositionList.length())
return 0;
if( mWidth <0)
if (mWidth <0)
updateWidth();
int start = glyphStartPosition(i);
int end;
if (i+1<mGlyphStartPositionList.length()) {
end = mGlyphStartPositionList[i+1];
} else {
end = mWidth;
}
return end-start;
return calcSegmentInterval(mGlyphStartPositionList, mWidth, i);
}
int DocumentLine::width()
@ -1764,7 +1746,7 @@ int Document::updateGlyphStartPositionList(
int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fontMetrics, const QFontMetrics &nonAsciiFontMetrics) const
{
int glyphWidth;
if (glyph.length()==1 && glyph[0].unicode()<0xFF) {
if (glyph.length()==1 && glyph[0].unicode()<128) {
QChar ch = glyph[0];
if (ch == '\t') {
glyphWidth = tabWidth() - left % tabWidth();
@ -1779,7 +1761,7 @@ int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fon
return glyphWidth;
}
void expandGlyphStartCharList(const QString &strAdded, int oldStrLen, QList<int> glyphStartCharList)
void expandGlyphStartCharList(const QString &strAdded, int oldStrLen, QList<int> &glyphStartCharList)
{
QList<int> addedList = calcGlyphStartCharList(strAdded);
for (int i=0;i<addedList.length();i++) {

View File

@ -34,7 +34,7 @@ int searchForSegmentIdx(const QList<int> &segList, int minVal, int maxVal, int v
int calcSegmentInterval(const QList<int> &segList, int maxVal, int idx);
int segmentIntervalStart(const QList<int> &segList, int minVal, int maxVal, int idx);
QList<int> calcGlyphStartCharList(const QString &text);
void expandGlyphStartCharList(const QString& strAdded, int oldStrLen, QList<int> glyphStartCharList);
void expandGlyphStartCharList(const QString& strAdded, int oldStrLen, QList<int> &glyphStartCharList);
class Document;

View File

@ -190,7 +190,7 @@ void QSynEditPainter::paintGutter(const QRect& clip)
// Form a rectangle for the square the user can click on
rcFold.setLeft(mEdit->mGutterWidth - mEdit->mGutter.rightOffset());
rcFold.setTop(( - mEdit->mTopLine) * mEdit->mTextHeight);
rcFold.setTop((row - mEdit->mTopLine) * mEdit->mTextHeight);
rcFold.setRight(rcFold.left() + mEdit->mGutter.rightOffset() - 4);
rcFold.setBottom(rcFold.top() + mEdit->mTextHeight);
@ -250,7 +250,7 @@ void QSynEditPainter::paintGutter(const QRect& clip)
int line = mEdit->rowToLine(row);
if ((line > mEdit->mDocument->count()) && (mEdit->mDocument->count() != 0))
break;
mEdit->onGutterPaint(*mPainter,line, 0, ( - mEdit->mTopLine) * mEdit->mTextHeight);
mEdit->onGutterPaint(*mPainter,line, 0, (row - mEdit->mTopLine) * mEdit->mTextHeight);
}
}
@ -1198,7 +1198,8 @@ void QSynEditPainter::paintLines()
}
if (!addOnStr.isEmpty()) {
expandGlyphStartCharList(addOnStr, sLine.length(), glyphStartCharList);
for (int i=0;i<glyphStartCharList.length()-glyphStartPositionsList.length();i++) {
int len=glyphStartCharList.length()-glyphStartPositionsList.length();
for (int i=0;i<len;i++) {
glyphStartPositionsList.append(tokenLeft);
}
attr = mEdit->mSyntaxer->symbolAttribute();
@ -1232,9 +1233,9 @@ void QSynEditPainter::paintLines()
}
}
int glyphIdx;
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->beginX);
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->beginX-1);
area->beginX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->endX);
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->endX-1);
area->endX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
}
//input method