Refactor: All file has a syntaxer

This commit is contained in:
Roy Qu 2024-03-04 16:01:23 +08:00
parent 518ce3f31a
commit 2a18f3f47a
19 changed files with 563 additions and 689 deletions

View File

@ -282,13 +282,11 @@ void Editor::loadFile(QString filename) {
default:
mUseCppSyntax = pSettings->editor().defaultFileCpp();
}
if (syntaxer()) {
reparse(true);
if (pSettings->editor().syntaxCheckWhenLineChanged()) {
checkSyntaxInBack();
}
reparseTodo();
reparse(true);
if (pSettings->editor().syntaxCheckWhenLineChanged()) {
checkSyntaxInBack();
}
reparseTodo();
saveAutoBackup();
}
@ -607,8 +605,6 @@ void Editor::undoSymbolCompletion(int pos)
QString token;
QSynedit::SyntaxState syntaxState;
if (!syntaxer())
return;
if (!pSettings->editor().removeSymbolPairs())
return;
if (!getTokenAttriAtRowCol(caretXY(), token, attr, syntaxState))
@ -736,82 +732,80 @@ void Editor::keyPressEvent(QKeyEvent *event)
clearUserCodeInTabStops();
} else {
QString s = lineText().mid(0,caretX()-1).trimmed();
if (syntaxer()) {
if (caretY()==1) {
syntaxer()->resetState();
} else {
syntaxer()->setState(document()->getSyntaxState(caretY()-2));
}
syntaxer()->setLine(s,caretY());
syntaxer()->nextToEol();
int state = syntaxer()->getState().state;
if (syntaxer()->isCommentNotFinished(state)) {
if (s=="/**") { //javadoc style docstring
s = lineText().mid(caretX()-1).trimmed();
if (s=="*/") {
QSynedit::BufferCoord p = caretXY();
setBlockBegin(p);
p.ch = lineText().length()+1;
setBlockEnd(p);
setSelText("");
if (caretY()==1) {
syntaxer()->resetState();
} else {
syntaxer()->setState(document()->getSyntaxState(caretY()-2));
}
syntaxer()->setLine(s,caretY());
syntaxer()->nextToEol();
int state = syntaxer()->getState().state;
if (syntaxer()->isCommentNotFinished(state)) {
if (s=="/**") { //javadoc style docstring
s = lineText().mid(caretX()-1).trimmed();
if (s=="*/") {
QSynedit::BufferCoord p = caretXY();
setBlockBegin(p);
p.ch = lineText().length()+1;
setBlockEnd(p);
setSelText("");
}
handled = true;
QStringList insertString;
insertString.append("");
PStatement function;
if (mParser)
function = mParser->findFunctionAt(mFilename,caretY()+1);
if (function) {
QStringList params;
QString funcName = function->command;
bool isVoid = (function->type == "void");
foreach (const PStatement& child, function->children) {
if (child->kind == StatementKind::skParameter)
params.append(child->command);
}
handled = true;
QStringList insertString;
insertString.append("");
PStatement function;
if (mParser)
function = mParser->findFunctionAt(mFilename,caretY()+1);
if (function) {
QStringList params;
QString funcName = function->command;
bool isVoid = (function->type == "void");
foreach (const PStatement& child, function->children) {
if (child->kind == StatementKind::skParameter)
params.append(child->command);
}
insertString.append(QString(" * @brief ")+USER_CODE_IN_INSERT_POS);
if (!params.isEmpty())
insertString.append(" * ");
foreach (const QString& param, params) {
insertString.append(QString(" * @param %1 %2")
.arg(param, USER_CODE_IN_INSERT_POS));
}
if (!isVoid) {
insertString.append(" * ");
insertString.append(QString(" * @return ")+USER_CODE_IN_INSERT_POS);
}
insertString.append(" */");
// } else if (caretY()==1) { /* file header */
// insertString.append(QString(" * @file %1<SOURCEPATH>%2")
// .arg(USER_CODE_IN_REPL_POS_BEGIN)
// .arg(USER_CODE_IN_REPL_POS_END));
// insertString.append(QString(" * @brief: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(QString(" * @version: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(QString(" * @copyright: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(QString(" * @author: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(" * @date: <DATETIME>");
// insertString.append(" * ");
// insertString.append(" **/");
} else {
insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS);
insertString.append(" */");
insertString.append(QString(" * @brief ")+USER_CODE_IN_INSERT_POS);
if (!params.isEmpty())
insertString.append(" * ");
foreach (const QString& param, params) {
insertString.append(QString(" * @param %1 %2")
.arg(param, USER_CODE_IN_INSERT_POS));
}
insertCodeSnippet(linesToText(insertString));
if (!isVoid) {
insertString.append(" * ");
insertString.append(QString(" * @return ")+USER_CODE_IN_INSERT_POS);
}
insertString.append(" */");
// } else if (caretY()==1) { /* file header */
// insertString.append(QString(" * @file %1<SOURCEPATH>%2")
// .arg(USER_CODE_IN_REPL_POS_BEGIN)
// .arg(USER_CODE_IN_REPL_POS_END));
// insertString.append(QString(" * @brief: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(QString(" * @version: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(QString(" * @copyright: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(QString(" * @author: ")+ USER_CODE_IN_INSERT_POS);
// insertString.append(" * @date: <DATETIME>");
// insertString.append(" * ");
// insertString.append(" **/");
} else {
s=trimLeft(lineText());
if (s.startsWith("* ")) {
handled = true;
int right = document()->getLine(caretY()-1).length()-caretX();
s=lineBreak()+"* ";
insertString(s,false);
QSynedit::BufferCoord p = caretXY();
p.line++;
p.ch = document()->getLine(p.line-1).length()+1;
if (right>0) {
p.ch -=right+1;
}
setCaretXY(p);
insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS);
insertString.append(" */");
}
insertCodeSnippet(linesToText(insertString));
} else {
s=trimLeft(lineText());
if (s.startsWith("* ")) {
handled = true;
int right = document()->getLine(caretY()-1).length()-caretX();
s=lineBreak()+"* ";
insertString(s,false);
QSynedit::BufferCoord p = caretXY();
p.line++;
p.ch = document()->getLine(p.line-1).length()+1;
if (right>0) {
p.ch -=right+1;
}
setCaretXY(p);
}
}
}
@ -976,7 +970,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
handled=true;
return;
}
} else if (syntaxer()) {
} else {
//show keywords
processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::KeywordsOnly);
@ -994,7 +988,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
showHeaderCompletion(false);
handled=true;
return;
} else if (syntaxer() && syntaxer()->language()==QSynedit::ProgrammingLanguage::CPP) {
} else if (syntaxer()->language()==QSynedit::ProgrammingLanguage::CPP) {
//preprocessor ?
if ((idCharPressed==0) && (ch=='#') && lineText().isEmpty()) {
processCommand(QSynedit::EditCommand::Char,ch,nullptr);
@ -1010,14 +1004,14 @@ void Editor::keyPressEvent(QKeyEvent *event)
handled=true;
return;
}
} else if (syntaxer() && syntaxer()->language()==QSynedit::ProgrammingLanguage::LUA) {
} else if (syntaxer()->language()==QSynedit::ProgrammingLanguage::LUA) {
if (ch=='.') {
processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::KeywordsOnly);
handled=true;
return;
}
} else if (syntaxer() && syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
} else if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
if ((idCharPressed==0) && (ch=='.')) {
processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::KeywordsOnly);
@ -1234,7 +1228,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (token.isEmpty())
return;
if (mParser && syntaxer()) {
if (mParser) {
// ifdef lines
if (!mParser->isLineVisible(mFilename, line)) {
foreground = syntaxer()->commentAttribute()->foreground();
@ -1303,7 +1297,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
}
}
if (syntaxer() && attr) {
if (attr) {
if (attr->tokenType() == QSynedit::TokenType::Keyword) {
//C++ type keywords
if (CppTypeKeywords.contains(token)
@ -1825,7 +1819,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
clearUserCodeInTabStops();
}
}
} else if (!selAvail() && syntaxer() && pSettings->editor().highlightMathingBraces()){
} else if (!selAvail() && pSettings->editor().highlightMathingBraces()){
invalidateLine(mHighlightCharPos1.line);
invalidateLine(mHighlightCharPos2.line);
mHighlightCharPos1 = QSynedit::BufferCoord{0,0};
@ -2006,8 +2000,7 @@ void Editor::onTooltipTimer()
}
}
if (reason == TipType::Number) {
if (!syntaxer() ||
(syntaxer()->language() != QSynedit::ProgrammingLanguage::Assembly
if ((syntaxer()->language() != QSynedit::ProgrammingLanguage::Assembly
&& syntaxer()->language() != QSynedit::ProgrammingLanguage::ATTAssembly
)
) {
@ -2043,9 +2036,8 @@ void Editor::onTooltipTimer()
}
break;
case TipType::Keyword:
if (syntaxer() &&
(syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
) {
if (!mCompletionPopup->isVisible()
&& !mHeaderCompletionPopup->isVisible()) {
@ -2114,9 +2106,8 @@ void Editor::onTooltipTimer()
}
break;
case TipType::Number:
if (syntaxer() &&
(syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
) {
bool neg=false;
qlonglong val;
@ -2141,9 +2132,8 @@ void Editor::onTooltipTimer()
break;
case TipType::Keyword:
if (pSettings->editor().enableIdentifierToolTips()) {
if (syntaxer() &&
(syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
) {
hint = QSynedit::ASMSyntaxer::Instructions.value(s.toLower(),"");
}
@ -2300,7 +2290,7 @@ QStringList Editor::getExpressionAtPosition(
const QSynedit::BufferCoord &pos)
{
QStringList result;
if (!syntaxer() || !parser())
if (!parser())
return result;
int line = pos.line-1;
int ch = pos.ch-1;
@ -2571,32 +2561,30 @@ bool Editor::handleSymbolCompletion(QChar key)
return false;
//todo: better methods to detect current caret type
if (syntaxer()) {
if (caretX() <= 1) {
if (caretY()>1) {
if (syntaxer()->isCommentNotFinished(document()->getSyntaxState(caretY() - 2).state))
return false;
if (syntaxer()->isStringNotFinished(document()->getSyntaxState(caretY() - 2).state)
&& (key!='\"') && (key!='\''))
return false;
}
} else {
QSynedit::BufferCoord HighlightPos = QSynedit::BufferCoord{caretX()-1, caretY()};
// Check if that line is highlighted as comment
QSynedit::PTokenAttribute attr;
QString token;
QSynedit::SyntaxState syntaxState;
if (getTokenAttriAtRowCol(HighlightPos, token, attr, syntaxState)) {
if (syntaxer()->isCommentNotFinished(syntaxState.state))
return false;
if (syntaxer()->isStringNotFinished(syntaxState.state)
&& (key!='\'') && (key!='\"') && (key!='(') && (key!=')'))
return false;
if (( key=='<' || key =='>') && (mParser && !mParser->isIncludeLine(lineText())))
return false;
if ((key == '\'') && (attr->name() == "SYNS_AttrNumber"))
return false;
}
if (caretX() <= 1) {
if (caretY()>1) {
if (syntaxer()->isCommentNotFinished(document()->getSyntaxState(caretY() - 2).state))
return false;
if (syntaxer()->isStringNotFinished(document()->getSyntaxState(caretY() - 2).state)
&& (key!='\"') && (key!='\''))
return false;
}
} else {
QSynedit::BufferCoord HighlightPos = QSynedit::BufferCoord{caretX()-1, caretY()};
// Check if that line is highlighted as comment
QSynedit::PTokenAttribute attr;
QString token;
QSynedit::SyntaxState syntaxState;
if (getTokenAttriAtRowCol(HighlightPos, token, attr, syntaxState)) {
if (syntaxer()->isCommentNotFinished(syntaxState.state))
return false;
if (syntaxer()->isStringNotFinished(syntaxState.state)
&& (key!='\'') && (key!='\"') && (key!='(') && (key!=')'))
return false;
if (( key=='<' || key =='>') && (mParser && !mParser->isIncludeLine(lineText())))
return false;
if ((key == '\'') && (attr->name() == "SYNS_AttrNumber"))
return false;
}
}
@ -2726,7 +2714,7 @@ bool Editor::handleParentheseSkip()
if (document()->count()==0)
return false;
if (syntaxer() && syntaxer()->supportBraceLevel()) {
if (syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1);
if (lastLineState.parenthesisLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
@ -2773,7 +2761,7 @@ bool Editor::handleBracketSkip()
if (document()->count()==0)
return false;
if (syntaxer() && syntaxer()->supportBraceLevel()) {
if (syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1);
if (lastLineState.bracketLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
@ -2887,7 +2875,7 @@ bool Editor::handleBraceSkip()
if (document()->count()==0)
return false;
if (syntaxer() && syntaxer()->supportBraceLevel()) {
if (syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1);
if (lastLineState.braceLevel==0) {
bool oldInsertMode = insertMode();
@ -2989,7 +2977,6 @@ bool Editor::handleDoubleQuoteCompletion()
return true;
}
if ((ch == 0)
|| !syntaxer()
|| ( syntaxer()->isWordBreakChar(ch)
|| syntaxer()->isSpaceChar(ch))) {
// insert ""
@ -3090,7 +3077,7 @@ void Editor::initParser()
resetCppParser(mParser);
mParser->setEnabled(
pSettings->codeCompletion().enabled() &&
(syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP));
(syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP));
}
} else {
mParser = nullptr;
@ -3112,8 +3099,6 @@ ParserLanguage Editor::calcParserLanguage()
Editor::QuoteStatus Editor::getQuoteStatus()
{
QuoteStatus Result = QuoteStatus::NotQuote;
if (!syntaxer())
return Result;
if ((caretY()>1) && syntaxer()->isStringNotFinished(document()->getSyntaxState(caretY() - 2).state))
Result = QuoteStatus::DoubleQuote;
@ -3238,8 +3223,6 @@ void Editor::reparse(bool resetParser)
return;
if (!pSettings->codeCompletion().enabled())
return;
if (!syntaxer())
return;
if (syntaxer()->language() != QSynedit::ProgrammingLanguage::CPP
&& syntaxer()->language() != QSynedit::ProgrammingLanguage::GLSL)
return;
@ -3274,8 +3257,6 @@ void Editor::reparseTodo()
return;
if (!mParentPageControl)
return;
if (!syntaxer())
return;
if (pSettings->editor().parseTodos())
pMainWindow->todoParser()->parseFile(mFilename, inProject());
}
@ -3487,14 +3468,9 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
if (!pSettings->codeCompletion().enabled())
return;
if (type==CodeCompletionType::KeywordsOnly) {
if (!syntaxer())
return;
} else {
if (!mParser || !mParser->enabled())
return;
if (!syntaxer())
return;
}
if (mCompletionPopup->isVisible()) // already in search, don't do it again
@ -3522,7 +3498,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
(attr->tokenType() == QSynedit::TokenType::String) &&
(attr->tokenType() != QSynedit::TokenType::Character)) {
return;
} else if (type==CodeCompletionType::KeywordsOnly && syntaxer() ) {
} else if (type==CodeCompletionType::KeywordsOnly ) {
if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly)
word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpATTASMKeywords);
else
@ -3592,53 +3568,53 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
mCompletionPopup->show();
// Scan the current function body
QSet<QString> keywords;
if (syntaxer()) {
if (syntaxer()->language() != QSynedit::ProgrammingLanguage::CPP ) {
if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
if (word.startsWith("."))
keywords = QSynedit::ASMSyntaxer::ATTDirectives;
else if (word.startsWith("%"))
keywords = QSynedit::ASMSyntaxer::ATTRegisters;
else {
keywords = QSynedit::ASMSyntaxer::InstructionNames;
}
} else {
int pos = word.lastIndexOf(".");
if (pos>=0) {
QString scopeWord=word.left(pos);
word = word.mid(pos+1);
QMap<QString, QSet<QString> > scopedKeywords = syntaxer()->scopedKeywords();
keywords = scopedKeywords.value(scopeWord, QSet<QString>());
} else
keywords = syntaxer()->keywords();
if (syntaxer()->language() != QSynedit::ProgrammingLanguage::CPP ) {
if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
if (word.startsWith("."))
keywords = QSynedit::ASMSyntaxer::ATTDirectives;
else if (word.startsWith("%"))
keywords = QSynedit::ASMSyntaxer::ATTRegisters;
else {
keywords = QSynedit::ASMSyntaxer::InstructionNames;
}
} else {
switch(calcParserLanguage()) {
case ParserLanguage::CPlusPlus:
foreach (const QString& keyword, CppKeywords.keys()) {
keywords.insert(keyword);
}
break;
case ParserLanguage::C:
keywords = CKeywords;
break;
#ifdef ENABLE_SDCC
case ParserLanguage::SDCC:
keywords = CKeywords;
foreach (const QString& keyword, SDCCKeywords.keys()) {
keywords.insert(keyword);
}
break;
#endif
int pos = word.lastIndexOf(".");
if (pos>=0) {
QString scopeWord=word.left(pos);
word = word.mid(pos+1);
QMap<QString, QSet<QString> > scopedKeywords = syntaxer()->scopedKeywords();
keywords = scopedKeywords.value(scopeWord, QSet<QString>());
} else
keywords = syntaxer()->keywords();
}
} else {
switch(calcParserLanguage()) {
case ParserLanguage::CPlusPlus:
foreach (const QString& keyword, CppKeywords.keys()) {
keywords.insert(keyword);
}
if (pSettings->editor().enableCustomCTypeKeywords()) {
foreach (const QString& keyword, pSettings->editor().customCTypeKeywords()) {
keywords.insert(keyword);
}
break;
case ParserLanguage::C:
keywords = CKeywords;
break;
#ifdef ENABLE_SDCC
case ParserLanguage::SDCC:
keywords = CKeywords;
foreach (const QString& keyword, SDCCKeywords.keys()) {
keywords.insert(keyword);
}
break;
#endif
}
if (pSettings->editor().enableCustomCTypeKeywords()) {
foreach (const QString& keyword, pSettings->editor().customCTypeKeywords()) {
keywords.insert(keyword);
}
}
}
if (word.isEmpty()) {
//word=getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpCompletion);
QString memberOperator;
@ -3788,7 +3764,7 @@ bool Editor::testInFunc(const QSynedit::BufferCoord& pos)
{
int y=pos.line-1;
int x=pos.ch;
if (!syntaxer() || syntaxer()->language()!=QSynedit::ProgrammingLanguage::CPP)
if (syntaxer()->language()!=QSynedit::ProgrammingLanguage::CPP)
return false;
if (y==0)
syntaxer()->resetState();
@ -3869,7 +3845,7 @@ void Editor::completionInsert(bool appendFunc)
// delete the part of the word that's already been typed ...
QSynedit::BufferCoord p = wordEnd();
QSynedit::BufferCoord pStart = wordStart();
if (syntaxer() && syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
if (statement->command.startsWith(".")
|| statement->command.startsWith("%"))
pStart.ch--;
@ -3978,7 +3954,7 @@ bool Editor::onCompletionKeyPressed(QKeyEvent *event)
return false;
QString oldPhrase = mCompletionPopup->memberPhrase();
WordPurpose purpose = WordPurpose::wpCompletion;
if (syntaxer() && syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
if (syntaxer()->language()==QSynedit::ProgrammingLanguage::ATTAssembly) {
purpose = WordPurpose::wpATTASMKeywords;
} else if (oldPhrase.startsWith('#')) {
purpose = WordPurpose::wpDirective;
@ -4118,7 +4094,7 @@ bool Editor::onCompletionInputMethod(QInputMethodEvent *event)
Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
{
// Only allow in the text area...
if (pointToCharLine(point, pos) && syntaxer()) {
if (pointToCharLine(point, pos)) {
//qDebug()<<gutterWidth()<<charWidth()<<point.y()<<point.x()<<pos.line<<pos.ch;
if (!pMainWindow->debugger()->executing()
&& getSyntaxIssueAtPosition(pos)) {
@ -4264,8 +4240,6 @@ void Editor::updateFunctionTip(bool showTip)
pMainWindow->functionTip()->hide();
return;
}
if (!syntaxer())
return;
if (!mParser || !mParser->enabled())
return;
@ -4682,7 +4656,7 @@ void Editor::setProject(Project *pProject)
return;
mProject = pProject;
if (mProject) {
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP) {
if (syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP) {
mParser = mProject->cppParser();
if (isVisible()) {
if (mParser && mParser->parsing()) {
@ -5188,8 +5162,6 @@ void Editor::checkSyntaxInBack()
return;
if (readOnly())
return;
if (!syntaxer())
return;
pMainWindow->checkSyntaxInBack(this);
}
@ -5348,7 +5320,7 @@ void Editor::applySettings()
options.setFlag(QSynedit::eoHalfPageScroll,pSettings->editor().halfPageScroll());
options.setFlag(QSynedit::eoShowRainbowColor,
pSettings->editor().rainbowParenthesis()
&& syntaxer() && syntaxer()->supportBraceLevel());
&& syntaxer()->supportBraceLevel());
options.setFlag(QSynedit::eoForceMonospace,
pSettings->editor().forceFixedFontWidth());
options.setFlag(QSynedit::eoLigatureSupport,
@ -5414,7 +5386,7 @@ void Editor::applySettings()
setRightEdge(0);
}
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP) {
if (syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP) {
QSet<QString> set;
if (pSettings->editor().enableCustomCTypeKeywords()) {
foreach(const QString& s, pSettings->editor().customCTypeKeywords())
@ -5457,7 +5429,7 @@ void Editor::applyColorScheme(const QString& schemeName)
QSynedit::EditorOptions options = getOptions();
options.setFlag(QSynedit::EditorOption::eoShowRainbowColor,
pSettings->editor().rainbowParenthesis()
&& syntaxer() && syntaxer()->supportBraceLevel());
&& syntaxer()->supportBraceLevel());
setOptions(options);
syntaxerManager.applyColorScheme(syntaxer(),schemeName);
if (pSettings->editor().rainbowParenthesis()) {

View File

@ -1755,8 +1755,7 @@ void MainWindow::updateCompilerSet(const Editor *e)
if (mProject) {
if ( !e || e->inProject()) {
index = mProject->options().compilerSet;
} else if (e->syntaxer()
&& e->syntaxer()->language()==QSynedit::ProgrammingLanguage::Makefile
} else if (e->syntaxer()->language()==QSynedit::ProgrammingLanguage::Makefile
&& mProject->directory() == extractFileDir(e->filename())) {
index = mProject->options().compilerSet;
}

View File

@ -17,15 +17,14 @@
#include "syntaxermanager.h"
#include <QFileInfo>
#include <QObject>
#include "qsynedit/constants.h"
#include "qsynedit/syntaxer/cpp.h"
#include "qsynedit/syntaxer/asm.h"
#include "qsynedit/syntaxer/glsl.h"
#include "qsynedit/syntaxer/lua.h"
#include "qsynedit/syntaxer/makefile.h"
#include "qsynedit/syntaxer/textfile.h"
#include "qsynedit/formatter/cppformatter.h"
#include "qsynedit/constants.h"
#include "colorscheme.h"
SyntaxerManager syntaxerManager;
@ -57,7 +56,7 @@ QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(QSynedit::ProgrammingLanguage l
return syntaxer;
}
default:
return QSynedit::PSyntaxer();
return std::make_shared<QSynedit::TextSyntaxer>();
}
}
@ -108,7 +107,7 @@ QSynedit::ProgrammingLanguage SyntaxerManager::getLanguage(const QString &filena
} else if (suffix.isEmpty()) {
return QSynedit::ProgrammingLanguage::CPP;
}
return QSynedit::ProgrammingLanguage::Unknown;
return QSynedit::ProgrammingLanguage::Textfile;
}
QSynedit::PSyntaxer SyntaxerManager::copy(QSynedit::PSyntaxer syntaxer) const

View File

@ -51,6 +51,7 @@ SOURCES += qsynedit/codefolding.cpp \
qsynedit/syntaxer/lua.cpp \
qsynedit/types.cpp \
qsynedit/syntaxer/makefile.cpp \
qsynedit/syntaxer/textfile.cpp \
qsynedit/syntaxer/syntaxer.cpp
HEADERS += \
@ -77,6 +78,7 @@ HEADERS += \
qsynedit/syntaxer/glsl.h \
qsynedit/syntaxer/lua.h \
qsynedit/syntaxer/makefile.h \
qsynedit/syntaxer/textfile.h \
qsynedit/syntaxer/syntaxer.h
INCLUDEPATH += ../redpanda_qt_utils

View File

@ -50,6 +50,8 @@ extern const QChar SoftBreakGlyph;
#define SYNS_AttrSymbol "Symbol"
#define SYNS_AttrVariable "Variable"
#define SYNS_AttrSpace "Space"
#define SYNS_AttrText "Text"
// names of exporter output formats
#define SYNS_ExporterFormatHTML "HTML"

View File

@ -477,7 +477,7 @@ void Document::putLine(int index, const QString &s, bool notify) {
&& mLines[index]->width() > mLines[mIndexOfLongestLine]->width())
mIndexOfLongestLine = index;
if (notify)
emit putted(index,1);
emit putted(index);
endUpdate();
}
}

View File

@ -53,7 +53,7 @@ void Exporter::exportAll(const PDocument& doc)
void Exporter::exportRange(const PDocument& doc, BufferCoord start, BufferCoord stop)
{
// abort if not all necessary conditions are met
if (!doc || !mSyntaxer || (doc->count() == 0))
if (!doc || (doc->count() == 0))
return;
stop.line = std::max(1, std::min(stop.line, doc->count()));
stop.ch = std::max(1, std::min(stop.ch, doc->getLine(stop.line - 1).length() + 1));

View File

@ -18,8 +18,6 @@ namespace QSynedit {
QSynEdit *editor)
{
Q_ASSERT(editor!=nullptr);
if (!editor->syntaxer())
return 0;
line = std::min(line, editor->document()->count()+1);
if (line<=1)
return 0;

View File

@ -159,7 +159,7 @@ void QSynEditPainter::paintGutter(const QRect& clip)
}
// Draw the folding lines and squares
if (mEdit->mUseCodeFolding) {
if (mEdit->useCodeFolding()) {
for (int row = mLastRow; row>= mFirstRow; row--) {
int line = mEdit->rowToLine(row);
if ((line > mEdit->mDocument->count()) && (mEdit->mDocument->count() != 0))
@ -780,20 +780,18 @@ void QSynEditPainter::paintFoldAttributes()
X = tabSteps * mEdit->mDocument->spaceWidth() + mEdit->textOffset() - 1;
tabSteps+=mEdit->tabSize();
indentLevel++ ;
if (mEdit->mSyntaxer) {
if (mEdit->mCodeFolding.indentGuides) {
PTokenAttribute attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
paintColor = attr->foreground();
}
if (mEdit->mCodeFolding.fillIndents) {
PTokenAttribute attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
gradientStart=attr->foreground();
attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel+1,attr);
gradientStart=attr->foreground();
}
if (mEdit->mCodeFolding.indentGuides) {
PTokenAttribute attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
paintColor = attr->foreground();
}
if (mEdit->mCodeFolding.fillIndents) {
PTokenAttribute attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
gradientStart=attr->foreground();
attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel+1,attr);
gradientStart=attr->foreground();
}
if (mEdit->mCodeFolding.fillIndents) {
int X1;
@ -821,7 +819,7 @@ void QSynEditPainter::paintFoldAttributes()
mPainter->setPen(oldPen);
}
if (!mEdit->mUseCodeFolding)
if (!mEdit->useCodeFolding())
return;
// Paint collapsed lines using changed pen
@ -972,250 +970,184 @@ void QSynEditPainter::paintLines()
int lineWidth;
QList<int> glyphStartCharList = mEdit->mDocument->getGlyphStartCharList(vLine-1,sLine);
QList<int> glyphStartPositionsList = mEdit->mDocument->getGlyphStartPositionList(vLine-1,sLine, lineWidth);
if (!mEdit->mSyntaxer || !mEdit->mSyntaxer->enabled()) {
sToken = sLine;
tokenWidth = lineWidth;
if (mEdit->mOptions.testFlag(eoShowLineBreaks) && (!mIsLineSelected) && (!mIsSpecialLine) && (tokenWidth <= mLeft)) {
expandGlyphStartCharList(LineBreakGlyph, sLine.length(), glyphStartCharList);
int width = mEdit->document()->glyphWidth(LineBreakGlyph,0);
glyphStartPositionsList.append(tokenWidth);
sLine+=LineBreakGlyph;
tokenWidth += width;
}
if (mIsComplexLine) {
setDrawingColors(true);
mRcToken.setLeft(std::max(mRcLine.left(), fixXValue(mLineSelStart)));
mRcToken.setRight(std::min(mRcLine.right(), fixXValue(mLineSelEnd)));
paintToken(
sLine,
glyphStartCharList,
glyphStartPositionsList,
0,
glyphStartCharList.length(),
tokenWidth, 0, mLineSelStart, mLineSelEnd,
mEdit->font(),false);
setDrawingColors(false);
mRcToken.setLeft(std::max(mRcLine.left(), fixXValue(mLeft)));
mRcToken.setRight(std::min(mRcLine.right(), fixXValue(mLineSelStart)));
paintToken(
sLine,
glyphStartCharList,
glyphStartPositionsList,
0,
glyphStartCharList.length(),
tokenWidth, 0, mLeft, mLineSelStart,
mEdit->font(), false);
mRcToken.setLeft(std::max(mRcLine.left(), fixXValue(mLineSelEnd)));
mRcToken.setRight(std::min(mRcLine.right(), fixXValue(mRight)));
paintToken(
sLine,
glyphStartCharList,
glyphStartPositionsList,
0,
glyphStartCharList.length(),
tokenWidth, 0, mLineSelEnd, mRight,
mEdit->font(), false);
} else {
setDrawingColors(mIsLineSelected);
paintToken(
sLine,
glyphStartCharList,
glyphStartPositionsList,
0,
glyphStartCharList.length(),
tokenWidth, 0, mLeft, mRight,
mEdit->font(),false);
}
//Paint editingAreaBorders
if (mIsCurrentLine && mEdit->mInputPreeditString.length()>0) {
PEditingArea area = std::make_shared<EditingArea>();
area->beginX = mEdit->charToGlyphLeft(vLine, sLine, mEdit->mCaretX);
area->endX = mEdit->charToGlyphLeft(vLine, sLine,mEdit->mCaretX + mEdit->mInputPreeditString.length());
area->type = EditingAreaType::eatUnderLine;
area->color = colFG;
areaList.append(area);
paintEditAreas(areaList);
}
{
// Initialize highlighter with line text and range info. It is
// necessary because we probably did not scan to the end of the last
// line - the internal highlighter range might be wrong.
if (vLine == 1) {
mEdit->mSyntaxer->resetState();
} else {
// Initialize highlighter with line text and range info. It is
// necessary because we probably did not scan to the end of the last
// line - the internal highlighter range might be wrong.
if (vLine == 1) {
mEdit->mSyntaxer->resetState();
} else {
mEdit->mSyntaxer->setState(
mEdit->mDocument->getSyntaxState(vLine-2));
mEdit->mSyntaxer->setState(
mEdit->mDocument->getSyntaxState(vLine-2));
}
mEdit->mSyntaxer->setLine(sLine, vLine - 1);
// Try to concatenate as many tokens as possible to minimize the count
// of ExtTextOut calls necessary. This depends on the selection state
// or the line having special colors. For spaces the foreground color
// is ignored as well.
mTokenAccu.width = 0;
tokenLeft = 0;
// Test first whether anything of this token is visible.
while (!mEdit->mSyntaxer->eol()) {
sToken = mEdit->mSyntaxer->getToken();
if (sToken.isEmpty()) {
continue;
// mEdit->mSyntaxer->next();
// if (mEdit->mSyntaxer->eol())
// break;
// sToken = mEdit->mSyntaxer->getToken();
// // Maybe should also test whether GetTokenPos changed...
// if (sToken.isEmpty()) {
// //qDebug()<<QSynEdit::tr("The highlighter seems to be in an infinite loop");
// throw BaseError(QSynEdit::tr("The syntaxer seems to be in an infinite loop"));
// }
}
mEdit->mSyntaxer->setLine(sLine, vLine - 1);
// Try to concatenate as many tokens as possible to minimize the count
// of ExtTextOut calls necessary. This depends on the selection state
// or the line having special colors. For spaces the foreground color
// is ignored as well.
mTokenAccu.width = 0;
tokenLeft = 0;
// Test first whether anything of this token is visible.
while (!mEdit->mSyntaxer->eol()) {
sToken = mEdit->mSyntaxer->getToken();
if (sToken.isEmpty()) {
continue;
// mEdit->mSyntaxer->next();
// if (mEdit->mSyntaxer->eol())
// break;
// sToken = mEdit->mSyntaxer->getToken();
// // Maybe should also test whether GetTokenPos changed...
// if (sToken.isEmpty()) {
// //qDebug()<<QSynEdit::tr("The highlighter seems to be in an infinite loop");
// throw BaseError(QSynEdit::tr("The syntaxer seems to be in an infinite loop"));
// }
}
int tokenStartChar = mEdit->mSyntaxer->getTokenPos();
int tokenEndChar = tokenStartChar + sToken.length();
int tokenStartChar = mEdit->mSyntaxer->getTokenPos();
int tokenEndChar = tokenStartChar + sToken.length();
// It's at least partially visible. Get the token attributes now.
attr = mEdit->mSyntaxer->getTokenAttribute();
// It's at least partially visible. Get the token attributes now.
attr = mEdit->mSyntaxer->getTokenAttribute();
//rainbow parenthesis
if (sToken == "["
|| sToken == "("
|| sToken == "{"
) {
SyntaxState rangeState = mEdit->mSyntaxer->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel
,attr);
} else if (sToken == "]"
|| sToken == ")"
|| sToken == "}"
){
SyntaxState rangeState = mEdit->mSyntaxer->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel+1,
attr);
}
//input method
if (mIsCurrentLine && mEdit->mInputPreeditString.length()>0) {
int startPos = mEdit->mSyntaxer->getTokenPos()+1;
int endPos = mEdit->mSyntaxer->getTokenPos() + sToken.length();
//qDebug()<<startPos<<":"<<endPos<<" - "+sToken+" - "<<edit->mCaretX<<":"<<edit->mCaretX+edit->mInputPreeditString.length();
if (!(endPos < mEdit->mCaretX
|| startPos >= mEdit->mCaretX+mEdit->mInputPreeditString.length())) {
if (!preeditAttr) {
preeditAttr = attr;
} else {
attr = preeditAttr;
}
}
}
bool showGlyph=false;
if (attr && attr->tokenType() == TokenType::Space) {
int pos = mEdit->mSyntaxer->getTokenPos();
if (pos==0) {
showGlyph = mEdit->mOptions.testFlag(eoShowLeadingSpaces);
} else if (pos+sToken.length()==sLine.length()) {
showGlyph = mEdit->mOptions.testFlag(eoShowTrailingSpaces);
} else {
showGlyph = mEdit->mOptions.testFlag(eoShowInnerSpaces);
}
}
addHighlightToken(
sLine,
sToken,
tokenLeft,
vLine, attr,showGlyph,
glyphStartCharList,
tokenStartChar,
tokenEndChar,
glyphStartPositionsList,
tokenWidth);
tokenLeft+=tokenWidth;
// Let the highlighter scan the next token.
mEdit->mSyntaxer->next();
}
mEdit->mDocument->setLineWidth(vLine-1, sLine, tokenLeft, glyphStartPositionsList);
if (tokenLeft<mRight) {
QString addOnStr;
// Paint folding
foldRange = mEdit->foldStartAtLine(vLine);
if ((foldRange) && foldRange->collapsed) {
addOnStr = mEdit->syntaxer()->foldString(sLine);
attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(mEdit->mSyntaxer->getState().braceLevel,attr);
} else {
// Draw LineBreak glyph.
if (mEdit->mOptions.testFlag(eoShowLineBreaks)
&& (mEdit->mDocument->lineWidth(vLine-1) < mRight)) {
addOnStr = LineBreakGlyph;
attr = mEdit->mSyntaxer->whitespaceAttribute();
}
}
if (!addOnStr.isEmpty()) {
expandGlyphStartCharList(addOnStr, sLine.length(), glyphStartCharList);
int len=glyphStartCharList.length()-glyphStartPositionsList.length();
for (int i=0;i<len;i++) {
glyphStartPositionsList.append(tokenLeft);
}
int oldLen = sLine.length();
sLine += addOnStr;
addHighlightToken(
sLine,
addOnStr,
tokenLeft,
vLine, attr, false,
glyphStartCharList,
oldLen,
sLine.length(),
glyphStartPositionsList,
tokenWidth);
tokenLeft += tokenWidth;
}
}
// Draw anything that's left in the TokenAccu record. Fill to the end
// of the invalid area with the correct colors.
paintHighlightToken(sLine, glyphStartCharList, glyphStartPositionsList, true);
//Paint editingAreaBorders
foreach (const PEditingArea& area, areaList) {
if (mIsCurrentLine && mEdit->mInputPreeditString.length()>0) {
if (area->beginX > mEdit->mCaretX) {
area->beginX += mEdit->mInputPreeditString.length();
}
if (area->endX > mEdit->mCaretX) {
area->endX += mEdit->mInputPreeditString.length();
}
}
int glyphIdx;
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->beginX-1);
area->beginX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->endX-1);
area->endX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
//rainbow parenthesis
if (sToken == "["
|| sToken == "("
|| sToken == "{"
) {
SyntaxState rangeState = mEdit->mSyntaxer->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel
,attr);
} else if (sToken == "]"
|| sToken == ")"
|| sToken == "}"
){
SyntaxState rangeState = mEdit->mSyntaxer->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel+1,
attr);
}
//input method
if (mIsCurrentLine && mEdit->mInputPreeditString.length()>0) {
PEditingArea area = std::make_shared<EditingArea>();
int glyphIdx;
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), mEdit->mCaretX-1);
area->beginX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), mEdit->mCaretX+mEdit->mInputPreeditString.length()-1);
area->endX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
area->type = EditingAreaType::eatUnderLine;
if (preeditAttr) {
area->color = preeditAttr->foreground();
} else {
area->color = colFG;
int startPos = mEdit->mSyntaxer->getTokenPos()+1;
int endPos = mEdit->mSyntaxer->getTokenPos() + sToken.length();
//qDebug()<<startPos<<":"<<endPos<<" - "+sToken+" - "<<edit->mCaretX<<":"<<edit->mCaretX+edit->mInputPreeditString.length();
if (!(endPos < mEdit->mCaretX
|| startPos >= mEdit->mCaretX+mEdit->mInputPreeditString.length())) {
if (!preeditAttr) {
preeditAttr = attr;
} else {
attr = preeditAttr;
}
}
areaList.append(area);
mEdit->mGlyphPostionCacheForInputMethod.str = sLine;
mEdit->mGlyphPostionCacheForInputMethod.glyphCharList = glyphStartCharList;
mEdit->mGlyphPostionCacheForInputMethod.glyphPositionList = glyphStartPositionsList;
mEdit->mGlyphPostionCacheForInputMethod.strWidth = tokenLeft;
}
paintEditAreas(areaList);
bool showGlyph=false;
if (attr && attr->tokenType() == TokenType::Space) {
int pos = mEdit->mSyntaxer->getTokenPos();
if (pos==0) {
showGlyph = mEdit->mOptions.testFlag(eoShowLeadingSpaces);
} else if (pos+sToken.length()==sLine.length()) {
showGlyph = mEdit->mOptions.testFlag(eoShowTrailingSpaces);
} else {
showGlyph = mEdit->mOptions.testFlag(eoShowInnerSpaces);
}
}
addHighlightToken(
sLine,
sToken,
tokenLeft,
vLine, attr,showGlyph,
glyphStartCharList,
tokenStartChar,
tokenEndChar,
glyphStartPositionsList,
tokenWidth);
tokenLeft+=tokenWidth;
// Let the highlighter scan the next token.
mEdit->mSyntaxer->next();
}
mEdit->mDocument->setLineWidth(vLine-1, sLine, tokenLeft, glyphStartPositionsList);
if (tokenLeft<mRight) {
QString addOnStr;
// Paint folding
foldRange = mEdit->foldStartAtLine(vLine);
if ((foldRange) && foldRange->collapsed) {
addOnStr = mEdit->mSyntaxer->foldString(sLine);
attr = mEdit->mSyntaxer->symbolAttribute();
getBraceColorAttr(mEdit->mSyntaxer->getState().braceLevel,attr);
} else {
// Draw LineBreak glyph.
if (mEdit->mOptions.testFlag(eoShowLineBreaks)
&& (mEdit->mDocument->lineWidth(vLine-1) < mRight)) {
addOnStr = LineBreakGlyph;
attr = mEdit->mSyntaxer->whitespaceAttribute();
}
}
if (!addOnStr.isEmpty()) {
expandGlyphStartCharList(addOnStr, sLine.length(), glyphStartCharList);
int len=glyphStartCharList.length()-glyphStartPositionsList.length();
for (int i=0;i<len;i++) {
glyphStartPositionsList.append(tokenLeft);
}
int oldLen = sLine.length();
sLine += addOnStr;
addHighlightToken(
sLine,
addOnStr,
tokenLeft,
vLine, attr, false,
glyphStartCharList,
oldLen,
sLine.length(),
glyphStartPositionsList,
tokenWidth);
tokenLeft += tokenWidth;
}
}
// Draw anything that's left in the TokenAccu record. Fill to the end
// of the invalid area with the correct colors.
paintHighlightToken(sLine, glyphStartCharList, glyphStartPositionsList, true);
//Paint editingAreaBorders
foreach (const PEditingArea& area, areaList) {
if (mIsCurrentLine && mEdit->mInputPreeditString.length()>0) {
if (area->beginX > mEdit->mCaretX) {
area->beginX += mEdit->mInputPreeditString.length();
}
if (area->endX > mEdit->mCaretX) {
area->endX += mEdit->mInputPreeditString.length();
}
}
int glyphIdx;
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->beginX-1);
area->beginX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), area->endX-1);
area->endX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
}
//input method
if (mIsCurrentLine && mEdit->mInputPreeditString.length()>0) {
PEditingArea area = std::make_shared<EditingArea>();
int glyphIdx;
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), mEdit->mCaretX-1);
area->beginX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
glyphIdx = searchForSegmentIdx(glyphStartCharList, 0, sLine.length(), mEdit->mCaretX+mEdit->mInputPreeditString.length()-1);
area->endX = segmentIntervalStart(glyphStartPositionsList, 0, tokenLeft, glyphIdx);
area->type = EditingAreaType::eatUnderLine;
if (preeditAttr) {
area->color = preeditAttr->foreground();
} else {
area->color = colFG;
}
areaList.append(area);
mEdit->mGlyphPostionCacheForInputMethod.str = sLine;
mEdit->mGlyphPostionCacheForInputMethod.glyphCharList = glyphStartCharList;
mEdit->mGlyphPostionCacheForInputMethod.glyphPositionList = glyphStartPositionsList;
mEdit->mGlyphPostionCacheForInputMethod.strWidth = tokenLeft;
}
paintEditAreas(areaList);
// Now paint the right edge if necessary. We do it line by line to reduce
// the flicker. Should not cost very much anyway, compared to the many

View File

@ -25,7 +25,7 @@
#include <QPainter>
#include <QTimerEvent>
#include "syntaxer/syntaxer.h"
#include "constants.h"
#include "syntaxer/textfile.h"
#include "painter.h"
#include <QClipboard>
#include <QDebug>
@ -48,6 +48,7 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mWheelAccumulatedDeltaX{0},
mWheelAccumulatedDeltaY{0}
{
mSyntaxer = std::make_shared<TextSyntaxer>();
mCharWidth=1;
mTextHeight = 1;
mLastKey = 0;
@ -327,7 +328,7 @@ bool QSynEdit::canRedo() const
int QSynEdit::maxScrollWidth() const
{
int maxWidth = mDocument->longestLineWidth();
if (syntaxer())
if (mSyntaxer->supportFolding())
maxWidth += stringWidth(syntaxer()->foldString(""),maxWidth);
if (mOptions.testFlag(eoScrollPastEol))
return std::max(maxWidth ,1);
@ -348,7 +349,7 @@ bool QSynEdit::getTokenAttriAtRowCol(
int posX, posY, endPos, start;
QString line;
posY = pos.line - 1;
if (mSyntaxer && (posY >= 0) && (posY < mDocument->count())) {
if ((posY >= 0) && (posY < mDocument->count())) {
line = mDocument->getLine(posY);
if (posY == 0) {
mSyntaxer->resetState();
@ -381,7 +382,7 @@ bool QSynEdit::getTokenAttriAtRowColEx(const BufferCoord &pos, QString &token, i
int posX, posY, endPos;
QString line;
posY = pos.line - 1;
if (mSyntaxer && (posY >= 0) && (posY < mDocument->count())) {
if ((posY >= 0) && (posY < mDocument->count())) {
line = mDocument->getLine(posY);
if (posY == 0) {
mSyntaxer->resetState();
@ -442,55 +443,29 @@ void QSynEdit::doTrimTrailingSpaces()
auto action=finally([this](){
endEditing();
});
if (mSyntaxer) {
for (int i=0;i<mDocument->count();i++) {
if (mDocument->getSyntaxState(i).hasTrailingSpaces) {
int line = i+1;
QString oldLine = mDocument->getLine(i);
QString newLine = trimRight(oldLine);
if (newLine.isEmpty())
continue;
properSetLine(i,newLine);
mUndoList->addChange(
ChangeReason::Delete,
BufferCoord{1,line},
BufferCoord{oldLine.length()+1, line},
QStringList(oldLine),
SelectionMode::Normal
);
mUndoList->addChange(
ChangeReason::Insert,
BufferCoord{1, line},
BufferCoord{newLine.length()+1, line},
QStringList(),
SelectionMode::Normal
);
}
for (int i=0;i<mDocument->count();i++) {
if (mDocument->getSyntaxState(i).hasTrailingSpaces) {
int line = i+1;
QString oldLine = mDocument->getLine(i);
QString newLine = trimRight(oldLine);
if (newLine.isEmpty())
continue;
properSetLine(i,newLine);
mUndoList->addChange(
ChangeReason::Delete,
BufferCoord{1,line},
BufferCoord{oldLine.length()+1, line},
QStringList(oldLine),
SelectionMode::Normal
);
mUndoList->addChange(
ChangeReason::Insert,
BufferCoord{1, line},
BufferCoord{newLine.length()+1, line},
QStringList(),
SelectionMode::Normal
);
}
} else {
for (int i=0;i<mDocument->count();i++) {
int line = i+1;
QString oldLine = mDocument->getLine(i);
QString newLine = trimRight(oldLine);
if (newLine.isEmpty())
continue;
properSetLine(i,newLine);
mUndoList->addChange(
ChangeReason::Delete,
BufferCoord{1,line},
BufferCoord{oldLine.length()+1, line},
QStringList(oldLine),
SelectionMode::Normal
);
mUndoList->addChange(
ChangeReason::Insert,
BufferCoord{1, line},
BufferCoord{newLine.length()+1, line},
QStringList(),
SelectionMode::Normal
);
}
}
mUndoList->endBlock();
}
@ -685,7 +660,7 @@ void QSynEdit::invalidateGutterLines(int firstLine, int lastLine)
// find the visible lines first
if (lastLine < firstLine)
std::swap(lastLine, firstLine);
if (mUseCodeFolding) {
if (useCodeFolding()) {
firstLine = lineToRow(firstLine);
if (lastLine <= mDocument->count())
lastLine = lineToRow(lastLine);
@ -775,7 +750,7 @@ DisplayCoord QSynEdit::bufferToDisplayPos(const BufferCoord &p) const
if (p.line-1 <mDocument->count())
result.x = charToGlyphLeft(p.line,p.ch);
// Account for code folding
if (mUseCodeFolding)
if (useCodeFolding())
result.row = foldLineToRow(result.row);
return result;
}
@ -791,7 +766,7 @@ BufferCoord QSynEdit::displayToBufferPos(const DisplayCoord &p) const
if (p.row<1)
return result;
// Account for code folding
if (mUseCodeFolding)
if (useCodeFolding())
result.line = foldRowToLine(p.row);
// Account for tabs
if (result.line <= mDocument->count() ) {
@ -928,7 +903,7 @@ int QSynEdit::getLineIndent(const QString &line) const
int QSynEdit::rowToLine(int aRow) const
{
if (mUseCodeFolding)
if (useCodeFolding())
return foldRowToLine(aRow);
else
return aRow;
@ -989,7 +964,7 @@ void QSynEdit::invalidateLine(int line)
return;
// invalidate text area of this line
if (mUseCodeFolding)
if (useCodeFolding())
line = foldLineToRow(line);
if (line >= mTopLine && line <= mTopLine + mLinesInWindow) {
rcInval = { mGutterWidth,
@ -1029,7 +1004,7 @@ void QSynEdit::invalidateLines(int firstLine, int lastLine)
if (lastLine >= mDocument->count())
lastLine = INT_MAX; // paint empty space beyond last line
if (mUseCodeFolding) {
if (useCodeFolding()) {
firstLine = lineToRow(firstLine);
// Could avoid this conversion if (First = Last) and
// (Length < CharsInWindow) but the dependency isn't worth IMO.
@ -1247,7 +1222,7 @@ void QSynEdit::processGutterClick(QMouseEvent *event)
int line = rowToLine(row);
// Check if we clicked on a folding thing
if (mUseCodeFolding) {
if (useCodeFolding()) {
PCodeFoldingRange foldRange = foldStartAtLine(line);
if (foldRange) {
// See if we actually clicked on the rectangle...
@ -1595,7 +1570,7 @@ void QSynEdit::doComment()
int endLine;
if (mReadOnly)
return;
if (!syntaxer() || syntaxer()->commentSymbol().isEmpty())
if (mSyntaxer->commentSymbol().isEmpty())
return;
beginEditing();
auto action = finally([this]{
@ -1609,7 +1584,7 @@ void QSynEdit::doComment()
endLine = std::max(origBlockBegin.line - 1, origBlockEnd.line - 2);
else
endLine = origBlockEnd.line - 1;
QString commentSymbol = syntaxer()->commentSymbol();
QString commentSymbol = mSyntaxer->commentSymbol();
int symbolLen = commentSymbol.length();
for (int i = origBlockBegin.line - 1; i<=endLine; i++) {
mDocument->putLine(i, commentSymbol + mDocument->getLine(i));
@ -1640,9 +1615,9 @@ void QSynEdit::doUncomment()
QStringList changeText;
if (mReadOnly)
return;
if (!syntaxer() || syntaxer()->commentSymbol().isEmpty())
if (mSyntaxer->commentSymbol().isEmpty())
return;
QString commentSymbol=syntaxer()->commentSymbol();
QString commentSymbol=mSyntaxer->commentSymbol();
int symbolLen = commentSymbol.length();
changeText.append(commentSymbol);
beginEditing();
@ -1695,9 +1670,9 @@ void QSynEdit::doToggleComment()
bool allCommented = true;
if (mReadOnly)
return;
if (!syntaxer() || syntaxer()->commentSymbol().isEmpty())
if (mSyntaxer->commentSymbol().isEmpty())
return;
QString commentSymbol=syntaxer()->commentSymbol();
QString commentSymbol=mSyntaxer->commentSymbol();
beginEditing();
auto action = finally([this]{
@ -1729,10 +1704,10 @@ void QSynEdit::doToggleBlockComment()
QString s;
if (mReadOnly)
return;
if (!syntaxer() || syntaxer()->blockCommentBeginSymbol().isEmpty())
if (mSyntaxer->blockCommentBeginSymbol().isEmpty())
return;
QString beginSymbol=syntaxer()->blockCommentBeginSymbol();
QString endSymbol=syntaxer()->blockCommentEndSymbol();
QString beginSymbol=mSyntaxer->blockCommentBeginSymbol();
QString endSymbol=mSyntaxer->blockCommentEndSymbol();
int beginLen = beginSymbol.length();
int endLen = endSymbol.length();
@ -1849,7 +1824,7 @@ QString QSynEdit::getDisplayStringAtLine(int line) const
QString s = mDocument->getLine(line-1);
PCodeFoldingRange foldRange = foldStartAtLine(line);
if ((foldRange) && foldRange->collapsed) {
return s+syntaxer()->foldString(s);
return s+mSyntaxer->foldString(s);
}
return s;
}
@ -2279,7 +2254,7 @@ void QSynEdit::insertLine(bool moveCaret)
if (mCaretX>lineText().length()+1) {
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
if ((foldRange) && foldRange->collapsed) {
QString s = temp+syntaxer()->foldString(temp);
QString s = temp+mSyntaxer->foldString(temp);
if (mCaretX > s.length()) {
if (!mUndoing) {
addCaretToUndo();
@ -2310,20 +2285,19 @@ void QSynEdit::insertLine(bool moveCaret)
bool notInComment=true;
properSetLine(mCaretY-1,leftLineText);
//update range stated for line mCaretY
if (mSyntaxer) {
if (mCaretY==1) {
mSyntaxer->resetState();
} else {
mSyntaxer->setState(mDocument->getSyntaxState(mCaretY-2));
}
mSyntaxer->setLine(leftLineText, mCaretY-1);
mSyntaxer->nextToEol();
mDocument->setSyntaxState(mCaretY-1,mSyntaxer->getState());
notInComment = !mSyntaxer->isCommentNotFinished(
mSyntaxer->getState().state)
&& !mSyntaxer->isStringNotFinished(
mSyntaxer->getState().state);
if (mCaretY==1) {
mSyntaxer->resetState();
} else {
mSyntaxer->setState(mDocument->getSyntaxState(mCaretY-2));
}
mSyntaxer->setLine(leftLineText, mCaretY-1);
mSyntaxer->nextToEol();
mDocument->setSyntaxState(mCaretY-1,mSyntaxer->getState());
notInComment = !mSyntaxer->isCommentNotFinished(
mSyntaxer->getState().state)
&& !mSyntaxer->isStringNotFinished(
mSyntaxer->getState().state);
int indentSpaces = 0;
if (mOptions.testFlag(eoAutoIndent)) {
rightLineText=trimLeft(rightLineText);
@ -2818,7 +2792,6 @@ void QSynEdit::doAddChar(const QChar& ch)
// auto
if (mActiveSelectionMode==SelectionMode::Normal
&& mOptions.testFlag(eoAutoIndent)
&& mSyntaxer
&& mSyntaxer->language() == ProgrammingLanguage::CPP
&& (oldCaretY<=mDocument->count()) ) {
@ -3180,18 +3153,13 @@ void QSynEdit::recalcCharExtent()
FontStyle styles[] = {FontStyle::fsBold, FontStyle::fsItalic, FontStyle::fsStrikeOut, FontStyle::fsUnderline};
bool hasStyles[] = {false,false,false,false};
int size = 4;
if (mSyntaxer && mSyntaxer->attributes().count()>0) {
if (mSyntaxer->attributes().count()>0) {
for (const PTokenAttribute& attribute: mSyntaxer->attributes()) {
for (int i=0;i<size;i++) {
if (attribute->styles().testFlag(styles[i]))
hasStyles[i] = true;
}
}
} else {
hasStyles[0] = font().bold();
hasStyles[1] = font().italic();
hasStyles[2] = font().strikeOut();
hasStyles[3] = font().underline();
}
mTextHeight = 0;
@ -3291,56 +3259,59 @@ void QSynEdit::updateModifiedStatus()
emit statusChanged(StatusChange::scModifyChanged);
}
void QSynEdit::scanFrom(int index)
void QSynEdit::reparseLines(int startLine, int endLine)
{
if (mEditingCount>0)
return;
SyntaxState state;
int idx = std::max(0,index);
if (idx >= mDocument->count())
startLine = std::max(0,startLine);
endLine = std::min(endLine, mDocument->count());
if (startLine >= endLine)
return;
if (idx == 0) {
if (startLine == 0) {
mSyntaxer->resetState();
} else {
mSyntaxer->setState(mDocument->getSyntaxState(idx-1));
mSyntaxer->setState(mDocument->getSyntaxState(startLine-1));
}
int line = startLine;
do {
mSyntaxer->setLine(mDocument->getLine(idx), idx);
mSyntaxer->setLine(mDocument->getLine(line), line);
mSyntaxer->nextToEol();
state = mSyntaxer->getState();
mDocument->setSyntaxState(idx,state);
idx ++ ;
} while (idx < mDocument->count());
if (mUseCodeFolding)
mDocument->setSyntaxState(line,state);
line ++ ;
} while (line < endLine);
if (useCodeFolding())
rescanFolds();
return ;
}
void QSynEdit::reparseLine(int line)
{
if (!mSyntaxer)
return;
line--;
line = std::max(0,line);
if (line >= mDocument->count())
return;
// void QSynEdit::reparseLine(int line)
// {
// if (!mSyntaxer)
// return;
// line--;
// line = std::max(0,line);
// if (line >= mDocument->count())
// return;
if (line == 0) {
mSyntaxer->resetState();
} else {
mSyntaxer->setState(mDocument->getSyntaxState(line-1));
}
mSyntaxer->setLine(mDocument->getLine(line), line);
mSyntaxer->nextToEol();
SyntaxState iRange = mSyntaxer->getState();
mDocument->setSyntaxState(line,iRange);
}
// if (line == 0) {
// mSyntaxer->resetState();
// } else {
// mSyntaxer->setState(mDocument->getSyntaxState(line-1));
// }
// mSyntaxer->setLine(mDocument->getLine(line), line);
// mSyntaxer->nextToEol();
// SyntaxState iRange = mSyntaxer->getState();
// mDocument->setSyntaxState(line,iRange);
// }
void QSynEdit::reparseDocument()
{
if (mSyntaxer && !mDocument->empty()) {
if (!mDocument->empty()) {
// qint64 begin=QDateTime::currentMSecsSinceEpoch();
mSyntaxer->resetState();
for (int i =0;i<mDocument->count();i++) {
@ -3352,7 +3323,7 @@ void QSynEdit::reparseDocument()
// qDebug()<<diff<<mDocument->count();
}
if (mUseCodeFolding)
if (useCodeFolding())
rescanFolds();
}
@ -3389,7 +3360,7 @@ void QSynEdit::collapse(PCodeFoldingRange FoldRange)
updateScrollbars();
}
void QSynEdit::foldOnListInserted(int Line, int Count)
void QSynEdit::foldOnLinesInserted(int Line, int Count)
{
// Delete collapsed inside selection
for (int i = mAllFoldRanges->count()-1;i>=0;i--) {
@ -3402,7 +3373,7 @@ void QSynEdit::foldOnListInserted(int Line, int Count)
}
}
void QSynEdit::foldOnListDeleted(int Line, int Count)
void QSynEdit::foldOnLinesDeleted(int Line, int Count)
{
// Delete collapsed inside selection
for (int i = mAllFoldRanges->count()-1;i>=0;i--) {
@ -3427,7 +3398,7 @@ void QSynEdit::foldOnListCleared()
void QSynEdit::rescanFolds()
{
//qDebug()<<QDateTime::currentDateTime();
if (!mUseCodeFolding)
if (!useCodeFolding())
return;
// qint64 begin=QDateTime::currentMSecsSinceEpoch();
@ -3491,29 +3462,13 @@ void QSynEdit::scanForFoldRanges(PCodeFoldingRanges topFoldRanges)
//this func should only be used in findSubFoldRange
int QSynEdit::lineHasChar(int Line, int startChar, QChar character, const QString& tokenAttrName) {
QString CurLine = mDocument->getLine(Line);
if (!mSyntaxer){
for (int i=startChar; i<CurLine.length();i++) {
if (CurLine[i]==character) {
return i;
}
}
} else {
/*
mHighlighter->setState(mLines->ranges(Line),
mLines->braceLevel(Line),
mLines->bracketLevel(Line),
mLines->parenthesisLevel(Line));
mHighlighter->setLine(CurLine,Line);
*/
QString token;
while (!mSyntaxer->eol()) {
token = mSyntaxer->getToken();
PTokenAttribute attr = mSyntaxer->getTokenAttribute();
if (token == character && attr->name()==tokenAttrName)
return mSyntaxer->getTokenPos();
mSyntaxer->next();
}
QString token;
while (!mSyntaxer->eol()) {
token = mSyntaxer->getToken();
PTokenAttribute attr = mSyntaxer->getTokenAttribute();
if (token == character && attr->name()==tokenAttrName)
return mSyntaxer->getTokenPos();
mSyntaxer->next();
}
return -1;
}
@ -3523,7 +3478,7 @@ void QSynEdit::findSubFoldRange(PCodeFoldingRanges topFoldRanges, PCodeFoldingRa
PCodeFoldingRange collapsedFold;
int line = 0;
QString curLine;
if (!mSyntaxer)
if (mSyntaxer->supportFolding())
return;
while (line < mDocument->count()) { // index is valid for LinesToScan and fLines
@ -4528,7 +4483,7 @@ QString QSynEdit::selText() const
PCodeFoldingRange foldRange = foldStartAtLine(blockEnd().line);
QString s = mDocument->getLine(lastLine);
if ((foldRange) && foldRange->collapsed && charTo>s.length()) {
s=s+syntaxer()->foldString(s);
s=s+mSyntaxer->foldString(s);
if (charTo>s.length()) {
lastLine = foldRange->toLine-1;
charTo = mDocument->getLine(lastLine).length()+1;
@ -4607,7 +4562,7 @@ QStringList QSynEdit::getContent(BufferCoord startPos, BufferCoord endPos, Selec
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
QString s = mDocument->getLine(lastLine);
if ((foldRange) && foldRange->collapsed && chTo>s.length()) {
s=s+syntaxer()->foldString(s);
s=s+mSyntaxer->foldString(s);
if (chTo>s.length()) {
lastLine = foldRange->toLine-1;
chTo = mDocument->getLine(lastLine).length()+1;
@ -4663,7 +4618,7 @@ QString QSynEdit::lineBreak() const
bool QSynEdit::useCodeFolding() const
{
return mUseCodeFolding;
return mUseCodeFolding && mSyntaxer->supportFolding();
}
void QSynEdit::setUseCodeFolding(bool value)
@ -4684,7 +4639,7 @@ QString QSynEdit::displayLineText()
QString s= mDocument->getLine(mCaretY - 1);
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
if ((foldRange) && foldRange->collapsed) {
return s+syntaxer()->foldString(s);
return s+mSyntaxer->foldString(s);
}
return s;
}
@ -4712,11 +4667,10 @@ PSyntaxer QSynEdit::syntaxer() const
void QSynEdit::setSyntaxer(const PSyntaxer &syntaxer)
{
Q_ASSERT(syntaxer!=nullptr);
PSyntaxer oldSyntaxer = mSyntaxer;
mSyntaxer = syntaxer;
if (oldSyntaxer && mSyntaxer &&
oldSyntaxer ->language() == syntaxer->language()) {
} else {
if (oldSyntaxer ->language() != syntaxer->language()) {
recalcCharExtent();
mDocument->beginUpdate();
auto action=finally([this]{
@ -5285,7 +5239,7 @@ void QSynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionM
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
QString s = mDocument->getLine(endPos.line-1);
if ((foldRange) && foldRange->collapsed && endPos.ch>s.length()) {
QString newS=s+syntaxer()->foldString(s);
QString newS=s+mSyntaxer->foldString(s);
if ((startPos.ch<=s.length() || startPos.line<endPos.line)
&& endPos.ch>newS.length() ) {
//selection has whole block
@ -5444,7 +5398,7 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
int caretY=pos.line;
// step1: insert the first line of Value into current line
if (text.length()>1) {
if (!mUndoing && mSyntaxer && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(eoAutoIndent)) {
if (!mUndoing && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(eoAutoIndent)) {
QString s = trimLeft(text[0]);
if (sLeftSide.isEmpty()) {
sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true);
@ -5458,7 +5412,7 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
str = sLeftSide + text[0] + sRightSide;
properSetLine(caretY - 1, str);
}
reparseLine(caretY);
reparseLines(caretY,caretY+1);
// step2: insert remaining lines of Value
for (int i=1;i<text.length();i++) {
bool notInComment = true;
@ -5481,12 +5435,12 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
if (i==text.length()-1)
str += sRightSide;
}
if (!mUndoing && mSyntaxer && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(eoAutoIndent) && notInComment) {
if (!mUndoing && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(eoAutoIndent) && notInComment) {
int indentSpaces = calcIndentSpaces(caretY,str,true);
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
}
properSetLine(caretY - 1, str,false);
reparseLine(caretY);
reparseLines(caretY, caretY+1);
result++;
}
bChangeScroll = !mOptions.testFlag(eoScrollPastEol);
@ -5942,41 +5896,12 @@ void QSynEdit::endEditingWithoutUndo()
bool QSynEdit::isIdentChar(const QChar &ch)
{
if (mSyntaxer) {
return mSyntaxer->isIdentChar(ch);
} else {
if (ch == '_') {
return true;
}
if ((ch>='0') && (ch <= '9')) {
return true;
}
if ((ch>='a') && (ch <= 'z')) {
return true;
}
if ((ch>='A') && (ch <= 'Z')) {
return true;
}
return false;
}
return mSyntaxer->isIdentChar(ch);
}
bool QSynEdit::isIdentStartChar(const QChar &ch)
{
if (mSyntaxer) {
return mSyntaxer->isIdentStartChar(ch);
} else {
if (ch == '_') {
return true;
}
if ((ch>='a') && (ch <= 'z')) {
return true;
}
if ((ch>='A') && (ch <= 'Z')) {
return true;
}
return false;
}
return mSyntaxer->isIdentStartChar(ch);
}
void QSynEdit::setRainbowAttrs(const PTokenAttribute &attr0, const PTokenAttribute &attr1, const PTokenAttribute &attr2, const PTokenAttribute &attr3)
@ -6655,7 +6580,7 @@ void QSynEdit::onLinesChanging()
void QSynEdit::onLinesCleared()
{
if (mUseCodeFolding)
if (useCodeFolding())
foldOnListCleared();
clearUndo();
// invalidate the *whole* client area
@ -6669,34 +6594,40 @@ void QSynEdit::onLinesCleared()
mStatusChanges.setFlag(StatusChange::scAll);
}
void QSynEdit::onLinesDeleted(int index, int count)
void QSynEdit::onLinesDeleted(int line, int count)
{
if (mUseCodeFolding)
foldOnListDeleted(index + 1, count);
if (mSyntaxer && mDocument->count() > 0) {
scanFrom(index);
foldOnLinesDeleted(line + 1, count);
if (mSyntaxer->needsLineState()) {
reparseLines(line, mDocument->count());
}
invalidateLines(index + 1, INT_MAX);
invalidateGutterLines(index + 1, INT_MAX);
invalidateLines(line + 1, INT_MAX);
// invalidateGutterLines(index + 1, INT_MAX);
}
void QSynEdit::onLinesInserted(int index, int count)
void QSynEdit::onLinesInserted(int line, int count)
{
if (mUseCodeFolding)
foldOnListInserted(index + 1, count);
if (mSyntaxer && mDocument->count() > 0) {
scanFrom(index);
foldOnLinesInserted(line + 1, count);
if (mSyntaxer->needsLineState()) {
reparseLines(line, mDocument->count());
} else {
// new lines should be parsed
reparseLines(line, line + count);
}
invalidateLines(index + 1, INT_MAX);
invalidateGutterLines(index + 1, INT_MAX);
invalidateLines(line + 1, INT_MAX);
// invalidateGutterLines(index + 1, INT_MAX);
}
void QSynEdit::onLinesPutted(int index, int /*count*/)
void QSynEdit::onLinesPutted(int line)
{
if (mSyntaxer) {
scanFrom(index);
if (mSyntaxer->needsLineState()) {
reparseLines(line, mDocument->count());
invalidateLines(line + 1, INT_MAX);
} else {
reparseLines(line, line+1);
invalidateLine( line + 1 );
}
invalidateLines(index + 1, INT_MAX);
}
void QSynEdit::onUndoAdded()
@ -6780,8 +6711,8 @@ void QSynEdit::setBlockEnd(BufferCoord value)
value.ch = 1;
} else {
int maxLen = mDocument->longestLineWidth();
if (syntaxer())
maxLen += stringWidth(syntaxer()->foldString(""),maxLen);
if (mSyntaxer->supportFolding())
maxLen += stringWidth(mSyntaxer->foldString(""),maxLen);
value.ch = minMax(value.ch, 1, maxLen+1);
}
if (value.ch != mBlockEnd.ch || value.line != mBlockEnd.line) {
@ -6887,8 +6818,8 @@ void QSynEdit::setBlockBegin(BufferCoord value)
value.ch = 1;
} else {
int maxLen = mDocument->longestLineWidth();
if (syntaxer())
maxLen += stringWidth(syntaxer()->foldString(""),maxLen);
if (mSyntaxer->supportFolding())
maxLen += stringWidth(mSyntaxer->foldString(""),maxLen);
value.ch = minMax(value.ch, 1, maxLen+1);
}
if (selAvail()) {

View File

@ -532,14 +532,14 @@ private:
void recalcCharExtent();
QString expandAtWideGlyphs(const QString& S);
void updateModifiedStatus();
void scanFrom(int index);
void reparseLines(int startLine, int endLine);
void reparseLine(int line);
void reparseDocument();
void uncollapse(PCodeFoldingRange FoldRange);
void collapse(PCodeFoldingRange FoldRange);
void foldOnListInserted(int Line, int Count);
void foldOnListDeleted(int Line, int Count);
void foldOnLinesInserted(int Line, int Count);
void foldOnLinesDeleted(int Line, int Count);
void foldOnListCleared();
void rescanFolds(); // rescan for folds
void rescanForFoldRanges();
@ -655,9 +655,9 @@ private slots:
void onLinesChanged();
void onLinesChanging();
void onLinesCleared();
void onLinesDeleted(int index, int count);
void onLinesInserted(int index, int count);
void onLinesPutted(int index, int count);
void onLinesDeleted(int line, int count);
void onLinesInserted(int line, int count);
void onLinesPutted(int line, int count);
//void onRedoAdded();
void onScrollTimeout();
void onDraggingScrollTimeout();

View File

@ -1720,12 +1720,12 @@ void ASMSyntaxer::setLine(const QString &newLine, int lineNumber)
bool ASMSyntaxer::isCommentNotFinished(int /*state*/) const
{
return true;
return false;
}
bool ASMSyntaxer::isStringNotFinished(int /*state*/) const
{
return true;
return false;
}
SyntaxState ASMSyntaxer::getState() const
@ -1745,6 +1745,16 @@ void ASMSyntaxer::resetState()
mHasTrailingSpaces = false;
}
bool ASMSyntaxer::supportFolding()
{
return false;
}
bool ASMSyntaxer::needsLineState()
{
return true;
}
QSet<QString> ASMSyntaxer::keywords()
{
if (mKeywordsCache.isEmpty()) {

View File

@ -1505,6 +1505,16 @@ QString CppSyntaxer::blockCommentEndSymbol()
return "*/";
}
bool CppSyntaxer::supportFolding()
{
return true;
}
bool CppSyntaxer::needsLineState()
{
return true;
}
bool CppSyntaxer::isCommentNotFinished(int state) const
{
return (state == RangeState::rsAnsiC ||

View File

@ -1438,4 +1438,14 @@ QString GLSLSyntaxer::blockCommentEndSymbol()
{
return "*/";
}
bool GLSLSyntaxer::supportFolding()
{
return true;
}
bool GLSLSyntaxer::needsLineState()
{
}
}

View File

@ -984,6 +984,16 @@ QString LuaSyntaxer::blockCommentEndSymbol()
return "]";
}
bool LuaSyntaxer::supportFolding()
{
return true;
}
bool LuaSyntaxer::needsLineState()
{
return false;
}
const QSet<QString> &LuaSyntaxer::customTypeKeywords() const
{
return mCustomTypeKeywords;

View File

@ -691,4 +691,14 @@ QString MakefileSyntaxer::commentSymbol()
return "#";
}
bool MakefileSyntaxer::supportFolding()
{
return false;
}
bool MakefileSyntaxer::needsLineState()
{
return true;
}
}

View File

@ -218,18 +218,6 @@ QString Syntaxer::blockCommentEndSymbol()
return QString();
}
bool Syntaxer::enabled() const
{
return mEnabled;
}
void Syntaxer::setEnabled(bool value)
{
if (value != mEnabled) {
mEnabled = value;
}
}
FontStyles TokenAttribute::styles() const
{
return mStyles;

View File

@ -122,7 +122,7 @@ public:
Syntaxer(const Syntaxer&)=delete;
Syntaxer& operator=(const Syntaxer&)=delete;
const QMap<QString, PTokenAttribute>& attributes() const;
virtual const QMap<QString, PTokenAttribute>& attributes() const;
const QSet<QChar>& wordBreakChars() const;
@ -166,13 +166,14 @@ public:
virtual bool supportBraceLevel();
virtual bool isSpaceChar(const QChar& ch);
virtual bool isWordBreakChar(const QChar& ch);
bool enabled() const;
void setEnabled(bool value);
virtual PTokenAttribute getAttribute(const QString& name) const;
virtual QString commentSymbol();
virtual QString blockCommentBeginSymbol();
virtual QString blockCommentEndSymbol();
virtual bool supportFolding() = 0;
virtual bool needsLineState() = 0;
protected:
PTokenAttribute mCommentAttribute;
@ -188,7 +189,6 @@ protected:
private:
QMap<QString,PTokenAttribute> mAttributes;
bool mEnabled;
QSet<QChar> mWordBreakChars;
};

View File

@ -37,6 +37,7 @@ enum class ProgrammingLanguage {
LUA,
XMAKE,
Custom,
Textfile,
Unknown
};