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

View File

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

View File

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

View File

@ -1218,16 +1218,7 @@ DocumentLine::DocumentLine(DocumentLine::UpdateWidthFunc updateWidthFunc):
int DocumentLine::glyphLength(int i) const int DocumentLine::glyphLength(int i) const
{ {
if (i<0 || i>=mGlyphStartCharList.length()) return calcSegmentInterval(mGlyphStartCharList, mLineText.length(), i);
return 0;
int start = glyphStartChar(i);
int end;
if (i+1<mGlyphStartCharList.length()) {
end = mGlyphStartCharList[i+1];
} else {
end = mLineText.length();
}
return end-start;
} }
QString DocumentLine::glyph(int i) const QString DocumentLine::glyph(int i) const
@ -1250,18 +1241,9 @@ int DocumentLine::glyphStartPosition(int i)
int DocumentLine::glyphWidth(int i) int DocumentLine::glyphWidth(int i)
{ {
if (i<0 || i>=mGlyphStartPositionList.length()) if (mWidth <0)
return 0;
if( mWidth <0)
updateWidth(); updateWidth();
int start = glyphStartPosition(i); return calcSegmentInterval(mGlyphStartPositionList, mWidth, i);
int end;
if (i+1<mGlyphStartPositionList.length()) {
end = mGlyphStartPositionList[i+1];
} else {
end = mWidth;
}
return end-start;
} }
int DocumentLine::width() 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 Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fontMetrics, const QFontMetrics &nonAsciiFontMetrics) const
{ {
int glyphWidth; int glyphWidth;
if (glyph.length()==1 && glyph[0].unicode()<0xFF) { if (glyph.length()==1 && glyph[0].unicode()<128) {
QChar ch = glyph[0]; QChar ch = glyph[0];
if (ch == '\t') { if (ch == '\t') {
glyphWidth = tabWidth() - left % tabWidth(); glyphWidth = tabWidth() - left % tabWidth();
@ -1779,7 +1761,7 @@ int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fon
return glyphWidth; 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); QList<int> addedList = calcGlyphStartCharList(strAdded);
for (int i=0;i<addedList.length();i++) { 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 calcSegmentInterval(const QList<int> &segList, int maxVal, int idx);
int segmentIntervalStart(const QList<int> &segList, int minVal, int maxVal, int idx); int segmentIntervalStart(const QList<int> &segList, int minVal, int maxVal, int idx);
QList<int> calcGlyphStartCharList(const QString &text); 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; 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 // Form a rectangle for the square the user can click on
rcFold.setLeft(mEdit->mGutterWidth - mEdit->mGutter.rightOffset()); 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.setRight(rcFold.left() + mEdit->mGutter.rightOffset() - 4);
rcFold.setBottom(rcFold.top() + mEdit->mTextHeight); rcFold.setBottom(rcFold.top() + mEdit->mTextHeight);
@ -250,7 +250,7 @@ void QSynEditPainter::paintGutter(const QRect& clip)
int line = mEdit->rowToLine(row); int line = mEdit->rowToLine(row);
if ((line > mEdit->mDocument->count()) && (mEdit->mDocument->count() != 0)) if ((line > mEdit->mDocument->count()) && (mEdit->mDocument->count() != 0))
break; 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()) { if (!addOnStr.isEmpty()) {
expandGlyphStartCharList(addOnStr, sLine.length(), glyphStartCharList); 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); glyphStartPositionsList.append(tokenLeft);
} }
attr = mEdit->mSyntaxer->symbolAttribute(); attr = mEdit->mSyntaxer->symbolAttribute();
@ -1232,9 +1233,9 @@ void QSynEditPainter::paintLines()
} }
} }
int glyphIdx; 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); 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); area->endX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
} }
//input method //input method