work save

This commit is contained in:
Roy Qu 2022-12-16 01:44:20 +08:00
parent 16db14e761
commit ff336ad5c3
4 changed files with 36 additions and 44 deletions

View File

@ -4705,7 +4705,7 @@ void Editor::applySettings()
QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo
| QSynedit::eoSelectWordByDblClick;
options.setFlag(QSynedit::eoShowSpecialChars);
options.setFlag(QSynedit::eoShowSpecialChars, false);
//options
options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent());

View File

@ -21,7 +21,7 @@ const QSet<QChar> WordBreakChars{'.', ',', ';', ':',
'"', '\'', '!', '?', '[', ']', '(', ')', '{', '}', '^', '-', '=', '+',
'-', '*', '/', '\\', '|'};
const QChar TabGlyph(0x2192);
const QChar SpaceGlyph(0x2027);
const QChar SpaceGlyph('.');
const QChar LineBreakGlyph(0x2193);
const QChar SoftBreakGlyph(0x2193);
}

View File

@ -338,7 +338,7 @@ int SynEditTextPainter::columnToXValue(int col)
void SynEditTextPainter::paintToken(const QString &token, int tokenCols, int columnsBefore,
int first, int last, bool /*isSelection*/, const QFont& font,
const QFont& fontForNonAscii)
const QFont& fontForNonAscii, bool showGlyphs)
{
bool startPaint;
int nX;
@ -392,7 +392,7 @@ void SynEditTextPainter::paintToken(const QString &token, int tokenCols, int col
if (token[i].unicode()<=0xFF) {
QChar ch;
int padding=0;
if (edit->mOptions.testFlag(eoShowSpecialChars)) {
if (showGlyphs) {
switch(token[i].unicode()) {
case '\t':
ch=TabGlyph;
@ -530,24 +530,25 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL)
if (bU1) {
setDrawingColors(false);
rcToken.setRight(columnToXValue(nLineSelStart));
paintToken(TokenAccu.s,TokenAccu.Columns,TokenAccu.ColumnsBefore,nC1,nLineSelStart,false,font,nonAsciiFont);
paintToken(
TokenAccu.s,TokenAccu.Columns,TokenAccu.ColumnsBefore,nC1,nLineSelStart,false,font,nonAsciiFont, TokenAccu.showSpecialGlyphs);
}
// selected part of the token
setDrawingColors(true);
nC1Sel = std::max(nLineSelStart, nC1);
nC2Sel = std::min(nLineSelEnd, nC2);
rcToken.setRight(columnToXValue(nC2Sel));
paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1Sel, nC2Sel,true,font,nonAsciiFont);
paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1Sel, nC2Sel,true,font,nonAsciiFont, TokenAccu.showSpecialGlyphs);
// second unselected part of the token
if (bU2) {
setDrawingColors(false);
rcToken.setRight(columnToXValue(nC2));
paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore,nLineSelEnd, nC2,false,font,nonAsciiFont);
paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore,nLineSelEnd, nC2,false,font,nonAsciiFont, TokenAccu.showSpecialGlyphs);
}
} else {
setDrawingColors(bSel);
rcToken.setRight(columnToXValue(nC2));
paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1, nC2,bSel,font,nonAsciiFont);
paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1, nC2,bSel,font,nonAsciiFont, TokenAccu.showSpecialGlyphs);
}
}
@ -589,22 +590,6 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL)
}
}
bool SynEditTextPainter::tokenIsSpaces(bool &bSpacesTest, const QString& token, bool& bIsSpaces)
{
if (!bSpacesTest) {
bSpacesTest = true;
for (QChar ch:token) {
//todo: should include tabs?
if (ch!= ' ') {
bIsSpaces = false;
return bIsSpaces;
}
}
bIsSpaces = true;
}
return bIsSpaces;
}
// Store the token chars with the attributes in the TokenAccu
// record. This will paint any chars already stored if there is
// a (visible) change in the attributes.
@ -614,12 +599,15 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo
bool bCanAppend;
QColor foreground, background;
FontStyles style;
bool bSpacesTest,bIsSpaces;
bool isSpaces=false;
bool showGlyphs=false;
if (p_Attri) {
foreground = p_Attri->foreground();
background = p_Attri->background();
style = p_Attri->styles();
isSpaces = p_Attri->tokenType() == TokenType::Space;
showGlyphs = isSpaces && edit->mOptions.testFlag(eoShowSpecialChars);
} else {
foreground = colFG;
background = colBG;
@ -641,17 +629,18 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo
// Do we have to paint the old chars first, or can we just append?
bCanAppend = false;
bSpacesTest = false;
if (TokenAccu.Columns > 0) {
// font style must be the same or token is only spaces
if (TokenAccu.Style == style || ( (style & FontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline)
&& tokenIsSpaces(bSpacesTest,Token,bIsSpaces)) ) {
if (
// background color must be the same and
((TokenAccu.BG == background) &&
// foreground color must be the same or token is only spaces
((TokenAccu.FG == foreground) || (tokenIsSpaces(bSpacesTest,Token,bIsSpaces) && !edit->mOptions.testFlag(eoShowSpecialChars))))) {
bCanAppend = true;
if (TokenAccu.Columns > 0 ) {
if (showGlyphs == TokenAccu.showSpecialGlyphs) {
// font style must be the same or token is only spaces
if (TokenAccu.Style == style || ( (style & FontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline)
&& isSpaces)) {
if (
// background color must be the same and
(TokenAccu.BG == background) &&
// foreground color must be the same or token is only spaces
((TokenAccu.FG == foreground) || isSpaces)) {
bCanAppend = true;
}
}
}
// If we can't append it, then we have to paint the old token chars first.
@ -669,6 +658,7 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo
TokenAccu.FG = foreground;
TokenAccu.BG = background;
TokenAccu.Style = style;
TokenAccu.showSpecialGlyphs = showGlyphs;
}
}
@ -926,17 +916,17 @@ void SynEditTextPainter::paintLines()
setDrawingColors(true);
rcToken.setLeft(std::max(rcLine.left(), columnToXValue(nLineSelStart)));
rcToken.setRight(std::min(rcLine.right(), columnToXValue(nLineSelEnd)));
paintToken(sToken, nTokenColumnLen, 0, nLineSelStart, nLineSelEnd,false,edit->font(),edit->fontForNonAscii());
paintToken(sToken, nTokenColumnLen, 0, nLineSelStart, nLineSelEnd,false,edit->font(),edit->fontForNonAscii(),false);
setDrawingColors(false);
rcToken.setLeft(std::max(rcLine.left(), columnToXValue(FirstCol)));
rcToken.setRight(std::min(rcLine.right(), columnToXValue(nLineSelStart)));
paintToken(sToken, nTokenColumnLen, 0, FirstCol, nLineSelStart,false,edit->font(),edit->fontForNonAscii());
paintToken(sToken, nTokenColumnLen, 0, FirstCol, nLineSelStart,false,edit->font(),edit->fontForNonAscii(),false);
rcToken.setLeft(std::max(rcLine.left(), columnToXValue(nLineSelEnd)));
rcToken.setRight(std::min(rcLine.right(), columnToXValue(LastCol)));
paintToken(sToken, nTokenColumnLen, 0, nLineSelEnd, LastCol,true,edit->font(),edit->fontForNonAscii());
paintToken(sToken, nTokenColumnLen, 0, nLineSelEnd, LastCol,true,edit->font(),edit->fontForNonAscii(),false);
} else {
setDrawingColors(bLineSelected);
paintToken(sToken, nTokenColumnLen, 0, FirstCol, LastCol,bLineSelected,edit->font(),edit->fontForNonAscii());
paintToken(sToken, nTokenColumnLen, 0, FirstCol, LastCol,bLineSelected,edit->font(),edit->fontForNonAscii(),false);
}
//Paint editingAreaBorders
if (bCurrentLine && edit->mInputPreeditString.length()>0) {
@ -1047,8 +1037,10 @@ void SynEditTextPainter::paintLines()
}
}
// Draw LineBreak glyph.
if (edit->mOptions.testFlag(eoShowSpecialChars) && (!bLineSelected) &&
(!bSpecialLine) && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) {
if (edit->mOptions.testFlag(eoShowSpecialChars)
// && (!bLineSelected)
// && (!bSpecialLine)
&& (edit->mDocument->lineColumns(vLine-1) < vLastChar)) {
addHighlightToken(LineBreakGlyph,
edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol),
edit->charColumns(LineBreakGlyph),vLine, edit->mSyntaxer->whitespaceAttribute());

View File

@ -35,6 +35,7 @@ class SynEditTextPainter
QColor FG;
QColor BG;
FontStyles Style;
bool showSpecialGlyphs;
};
public:
@ -50,10 +51,9 @@ private:
int columnToXValue(int col);
void paintToken(const QString& token, int tokenLen, int columnsBefore,
int first, int last, bool isSelection, const QFont& font,
const QFont& fontForNonAscii);
const QFont& fontForNonAscii, bool showGlyphs);
void paintEditAreas(const EditingAreaList& areaList);
void paintHighlightToken(bool bFillToEOL);
bool tokenIsSpaces(bool& bSpacesTest, const QString& token, bool& bIsSpaces);
void addHighlightToken(const QString& token, int columnsBefore, int tokenColumns,
int cLine, PTokenAttribute p_Attri);