- fix: crash when editing txt file and input symbol at the beginning of a line

This commit is contained in:
Roy Qu 2022-04-03 11:54:07 +08:00
parent 65b328396c
commit 7d86c6e5b1
2 changed files with 28 additions and 25 deletions

View File

@ -5,6 +5,7 @@ Red Panda C++ Version 1.0.3
- enhancement: shift+ctrl+down/up to move currenlt selection lines up / down - enhancement: shift+ctrl+down/up to move currenlt selection lines up / down
- fix: can't compile under linux - fix: can't compile under linux
- enhancement: support Devcie Pixel Ratio ( for linux ) - enhancement: support Devcie Pixel Ratio ( for linux )
- fix: crash when editing txt file and input symbol at the beginning of a line
Red Panda C++ Version 1.0.2 Red Panda C++ Version 1.0.2
- enhancement: press tab in column mode won't exit column mode - enhancement: press tab in column mode won't exit column mode

View File

@ -2001,31 +2001,33 @@ bool Editor::handleSymbolCompletion(QChar key)
return false; return false;
//todo: better methods to detect current caret type //todo: better methods to detect current caret type
if (caretX() <= 1) { if (highlighter()) {
if (caretY()>1) { if (caretX() <= 1) {
if (highlighter()->isLastLineCommentNotFinished(lines()->ranges(caretY() - 2).state)) if (caretY()>1) {
return false; if (highlighter()->isLastLineCommentNotFinished(lines()->ranges(caretY() - 2).state))
if (highlighter()->isLastLineStringNotFinished(lines()->ranges(caretY() - 2).state) return false;
&& (key!='\"') && (key!='\'')) if (highlighter()->isLastLineStringNotFinished(lines()->ranges(caretY() - 2).state)
return false; && (key!='\"') && (key!='\''))
} return false;
} else { }
BufferCoord HighlightPos = BufferCoord{caretX()-1, caretY()}; } else {
// Check if that line is highlighted as comment BufferCoord HighlightPos = BufferCoord{caretX()-1, caretY()};
PSynHighlighterAttribute Attr; // Check if that line is highlighted as comment
QString Token; PSynHighlighterAttribute Attr;
bool tokenFinished; QString Token;
SynHighlighterTokenType tokenType; bool tokenFinished;
if (getHighlighterAttriAtRowCol(HighlightPos, Token, tokenFinished, tokenType,Attr)) { SynHighlighterTokenType tokenType;
if ((tokenType == SynHighlighterTokenType::Comment) && (!tokenFinished)) if (getHighlighterAttriAtRowCol(HighlightPos, Token, tokenFinished, tokenType,Attr)) {
return false; if ((tokenType == SynHighlighterTokenType::Comment) && (!tokenFinished))
if ((tokenType == SynHighlighterTokenType::String) && (!tokenFinished) return false;
&& (key!='\'') && (key!='\"') && (key!='(') && (key!=')')) if ((tokenType == SynHighlighterTokenType::String) && (!tokenFinished)
return false; && (key!='\'') && (key!='\"') && (key!='(') && (key!=')'))
if (( key=='<' || key =='>') && (mParser && !mParser->isIncludeLine(lineText()))) return false;
return false; if (( key=='<' || key =='>') && (mParser && !mParser->isIncludeLine(lineText())))
if ((key == '\'') && (Attr->name() == "SYNS_AttrNumber")) return false;
return false; if ((key == '\'') && (Attr->name() == "SYNS_AttrNumber"))
return false;
}
} }
} }