Merge branch 'master' of github.com:royqh1979/RedPanda-CPP

This commit is contained in:
Roy Qu 2022-12-16 09:10:57 +08:00
commit 7ddc30967d
29 changed files with 1324 additions and 1185 deletions

View File

@ -1,3 +1,9 @@
Red Panda C++ Version 2.7
- enhancement: Remove multiple problems in the problem set view
- enhancement: Clear the proble view after a new problem set created
- enhancement: "Remove trailing spaces" in options / editor / misc
Red Panda C++ Version 2.6 Red Panda C++ Version 2.6
- enhancement: Highlighter for makefiles - enhancement: Highlighter for makefiles

View File

@ -10,7 +10,7 @@ isEmpty(APP_NAME) {
} }
isEmpty(APP_VERSION) { isEmpty(APP_VERSION) {
APP_VERSION = 2.6 APP_VERSION = 2.7
} }
macos: { macos: {

View File

@ -265,6 +265,8 @@ bool Editor::save(bool force, bool doReparse) {
try { try {
if (pSettings->editor().autoFormatWhenSaved()) { if (pSettings->editor().autoFormatWhenSaved()) {
reformat(false); reformat(false);
} else if (pSettings->editor().removeTrailingSpacesWhenSaved()) {
trimTrailingSpaces();
} }
saveFile(mFilename); saveFile(mFilename);
pMainWindow->fileSystemWatcher()->addPath(mFilename); pMainWindow->fileSystemWatcher()->addPath(mFilename);
@ -356,6 +358,8 @@ bool Editor::saveAs(const QString &name, bool fromProject){
if (pSettings->editor().autoFormatWhenSaved()) { if (pSettings->editor().autoFormatWhenSaved()) {
reformat(false); reformat(false);
} else if (pSettings->editor().removeTrailingSpacesWhenSaved()) {
trimTrailingSpaces();
} }
try { try {
mFilename = newName; mFilename = newName;
@ -521,7 +525,7 @@ void Editor::undoSymbolCompletion(int pos)
(pSettings->editor().completeBrace() && (DeletedChar == '{') && (NextChar == '}')) || (pSettings->editor().completeBrace() && (DeletedChar == '{') && (NextChar == '}')) ||
(pSettings->editor().completeSingleQuote() && (DeletedChar == '\'') && (NextChar == '\'')) || (pSettings->editor().completeSingleQuote() && (DeletedChar == '\'') && (NextChar == '\'')) ||
(pSettings->editor().completeDoubleQuote() && (DeletedChar == '\"') && (NextChar == '\"'))) { (pSettings->editor().completeDoubleQuote() && (DeletedChar == '\"') && (NextChar == '\"'))) {
commandProcessor(QSynedit::EditCommand::ecDeleteChar); processCommand(QSynedit::EditCommand::DeleteChar);
} }
} }
@ -723,7 +727,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
if (mParser && mParser->isIncludeLine(lineText()) if (mParser && mParser->isIncludeLine(lineText())
&& mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()) { && mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()) {
// is a #include line // is a #include line
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showHeaderCompletion(false); showHeaderCompletion(false);
handled=true; handled=true;
return; return;
@ -731,12 +735,12 @@ void Editor::keyPressEvent(QKeyEvent *event)
QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY()); QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY());
if (mParser && !lastWord.isEmpty()) { if (mParser && !lastWord.isEmpty()) {
if (lastWord == "using") { if (lastWord == "using") {
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false, CodeCompletionType::ComplexKeyword); showCompletion(lastWord,false, CodeCompletionType::ComplexKeyword);
handled=true; handled=true;
return; return;
} else if (lastWord == "namespace") { } else if (lastWord == "namespace") {
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false, CodeCompletionType::Namespaces); showCompletion(lastWord,false, CodeCompletionType::Namespaces);
handled=true; handled=true;
return; return;
@ -747,7 +751,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
} }
if (!currentScope || currentScope->kind == StatementKind::skNamespace) { if (!currentScope || currentScope->kind == StatementKind::skNamespace) {
//may define a function //may define a function
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false,CodeCompletionType::FunctionWithoutDefinition); showCompletion(lastWord,false,CodeCompletionType::FunctionWithoutDefinition);
handled=true; handled=true;
return; return;
@ -757,7 +761,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
lastWord == "signed" || lastWord == "signed" ||
lastWord == "unsigned" lastWord == "unsigned"
) { ) {
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false, CodeCompletionType::ComplexKeyword); showCompletion(lastWord,false, CodeCompletionType::ComplexKeyword);
handled=true; handled=true;
return; return;
@ -783,7 +787,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
} }
if (!currentScope || currentScope->kind == StatementKind::skNamespace) { if (!currentScope || currentScope->kind == StatementKind::skNamespace) {
//may define a function //may define a function
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition); showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition);
handled=true; handled=true;
return; return;
@ -801,13 +805,13 @@ void Editor::keyPressEvent(QKeyEvent *event)
} }
if (!currentScope || currentScope->kind == StatementKind::skNamespace) { if (!currentScope || currentScope->kind == StatementKind::skNamespace) {
//may define a function //may define a function
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition); showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition);
handled=true; handled=true;
return; return;
} }
} }
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::Normal); showCompletion("",false,CodeCompletionType::Normal);
handled=true; handled=true;
return; return;
@ -819,7 +823,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& pSettings->codeCompletion().showCompletionWhileInput() ) { && pSettings->codeCompletion().showCompletionWhileInput() ) {
mLastIdCharPressed++; mLastIdCharPressed++;
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::Normal); showCompletion("",false,CodeCompletionType::Normal);
handled=true; handled=true;
return; return;
@ -831,7 +835,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& pSettings->codeCompletion().showCompletionWhileInput() ) { && pSettings->codeCompletion().showCompletionWhileInput() ) {
mLastIdCharPressed++; mLastIdCharPressed++;
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::Normal); showCompletion("",false,CodeCompletionType::Normal);
handled=true; handled=true;
return; return;
@ -1877,52 +1881,52 @@ bool Editor::notParsed()
void Editor::insertLine() void Editor::insertLine()
{ {
commandProcessor(QSynedit::EditCommand::ecInsertLine,QChar(),nullptr); processCommand(QSynedit::EditCommand::InsertLine,QChar(),nullptr);
} }
void Editor::deleteWord() void Editor::deleteWord()
{ {
commandProcessor(QSynedit::EditCommand::ecDeleteWord,QChar(),nullptr); processCommand(QSynedit::EditCommand::DeleteWord,QChar(),nullptr);
} }
void Editor::deleteToWordStart() void Editor::deleteToWordStart()
{ {
commandProcessor(QSynedit::EditCommand::ecDeleteWordStart,QChar(),nullptr); processCommand(QSynedit::EditCommand::DeleteWordStart,QChar(),nullptr);
} }
void Editor::deleteToWordEnd() void Editor::deleteToWordEnd()
{ {
commandProcessor(QSynedit::EditCommand::ecDeleteWordEnd,QChar(),nullptr); processCommand(QSynedit::EditCommand::DeleteWordEnd,QChar(),nullptr);
} }
void Editor::deleteLine() void Editor::deleteLine()
{ {
commandProcessor(QSynedit::EditCommand::ecDeleteLine,QChar(),nullptr); processCommand(QSynedit::EditCommand::DeleteLine,QChar(),nullptr);
} }
void Editor::duplicateLine() void Editor::duplicateLine()
{ {
commandProcessor(QSynedit::EditCommand::ecDuplicateLine,QChar(),nullptr); processCommand(QSynedit::EditCommand::DuplicateLine,QChar(),nullptr);
} }
void Editor::deleteToEOL() void Editor::deleteToEOL()
{ {
commandProcessor(QSynedit::EditCommand::ecDeleteEOL,QChar(),nullptr); processCommand(QSynedit::EditCommand::DeleteEOL,QChar(),nullptr);
} }
void Editor::deleteToBOL() void Editor::deleteToBOL()
{ {
commandProcessor(QSynedit::EditCommand::ecDeleteBOL,QChar(),nullptr); processCommand(QSynedit::EditCommand::DeleteBOL,QChar(),nullptr);
} }
void Editor::gotoBlockStart() void Editor::gotoBlockStart()
{ {
commandProcessor(QSynedit::EditCommand::ecBlockStart,QChar(),nullptr); processCommand(QSynedit::EditCommand::BlockStart,QChar(),nullptr);
} }
void Editor::gotoBlockEnd() void Editor::gotoBlockEnd()
{ {
commandProcessor(QSynedit::EditCommand::ecBlockEnd,QChar(),nullptr); processCommand(QSynedit::EditCommand::BlockEnd,QChar(),nullptr);
} }
QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion( QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion(
@ -2302,17 +2306,17 @@ bool Editor::handleParentheseCompletion()
QString text=selText(); QString text=selText();
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'('); processCommand(QSynedit::EditCommand::Char,'(');
setSelText(text); setSelText(text);
commandProcessor(QSynedit::EditCommand::ecChar,')'); processCommand(QSynedit::EditCommand::Char,')');
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
} else { } else {
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'('); processCommand(QSynedit::EditCommand::Char,'(');
QSynedit::BufferCoord oldCaret = caretXY(); QSynedit::BufferCoord oldCaret = caretXY();
commandProcessor(QSynedit::EditCommand::ecChar,')'); processCommand(QSynedit::EditCommand::Char,')');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
@ -2363,17 +2367,17 @@ bool Editor::handleBracketCompletion()
QString text=selText(); QString text=selText();
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'['); processCommand(QSynedit::EditCommand::Char,'[');
setSelText(text); setSelText(text);
commandProcessor(QSynedit::EditCommand::ecChar,']'); processCommand(QSynedit::EditCommand::Char,']');
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
} else { } else {
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'['); processCommand(QSynedit::EditCommand::Char,'[');
QSynedit::BufferCoord oldCaret = caretXY(); QSynedit::BufferCoord oldCaret = caretXY();
commandProcessor(QSynedit::EditCommand::ecChar,']'); processCommand(QSynedit::EditCommand::Char,']');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
@ -2411,14 +2415,14 @@ bool Editor::handleMultilineCommentCompletion()
QString text=selText(); QString text=selText();
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'*'); processCommand(QSynedit::EditCommand::Char,'*');
QSynedit::BufferCoord oldCaret; QSynedit::BufferCoord oldCaret;
if (text.isEmpty()) if (text.isEmpty())
oldCaret = caretXY(); oldCaret = caretXY();
else else
setSelText(text); setSelText(text);
commandProcessor(QSynedit::EditCommand::ecChar,'*'); processCommand(QSynedit::EditCommand::Char,'*');
commandProcessor(QSynedit::EditCommand::ecChar,'/'); processCommand(QSynedit::EditCommand::Char,'/');
if (text.isEmpty()) if (text.isEmpty())
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock(); endUndoBlock();
@ -2439,16 +2443,16 @@ bool Editor::handleBraceCompletion()
QString text=selText(); QString text=selText();
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'{'); processCommand(QSynedit::EditCommand::Char,'{');
QSynedit::BufferCoord oldCaret; QSynedit::BufferCoord oldCaret;
if (text.isEmpty()) { if (text.isEmpty()) {
oldCaret = caretXY(); oldCaret = caretXY();
} else { } else {
commandProcessor(QSynedit::EditCommand::ecInsertLine); processCommand(QSynedit::EditCommand::InsertLine);
setSelText(text); setSelText(text);
commandProcessor(QSynedit::EditCommand::ecInsertLine); processCommand(QSynedit::EditCommand::InsertLine);
} }
commandProcessor(QSynedit::EditCommand::ecChar,'}'); processCommand(QSynedit::EditCommand::Char,'}');
if ( if (
( (s.startsWith("struct") ( (s.startsWith("struct")
|| s.startsWith("class") || s.startsWith("class")
@ -2459,7 +2463,7 @@ bool Editor::handleBraceCompletion()
|| s.startsWith("enum") ) || s.startsWith("enum") )
&& !s.contains(';') && !s.contains(';')
) || s.endsWith('=')) { ) || s.endsWith('=')) {
commandProcessor(QSynedit::EditCommand::ecChar,';'); processCommand(QSynedit::EditCommand::Char,';');
} }
if (text.isEmpty()) if (text.isEmpty())
setCaretXY(oldCaret); setCaretXY(oldCaret);
@ -2481,7 +2485,7 @@ bool Editor::handleBraceSkip()
if (lastLineState.braceLevel==0) { if (lastLineState.braceLevel==0) {
bool oldInsertMode = insertMode(); bool oldInsertMode = insertMode();
setInsertMode(false); //set mode to overwrite setInsertMode(false); //set mode to overwrite
commandProcessor(QSynedit::EditCommand::ecChar,'}'); processCommand(QSynedit::EditCommand::Char,'}');
setInsertMode(oldInsertMode); setInsertMode(oldInsertMode);
return true; return true;
} }
@ -2490,7 +2494,7 @@ bool Editor::handleBraceSkip()
if (pos.line != 0) { if (pos.line != 0) {
bool oldInsertMode = insertMode(); bool oldInsertMode = insertMode();
setInsertMode(false); //set mode to overwrite setInsertMode(false); //set mode to overwrite
commandProcessor(QSynedit::EditCommand::ecChar,'}'); processCommand(QSynedit::EditCommand::Char,'}');
setInsertMode(oldInsertMode); setInsertMode(oldInsertMode);
return true; return true;
} }
@ -2513,9 +2517,9 @@ bool Editor::handleSingleQuoteCompletion()
QString text=selText(); QString text=selText();
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'\''); processCommand(QSynedit::EditCommand::Char,'\'');
setSelText(text); setSelText(text);
commandProcessor(QSynedit::EditCommand::ecChar,'\''); processCommand(QSynedit::EditCommand::Char,'\'');
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
@ -2524,9 +2528,9 @@ bool Editor::handleSingleQuoteCompletion()
// insert '' // insert ''
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'\''); processCommand(QSynedit::EditCommand::Char,'\'');
QSynedit::BufferCoord oldCaret = caretXY(); QSynedit::BufferCoord oldCaret = caretXY();
commandProcessor(QSynedit::EditCommand::ecChar,'\''); processCommand(QSynedit::EditCommand::Char,'\'');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
@ -2553,9 +2557,9 @@ bool Editor::handleDoubleQuoteCompletion()
QString text=selText(); QString text=selText();
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'"'); processCommand(QSynedit::EditCommand::Char,'"');
setSelText(text); setSelText(text);
commandProcessor(QSynedit::EditCommand::ecChar,'"'); processCommand(QSynedit::EditCommand::Char,'"');
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
@ -2564,9 +2568,9 @@ bool Editor::handleDoubleQuoteCompletion()
// insert "" // insert ""
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'"'); processCommand(QSynedit::EditCommand::Char,'"');
QSynedit::BufferCoord oldCaret = caretXY(); QSynedit::BufferCoord oldCaret = caretXY();
commandProcessor(QSynedit::EditCommand::ecChar,'"'); processCommand(QSynedit::EditCommand::Char,'"');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock(); endUndoBlock();
endUpdate(); endUpdate();
@ -2586,9 +2590,9 @@ bool Editor::handleGlobalIncludeCompletion()
return false; return false;
beginUpdate(); beginUpdate();
beginUndoBlock(); beginUndoBlock();
commandProcessor(QSynedit::EditCommand::ecChar,'<'); processCommand(QSynedit::EditCommand::Char,'<');
QSynedit::BufferCoord oldCaret = caretXY(); QSynedit::BufferCoord oldCaret = caretXY();
commandProcessor(QSynedit::EditCommand::ecChar,'>'); processCommand(QSynedit::EditCommand::Char,'>');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUpdate(); endUpdate();
endUndoBlock(); endUndoBlock();
@ -2617,17 +2621,17 @@ bool Editor::handleCodeCompletion(QChar key)
if (mParser) { if (mParser) {
switch(key.unicode()) { switch(key.unicode()) {
case '.': case '.':
commandProcessor(QSynedit::EditCommand::ecChar, key); processCommand(QSynedit::EditCommand::Char, key);
showCompletion("",false,CodeCompletionType::Normal); showCompletion("",false,CodeCompletionType::Normal);
return true; return true;
case '>': case '>':
commandProcessor(QSynedit::EditCommand::ecChar, key); processCommand(QSynedit::EditCommand::Char, key);
if ((caretX() > 2) && (lineText().length() >= 2) && if ((caretX() > 2) && (lineText().length() >= 2) &&
(lineText()[caretX() - 3] == '-')) (lineText()[caretX() - 3] == '-'))
showCompletion("",false,CodeCompletionType::Normal); showCompletion("",false,CodeCompletionType::Normal);
return true; return true;
case ':': case ':':
commandProcessor(QSynedit::EditCommand::ecChar,':',nullptr); processCommand(QSynedit::EditCommand::Char,':',nullptr);
//setSelText(key); //setSelText(key);
if ((caretX() > 2) && (lineText().length() >= 2) && if ((caretX() > 2) && (lineText().length() >= 2) &&
(lineText()[caretX() - 3] == ':')) (lineText()[caretX() - 3] == ':'))
@ -2635,7 +2639,7 @@ bool Editor::handleCodeCompletion(QChar key)
return true; return true;
case '/': case '/':
case '\\': case '\\':
commandProcessor(QSynedit::EditCommand::ecChar, key); processCommand(QSynedit::EditCommand::Char, key);
if (mParser->isIncludeLine(lineText())) { if (mParser->isIncludeLine(lineText())) {
showHeaderCompletion(false); showHeaderCompletion(false);
} }
@ -3395,8 +3399,8 @@ bool Editor::onCompletionKeyPressed(QKeyEvent *event)
//ignore it //ignore it
return true; return true;
case Qt::Key_Backspace: case Qt::Key_Backspace:
commandProcessor( processCommand(
QSynedit::EditCommand::ecDeleteLastChar, QSynedit::EditCommand::DeleteLastChar,
QChar(), nullptr); // Simulate backspace in editor QChar(), nullptr); // Simulate backspace in editor
if (purpose == WordPurpose::wpCompletion) { if (purpose == WordPurpose::wpCompletion) {
phrase = getWordForCompletionSearch(caretXY(), mCompletionPopup->memberOperator()=="::"); phrase = getWordForCompletionSearch(caretXY(), mCompletionPopup->memberOperator()=="::");
@ -3429,7 +3433,7 @@ bool Editor::onCompletionKeyPressed(QKeyEvent *event)
} }
QChar ch = event->text().front(); QChar ch = event->text().front();
if (isIdentChar(ch)) { if (isIdentChar(ch)) {
commandProcessor(QSynedit::EditCommand::ecChar, ch); processCommand(QSynedit::EditCommand::Char, ch);
if (purpose == WordPurpose::wpCompletion) { if (purpose == WordPurpose::wpCompletion) {
phrase = getWordForCompletionSearch(caretXY(),mCompletionPopup->memberOperator()=="::"); phrase = getWordForCompletionSearch(caretXY(),mCompletionPopup->memberOperator()=="::");
} else } else
@ -3457,8 +3461,8 @@ bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
QSynedit::BufferCoord pBeginPos,pEndPos; QSynedit::BufferCoord pBeginPos,pEndPos;
switch (event->key()) { switch (event->key()) {
case Qt::Key_Backspace: case Qt::Key_Backspace:
commandProcessor( processCommand(
QSynedit::EditCommand::ecDeleteLastChar, QSynedit::EditCommand::DeleteLastChar,
QChar(), nullptr); // Simulate backspace in editor QChar(), nullptr); // Simulate backspace in editor
phrase = getWordAtPosition(this,caretXY(), phrase = getWordAtPosition(this,caretXY(),
pBeginPos,pEndPos, pBeginPos,pEndPos,
@ -3489,7 +3493,7 @@ bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
if (isIdentChar(ch) || ch == '.' if (isIdentChar(ch) || ch == '.'
|| ch =='_' || ch=='+') { || ch =='_' || ch=='+') {
commandProcessor(QSynedit::EditCommand::ecChar, ch); processCommand(QSynedit::EditCommand::Char, ch);
phrase = getWordAtPosition(this,caretXY(), phrase = getWordAtPosition(this,caretXY(),
pBeginPos,pEndPos, pBeginPos,pEndPos,
WordPurpose::wpHeaderCompletion); WordPurpose::wpHeaderCompletion);
@ -4698,7 +4702,10 @@ void Editor::applySettings()
{ {
QSynedit::EditorOptions options = QSynedit::eoAltSetsColumnMode | QSynedit::EditorOptions options = QSynedit::eoAltSetsColumnMode |
QSynedit::eoDragDropEditing | QSynedit::eoDropFiles | QSynedit::eoKeepCaretX | QSynedit::eoTabsToSpaces | QSynedit::eoDragDropEditing | QSynedit::eoDropFiles | QSynedit::eoKeepCaretX | QSynedit::eoTabsToSpaces |
QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo; QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo
| QSynedit::eoSelectWordByDblClick;
options.setFlag(QSynedit::eoShowSpecialChars, false);
//options //options
options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent()); options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent());

View File

@ -7789,6 +7789,7 @@ void MainWindow::on_btnNewProblemSet_clicked()
mOJProblemSetNameCounter++; mOJProblemSetNameCounter++;
mOJProblemSetModel.create(tr("Problem Set %1").arg(mOJProblemSetNameCounter)); mOJProblemSetModel.create(tr("Problem Set %1").arg(mOJProblemSetNameCounter));
ui->lblProblemSet->setText(mOJProblemSetModel.name()); ui->lblProblemSet->setText(mOJProblemSetModel.name());
onProblemSetIndexChanged(QModelIndex(),QModelIndex());
} }
@ -7810,10 +7811,17 @@ void MainWindow::on_btnAddProblem_clicked()
void MainWindow::on_btnRemoveProblem_clicked() void MainWindow::on_btnRemoveProblem_clicked()
{ {
QModelIndex idx = ui->lstProblemSet->currentIndex(); QList<int> idxList;
if (!idx.isValid()) foreach (const QModelIndex idx,ui->lstProblemSet->selectionModel()->selectedIndexes()) {
return; idxList.append(idx.row());
mOJProblemSetModel.removeProblem(idx.row()); }
std::sort(idxList.begin(),idxList.end(),[](int i1, int i2){
return i1>i2;
});
foreach (int id,idxList) {
mOJProblemSetModel.removeProblem(id);
}
} }

View File

@ -879,6 +879,9 @@
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior"> <property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum> <enum>QAbstractItemView::SelectRows</enum>
</property> </property>

View File

@ -720,6 +720,16 @@ void Settings::Editor::setEnableCustomCTypeKeywords(bool newEnableCustomCTypeKey
mEnableCustomCTypeKeywords = newEnableCustomCTypeKeywords; mEnableCustomCTypeKeywords = newEnableCustomCTypeKeywords;
} }
bool Settings::Editor::removeTrailingSpacesWhenSaved() const
{
return mRemoveTrailingSpacesWhenSaved;
}
void Settings::Editor::setRemoveTrailingSpacesWhenSaved(bool newRemoveTrailingSpacesWhenSaved)
{
mRemoveTrailingSpacesWhenSaved = newRemoveTrailingSpacesWhenSaved;
}
bool Settings::Editor::highlightCurrentWord() const bool Settings::Editor::highlightCurrentWord() const
{ {
return mHighlightCurrentWord; return mHighlightCurrentWord;
@ -1301,6 +1311,7 @@ void Settings::Editor::doSave()
saveValue("undo_limit",mUndoLimit); saveValue("undo_limit",mUndoLimit);
saveValue("undo_memory_usage", mUndoMemoryUsage); saveValue("undo_memory_usage", mUndoMemoryUsage);
saveValue("auto_format_when_saved", mAutoFormatWhenSaved); saveValue("auto_format_when_saved", mAutoFormatWhenSaved);
saveValue("remove_trailing_spaces_when_saved",mRemoveTrailingSpacesWhenSaved);
saveValue("parse_todos",mParseTodos); saveValue("parse_todos",mParseTodos);
saveValue("custom_c_type_keywords", mCustomCTypeKeywords); saveValue("custom_c_type_keywords", mCustomCTypeKeywords);
@ -1448,6 +1459,7 @@ void Settings::Editor::doLoad()
mUndoLimit = intValue("undo_limit",0); mUndoLimit = intValue("undo_limit",0);
mUndoMemoryUsage = intValue("undo_memory_usage", 10); mUndoMemoryUsage = intValue("undo_memory_usage", 10);
mAutoFormatWhenSaved = boolValue("auto_format_when_saved", false); mAutoFormatWhenSaved = boolValue("auto_format_when_saved", false);
mRemoveTrailingSpacesWhenSaved = boolValue("remove_trailing_spaces_when_saved",false);
mParseTodos = boolValue("parse_todos",true); mParseTodos = boolValue("parse_todos",true);
mCustomCTypeKeywords = stringListValue("custom_c_type_keywords"); mCustomCTypeKeywords = stringListValue("custom_c_type_keywords");

View File

@ -379,6 +379,9 @@ public:
bool enableCustomCTypeKeywords() const; bool enableCustomCTypeKeywords() const;
void setEnableCustomCTypeKeywords(bool newEnableCustomCTypeKeywords); void setEnableCustomCTypeKeywords(bool newEnableCustomCTypeKeywords);
bool removeTrailingSpacesWhenSaved() const;
void setRemoveTrailingSpacesWhenSaved(bool newRemoveTrailingSpacesWhenSaved);
private: private:
//General //General
// indents // indents
@ -488,6 +491,7 @@ public:
int mUndoLimit; int mUndoLimit;
int mUndoMemoryUsage; int mUndoMemoryUsage;
bool mAutoFormatWhenSaved; bool mAutoFormatWhenSaved;
bool mRemoveTrailingSpacesWhenSaved;
bool mParseTodos; bool mParseTodos;
QStringList mCustomCTypeKeywords; QStringList mCustomCTypeKeywords;

View File

@ -66,7 +66,13 @@ void EditorMiscWidget::doLoad()
} }
ui->spinMaxUndo->setValue(pSettings->editor().undoLimit()); ui->spinMaxUndo->setValue(pSettings->editor().undoLimit());
ui->spinMaxUndoMemory->setValue(pSettings->editor().undoMemoryUsage()); ui->spinMaxUndoMemory->setValue(pSettings->editor().undoMemoryUsage());
ui->chkAutoReformat->setChecked(pSettings->editor().autoFormatWhenSaved()); if (pSettings->editor().removeTrailingSpacesWhenSaved())
ui->rbRemoveTrailingSpaces->setChecked(true);
else if (pSettings->editor().autoFormatWhenSaved())
ui->rbAutoReformat->setChecked(true);
else
ui->rbNone->setChecked(true);
ui->chkParseTodos->setChecked(pSettings->editor().parseTodos()); ui->chkParseTodos->setChecked(pSettings->editor().parseTodos());
} }
@ -84,7 +90,8 @@ void EditorMiscWidget::doSave()
} }
pSettings->editor().setUndoLimit(ui->spinMaxUndo->value()); pSettings->editor().setUndoLimit(ui->spinMaxUndo->value());
pSettings->editor().setUndoMemoryUsage(ui->spinMaxUndoMemory->value()); pSettings->editor().setUndoMemoryUsage(ui->spinMaxUndoMemory->value());
pSettings->editor().setAutoFormatWhenSaved(ui->chkAutoReformat->isChecked()); pSettings->editor().setAutoFormatWhenSaved(ui->rbAutoReformat->isChecked());
pSettings->editor().setRemoveTrailingSpacesWhenSaved(ui->rbRemoveTrailingSpaces->isChecked());
pSettings->editor().setParseTodos(ui->chkParseTodos->isChecked()); pSettings->editor().setParseTodos(ui->chkParseTodos->isChecked());

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>515</width> <width>515</width>
<height>408</height> <height>510</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -36,10 +36,55 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="chkAutoReformat"> <widget class="QGroupBox" name="groupBox_4">
<property name="text"> <property name="title">
<string>Auto reformat code before saving files</string> <string>Limits for Undo</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Memory Usage</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinMaxUndo">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
<property name="value">
<number>10000</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Steps</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="spinMaxUndoMemory">
<property name="suffix">
<string>MB</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -57,42 +102,6 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Max Undo Steps</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinMaxUndo">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
<property name="value">
<number>10000</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -111,28 +120,38 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> </layout>
<widget class="QLabel" name="label_2"> </widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Action before saving files</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QRadioButton" name="rbAutoReformat">
<property name="text"> <property name="text">
<string>Max Undo Memory Usage</string> <string>Reformat Code</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="2">
<widget class="QSpinBox" name="spinMaxUndoMemory"> <widget class="QRadioButton" name="rbRemoveTrailingSpaces">
<property name="suffix"> <property name="text">
<string>MB</string> <string>Remove Trailing Spaces</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="0">
<spacer name="horizontalSpacer_3"> <widget class="QRadioButton" name="rbNone">
<property name="text">
<string>None</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -187,7 +206,14 @@
<property name="title"> <property name="title">
<string>Default file type</string> <string>Default file type</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="rbCFile">
<property name="text">
<string>C files</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QRadioButton" name="rbCppFile"> <widget class="QRadioButton" name="rbCppFile">
<property name="text"> <property name="text">
@ -196,11 +222,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="rbCFile"> <spacer name="horizontalSpacer_3">
<property name="text"> <property name="orientation">
<string>C files</string> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -1433,7 +1433,7 @@
</message> </message>
<message> <message>
<source>Max Undo Steps</source> <source>Max Undo Steps</source>
<translation>Quantidade máxima de passos a serem desfeitos</translation> <translation type="vanished">Quantidade máxima de passos a serem desfeitos</translation>
</message> </message>
<message> <message>
<source>Default file encoding</source> <source>Default file encoding</source>
@ -1463,20 +1463,40 @@
<source>UTF-8 BOM</source> <source>UTF-8 BOM</source>
<translation>UTF-8 BOM</translation> <translation>UTF-8 BOM</translation>
</message> </message>
<message>
<source>Max Undo Memory Usage</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>MB</source> <source>MB</source>
<translation type="unfinished">MB</translation> <translation type="unfinished">MB</translation>
</message> </message>
<message> <message>
<source>Auto reformat code before saving files</source> <source>Parse TODOs</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Parse TODOs</source> <source>Memory Usage</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Steps</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Action before saving files</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reformat Code</source>
<translation type="unfinished">Reformatar código</translation>
</message>
<message>
<source>Remove Trailing Spaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>None</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Limits for Undo</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
@ -6947,6 +6967,10 @@
<source>Command: %1 %2</source> <source>Command: %1 %2</source>
<translation>Comando: %1 %2</translation> <translation>Comando: %1 %2</translation>
</message> </message>
<message>
<source>Compiling...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SymbolUsageManager</name> <name>SymbolUsageManager</name>

File diff suppressed because it is too large Load Diff

View File

@ -1324,10 +1324,6 @@
<source>Auto detect encoding when openning files</source> <source>Auto detect encoding when openning files</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Max Undo Steps</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Default file encoding</source> <source>Default file encoding</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -1356,20 +1352,40 @@
<source>UTF-8 BOM</source> <source>UTF-8 BOM</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Max Undo Memory Usage</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>MB</source> <source>MB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Auto reformat code before saving files</source> <source>Parse TODOs</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Parse TODOs</source> <source>Memory Usage</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Steps</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Action before saving files</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reformat Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Trailing Spaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>None</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Limits for Undo</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
@ -6560,6 +6576,10 @@
<source>Command: %1 %2</source> <source>Command: %1 %2</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Compiling...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SymbolUsageManager</name> <name>SymbolUsageManager</name>

View File

@ -33,7 +33,7 @@ RedPandaIDE.depends += redpanda-git-askpass
APP_NAME = RedPandaCPP APP_NAME = RedPandaCPP
APP_VERSION = 2.6 APP_VERSION = 2.7
linux: { linux: {
isEmpty(PREFIX) { isEmpty(PREFIX) {

View File

@ -24,7 +24,7 @@ EditKeyStroke::EditKeyStroke()
mKeyModifiers = Qt::NoModifier; mKeyModifiers = Qt::NoModifier;
mKey2 = 0; mKey2 = 0;
mKeyModifiers2 = Qt::NoModifier; mKeyModifiers2 = Qt::NoModifier;
mCommand = EditCommand::ecNone; mCommand = EditCommand::None;
} }
QKeySequence EditKeyStroke::keySequence() const QKeySequence EditKeyStroke::keySequence() const
@ -181,105 +181,71 @@ void EditKeyStrokes::clear()
void EditKeyStrokes::resetDefaults() void EditKeyStrokes::resetDefaults()
{ {
clear(); clear();
add(EditCommand::ecUp, Qt::Key_Up, Qt::NoModifier); add(EditCommand::Up, Qt::Key_Up, Qt::NoModifier);
add(EditCommand::ecSelUp, Qt::Key_Up, Qt::ShiftModifier); add(EditCommand::SelUp, Qt::Key_Up, Qt::ShiftModifier);
add(EditCommand::ecSelUp, Qt::Key_Up, Qt::ShiftModifier | Qt::AltModifier); add(EditCommand::SelUp, Qt::Key_Up, Qt::ShiftModifier | Qt::AltModifier);
add(EditCommand::ecScrollUp, Qt::Key_Up, Qt::ControlModifier); add(EditCommand::ScrollUp, Qt::Key_Up, Qt::ControlModifier);
add(EditCommand::ecDown, Qt::Key_Down, Qt::NoModifier); add(EditCommand::Down, Qt::Key_Down, Qt::NoModifier);
add(EditCommand::ecSelDown, Qt::Key_Down, Qt::ShiftModifier); add(EditCommand::SelDown, Qt::Key_Down, Qt::ShiftModifier);
add(EditCommand::ecSelDown, Qt::Key_Down, Qt::ShiftModifier | Qt::AltModifier); add(EditCommand::SelDown, Qt::Key_Down, Qt::ShiftModifier | Qt::AltModifier);
add(EditCommand::ecScrollDown, Qt::Key_Down, Qt::ControlModifier); add(EditCommand::ScrollDown, Qt::Key_Down, Qt::ControlModifier);
add(EditCommand::ecLeft, Qt::Key_Left, Qt::NoModifier); add(EditCommand::Left, Qt::Key_Left, Qt::NoModifier);
add(EditCommand::ecSelLeft, Qt::Key_Left, Qt::ShiftModifier); add(EditCommand::SelLeft, Qt::Key_Left, Qt::ShiftModifier);
add(EditCommand::ecWordLeft, Qt::Key_Left, Qt::ControlModifier); add(EditCommand::WordLeft, Qt::Key_Left, Qt::ControlModifier);
add(EditCommand::ecSelWordLeft, Qt::Key_Left, Qt::ShiftModifier|Qt::ControlModifier); add(EditCommand::SelWordLeft, Qt::Key_Left, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecRight, Qt::Key_Right, Qt::NoModifier); add(EditCommand::Right, Qt::Key_Right, Qt::NoModifier);
add(EditCommand::ecSelRight, Qt::Key_Right, Qt::ShiftModifier); add(EditCommand::SelRight, Qt::Key_Right, Qt::ShiftModifier);
add(EditCommand::ecWordRight, Qt::Key_Right, Qt::ControlModifier); add(EditCommand::WordRight, Qt::Key_Right, Qt::ControlModifier);
add(EditCommand::ecSelWordRight, Qt::Key_Right, Qt::ShiftModifier|Qt::ControlModifier); add(EditCommand::SelWordRight, Qt::Key_Right, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecBlockStart, Qt::Key_Up, Qt::MetaModifier|Qt::ControlModifier); add(EditCommand::BlockStart, Qt::Key_Up, Qt::MetaModifier|Qt::ControlModifier);
add(EditCommand::ecSelBlockStart, Qt::Key_Up, Qt::ShiftModifier|Qt::ControlModifier|Qt::MetaModifier); add(EditCommand::SelBlockStart, Qt::Key_Up, Qt::ShiftModifier|Qt::ControlModifier|Qt::MetaModifier);
add(EditCommand::ecBlockEnd, Qt::Key_Down, Qt::MetaModifier|Qt::ControlModifier); add(EditCommand::BlockEnd, Qt::Key_Down, Qt::MetaModifier|Qt::ControlModifier);
add(EditCommand::ecSelBlockEnd, Qt::Key_Down, Qt::ShiftModifier|Qt::ControlModifier|Qt::MetaModifier); add(EditCommand::SelBlockEnd, Qt::Key_Down, Qt::ShiftModifier|Qt::ControlModifier|Qt::MetaModifier);
// add(SynEditorCommand::ecExpandSelection, Qt::Key_Right, Qt::ShiftModifier|Qt::AltModifier); add(EditCommand::PageDown, Qt::Key_PageDown, Qt::NoModifier);
// add(SynEditorCommand::ecShrinkSelection, Qt::Key_Left, Qt::ShiftModifier | Qt::AltModifier); add(EditCommand::SelPageDown, Qt::Key_PageDown, Qt::ShiftModifier);
add(EditCommand::PageBottom, Qt::Key_PageDown, Qt::ControlModifier);
add(EditCommand::SelPageBottom, Qt::Key_PageDown, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::PageUp, Qt::Key_PageUp, Qt::NoModifier);
add(EditCommand::SelPageUp, Qt::Key_PageUp, Qt::ShiftModifier);
add(EditCommand::PageTop, Qt::Key_PageUp, Qt::ControlModifier);
add(EditCommand::SelPageTop, Qt::Key_PageUp, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::LineStart, Qt::Key_Home, Qt::NoModifier);
add(EditCommand::SelLineStart, Qt::Key_Home, Qt::ShiftModifier);
add(EditCommand::EditorStart, Qt::Key_Home, Qt::ControlModifier);
add(EditCommand::SelEditorStart, Qt::Key_Home, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::LineEnd, Qt::Key_End, Qt::NoModifier);
add(EditCommand::SelLineEnd, Qt::Key_End, Qt::ShiftModifier);
add(EditCommand::EditorEnd, Qt::Key_End, Qt::ControlModifier);
add(EditCommand::SelEditorEnd, Qt::Key_End, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ToggleMode, Qt::Key_Insert, Qt::NoModifier);
add(EditCommand::DeleteChar, Qt::Key_Delete, Qt::NoModifier);
add(EditCommand::DeleteLastChar, Qt::Key_Backspace, Qt::NoModifier);
add(EditCommand::LineBreak, Qt::Key_Return, Qt::NoModifier);
add(EditCommand::LineBreak, Qt::Key_Return, Qt::ShiftModifier);
add(EditCommand::LineBreakAtEnd, Qt::Key_Return, Qt::ControlModifier);
add(EditCommand::LineBreak, Qt::Key_Enter, Qt::NoModifier);
add(EditCommand::LineBreak, Qt::Key_Enter, Qt::ShiftModifier);
add(EditCommand::LineBreakAtEnd, Qt::Key_Enter, Qt::ControlModifier);
add(EditCommand::ecPageDown, Qt::Key_PageDown, Qt::NoModifier);
add(EditCommand::ecSelPageDown, Qt::Key_PageDown, Qt::ShiftModifier);
add(EditCommand::ecPageBottom, Qt::Key_PageDown, Qt::ControlModifier);
add(EditCommand::ecSelPageBottom, Qt::Key_PageDown, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecPageUp, Qt::Key_PageUp, Qt::NoModifier);
add(EditCommand::ecSelPageUp, Qt::Key_PageUp, Qt::ShiftModifier);
add(EditCommand::ecPageTop, Qt::Key_PageUp, Qt::ControlModifier);
add(EditCommand::ecSelPageTop, Qt::Key_PageUp, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecLineStart, Qt::Key_Home, Qt::NoModifier);
add(EditCommand::ecSelLineStart, Qt::Key_Home, Qt::ShiftModifier);
add(EditCommand::ecEditorStart, Qt::Key_Home, Qt::ControlModifier);
add(EditCommand::ecSelEditorStart, Qt::Key_Home, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecLineEnd, Qt::Key_End, Qt::NoModifier);
add(EditCommand::ecSelLineEnd, Qt::Key_End, Qt::ShiftModifier);
add(EditCommand::ecEditorEnd, Qt::Key_End, Qt::ControlModifier);
add(EditCommand::ecSelEditorEnd, Qt::Key_End, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecToggleMode, Qt::Key_Insert, Qt::NoModifier);
// add(SynEditorCommand::ecCopy, Qt::Key_Insert, Qt::ControlModifier);
// add(SynEditorCommand::ecCut, Qt::Key_Delete, Qt::ShiftModifier);
// add(SynEditorCommand::ecPaste, Qt::Key_Insert, Qt::ShiftModifier);
add(EditCommand::ecDeleteChar, Qt::Key_Delete, Qt::NoModifier);
add(EditCommand::ecDeleteLastChar, Qt::Key_Backspace, Qt::NoModifier);
// add(SynEditorCommand::ecDeleteLastChar, Qt::Key_Backspace, Qt::ShiftModifier);
// add(SynEditorCommand::ecDeleteWordStart, Qt::Key_Backspace, Qt::ControlModifier);
// add(SynEditorCommand::ecDeleteWordEnd, Qt::Key_Delete, Qt::ControlModifier);
// add(SynEditorCommand::ecUndo, Qt::Key_Backspace, Qt::AltModifier);
// add(SynEditorCommand::ecRedo, Qt::Key_Backspace, Qt::AltModifier|Qt::ShiftModifier);
add(EditCommand::ecLineBreak, Qt::Key_Return, Qt::NoModifier);
add(EditCommand::ecLineBreak, Qt::Key_Return, Qt::ShiftModifier);
add(EditCommand::ecLineBreakAtEnd, Qt::Key_Return, Qt::ControlModifier);
add(EditCommand::ecLineBreak, Qt::Key_Enter, Qt::NoModifier);
add(EditCommand::ecLineBreak, Qt::Key_Enter, Qt::ShiftModifier);
add(EditCommand::ecLineBreakAtEnd, Qt::Key_Enter, Qt::ControlModifier);
// add(SynEditorCommand::ecTab, Qt::Key_Tab, Qt::NoModifier);
// add(SynEditorCommand::ecShiftTab, Qt::Key_Backtab, Qt::ShiftModifier);
// add(SynEditorCommand::ecShiftTab, Qt::Key_Tab, Qt::ShiftModifier);
add(EditCommand::ecContextHelp, Qt::Key_F1, Qt::NoModifier);
// add(SynEditorCommand::ecSelectAll, Qt::Key_A, Qt::ControlModifier);
// add(SynEditorCommand::ecCopy, Qt::Key_C, Qt::ControlModifier);
// add(SynEditorCommand::ecPaste, Qt::Key_V, Qt::ControlModifier);
// add(SynEditorCommand::ecCut, Qt::Key_X, Qt::ControlModifier);
// add(SynEditorCommand::ecBlockIndent, Qt::Key_I, Qt::ControlModifier|Qt::ShiftModifier);
// add(SynEditorCommand::ecBlockUnindent, Qt::Key_U, Qt::ControlModifier|Qt::ShiftModifier);
// add(SynEditorCommand::ecLineBreak, Qt::Key_M, Qt::ControlModifier);
// add(SynEditorCommand::ecInsertLine, Qt::Key_N, Qt::ControlModifier);
// add(SynEditorCommand::ecDeleteWord, Qt::Key_T, Qt::ControlModifier);
// add(SynEditorCommand::ecDeleteLine, Qt::Key_Y, Qt::ControlModifier);
// add(SynEditorCommand::ecDeleteEOL, Qt::Key_Y, Qt::ControlModifier|Qt::ShiftModifier);
// add(SynEditorCommand::ecDuplicateLine, Qt::Key_D, Qt::ControlModifier);
// add(SynEditorCommand::ecUndo, Qt::Key_Z, Qt::ControlModifier);
// add(SynEditorCommand::ecRedo, Qt::Key_Z, Qt::ControlModifier|Qt::ShiftModifier);
// add(SynEditorCommand::ecNormalSelect, Qt::Key_N, Qt::ControlModifier | Qt::ShiftModifier);
// add(SynEditorCommand::ecColumnSelect, Qt::Key_C, Qt::ControlModifier | Qt::ShiftModifier);
// add(SynEditorCommand::ecLineSelect, Qt::Key_L, Qt::ControlModifier | Qt::ShiftModifier);
// add(SynEditorCommand::ecMatchBracket, Qt::Key_B, Qt::ControlModifier | Qt::ShiftModifier);
} }
void EditKeyStrokes::setExtraKeyStrokes() void EditKeyStrokes::setExtraKeyStrokes()
{ {
add(EditCommand::ecDeleteWordStart, Qt::Key_Backspace, Qt::ControlModifier); add(EditCommand::DeleteWordStart, Qt::Key_Backspace, Qt::ControlModifier);
add(EditCommand::ecDeleteWordEnd, Qt::Key_Delete, Qt::ControlModifier); add(EditCommand::DeleteWordEnd, Qt::Key_Delete, Qt::ControlModifier);
add(EditCommand::ecDuplicateLine, Qt::Key_D, Qt::ControlModifier); add(EditCommand::DuplicateLine, Qt::Key_D, Qt::ControlModifier);
add(EditCommand::ecDeleteLine, Qt::Key_E, Qt::ControlModifier); add(EditCommand::DeleteLine, Qt::Key_E, Qt::ControlModifier);
add(EditCommand::ecSelectAll, Qt::Key_A, Qt::ControlModifier); add(EditCommand::SelectAll, Qt::Key_A, Qt::ControlModifier);
add(EditCommand::ecCopy, Qt::Key_C, Qt::ControlModifier); add(EditCommand::Copy, Qt::Key_C, Qt::ControlModifier);
add(EditCommand::ecPaste, Qt::Key_V, Qt::ControlModifier); add(EditCommand::Paste, Qt::Key_V, Qt::ControlModifier);
add(EditCommand::ecCut, Qt::Key_X, Qt::ControlModifier); add(EditCommand::Cut, Qt::Key_X, Qt::ControlModifier);
add(EditCommand::ecUndo, Qt::Key_Z, Qt::ControlModifier); add(EditCommand::Undo, Qt::Key_Z, Qt::ControlModifier);
add(EditCommand::ecRedo, Qt::Key_Y, Qt::ControlModifier); add(EditCommand::Redo, Qt::Key_Y, Qt::ControlModifier);
} }
} }

View File

@ -39,144 +39,139 @@ namespace QSynedit {
// read-only mode // read-only mode
enum class EditCommand { enum class EditCommand {
ecNone = 0, // Nothing. Useful for user event to handle command None = 0, // Nothing. Useful for user event to handle command
ecViewCommandFirst = 0,
ecViewCommandLast = 500,
ecEditCommandFirst = 501,
ecEditCommandLast = 1000,
ecLeft = 1, // Move cursor left one char Left = 1, // Move cursor left one char
ecRight = 2, // Move cursor right one char Right = 2, // Move cursor right one char
ecUp = 3, // Move cursor up one line Up = 3, // Move cursor up one line
ecDown = 4, // Move cursor down one line Down = 4, // Move cursor down one line
ecWordLeft = 5, // Move cursor left one word WordLeft = 5, // Move cursor left one word
ecWordRight = 6, // Move cursor right one word WordRight = 6, // Move cursor right one word
ecLineStart = 7, // Move cursor to beginning of line LineStart = 7, // Move cursor to beginning of line
ecLineEnd = 8, // Move cursor to end of line LineEnd = 8, // Move cursor to end of line
ecPageUp = 9, // Move cursor up one page PageUp = 9, // Move cursor up one page
ecPageDown = 10, // Move cursor down one page PageDown = 10, // Move cursor down one page
ecPageLeft = 11, // Move cursor right one page PageLeft = 11, // Move cursor right one page
ecPageRight = 12, // Move cursor left one page PageRight = 12, // Move cursor left one page
ecPageTop = 13, // Move cursor to top of page PageTop = 13, // Move cursor to top of page
ecPageBottom = 14, // Move cursor to bottom of page PageBottom = 14, // Move cursor to bottom of page
ecEditorStart = 15, // Move cursor to absolute beginning EditorStart = 15, // Move cursor to absolute beginning
ecEditorEnd = 16, // Move cursor to absolute end EditorEnd = 16, // Move cursor to absolute end
ecGotoXY = 17, // Move cursor to specific coordinates, Data = PPoint GotoXY = 17, // Move cursor to specific coordinates, Data = PPoint
ecBlockStart = 18, // Move cursor to begin of block BlockStart = 18, // Move cursor to begin of block
ecBlockEnd = 19, // Move cursor to end of block BlockEnd = 19, // Move cursor to end of block
//****************************************************************************** //******************************************************************************
// Maybe the command processor should just take a boolean that signifies if // Maybe the command processor should just take a boolean that signifies if
// selection is affected or not? // selection is affected or not?
//****************************************************************************** //******************************************************************************
ecSelection = 100, // Add this to ecXXX command to get equivalent Selection = 100, // Add this to ecXXX command to get equivalent
// command, but with selection enabled. This is not // command, but with selection enabled. This is not
// a command itself. // a command itself.
// Same as commands above, except they affect selection, too // Same as commands above, except they affect selection, too
ecSelLeft = ecLeft + ecSelection, SelLeft = Left + Selection,
ecSelRight = ecRight + ecSelection, SelRight = Right + Selection,
ecSelUp = ecUp + ecSelection, SelUp = Up + Selection,
ecSelDown = ecDown + ecSelection, SelDown = Down + Selection,
ecSelWordLeft = ecWordLeft + ecSelection, SelWordLeft = WordLeft + Selection,
ecSelWordRight = ecWordRight + ecSelection, SelWordRight = WordRight + Selection,
ecSelLineStart = ecLineStart + ecSelection, SelLineStart = LineStart + Selection,
ecSelLineEnd = ecLineEnd + ecSelection, SelLineEnd = LineEnd + Selection,
ecSelPageUp = ecPageUp + ecSelection, SelPageUp = PageUp + Selection,
ecSelPageDown = ecPageDown + ecSelection, SelPageDown = PageDown + Selection,
ecSelPageLeft = ecPageLeft + ecSelection, SelPageLeft = PageLeft + Selection,
ecSelPageRight = ecPageRight + ecSelection, SelPageRight = PageRight + Selection,
ecSelPageTop = ecPageTop + ecSelection, SelPageTop = PageTop + Selection,
ecSelPageBottom = ecPageBottom + ecSelection, SelPageBottom = PageBottom + Selection,
ecSelEditorStart = ecEditorStart + ecSelection, SelEditorStart = EditorStart + Selection,
ecSelEditorEnd = ecEditorEnd + ecSelection, SelEditorEnd = EditorEnd + Selection,
ecSelGotoXY = ecGotoXY + ecSelection, // Data = PPoint SelGotoXY = GotoXY + Selection, // Data = PPoint
ecSelBlockStart = ecBlockStart + ecSelection, // Move cursor to begin of scope SelBlockStart = BlockStart + Selection, // Move cursor to begin of scope
ecSelBlockEnd = ecBlockEnd + ecSelection, // Move cursor to end of scope SelBlockEnd = BlockEnd + Selection, // Move cursor to end of scope
ecCopy = 201, // Copy selection to clipboard Copy = 201, // Copy selection to clipboard
ecSelWord = 202, SelWord = 202,
ecSelectAll = 203, // Select entire contents of editor, cursor to end SelectAll = 203, // Select entire contents of editor, cursor to end
ecExpandSelection = 204, // expand selection ExpandSelection = 204, // expand selection
ecShrinkSelection = 205, // shrink selection ShrinkSelection = 205, // shrink selection
ecScrollUp = 211, // Scroll up one line leaving cursor position unchanged. ScrollUp = 211, // Scroll up one line leaving cursor position unchanged.
ecScrollDown = 212, // Scroll down one line leaving cursor position unchanged. ScrollDown = 212, // Scroll down one line leaving cursor position unchanged.
ecScrollLeft = 213, // Scroll left one char leaving cursor position unchanged. ScrollLeft = 213, // Scroll left one char leaving cursor position unchanged.
ecScrollRight = 214, // Scroll right one char leaving cursor position unchanged. ScrollRight = 214, // Scroll right one char leaving cursor position unchanged.
ecInsertMode = 221, // Set insert mode InsertMode = 221, // Set insert mode
ecOverwriteMode = 222, // Set overwrite mode OverwriteMode = 222, // Set overwrite mode
ecToggleMode = 223, // Toggle ins/ovr mode ToggleMode = 223, // Toggle ins/ovr mode
ecNormalSelect = 231, // Normal selection mode NormalSelect = 231, // Normal selection mode
ecColumnSelect = 232, // Column selection mode ColumnSelect = 232, // Column selection mode
ecLineSelect = 233, // Line selection mode LineSelect = 233, // Line selection mode
ecMatchBracket = 250, // Go to matching bracket MatchBracket = 250, // Go to matching bracket
ecContextHelp = 490, // Help on Word, Data = Word ContextHelp = 490, // Help on Word, Data = Word
ecDeleteLastChar = 501, // Delete last char (i.e. backspace key) DeleteLastChar = 501, // Delete last char (i.e. backspace key)
ecDeleteChar = 502, // Delete char at cursor (i.e. delete key) DeleteChar = 502, // Delete char at cursor (i.e. delete key)
ecDeleteWordEnd = 503, // Delete from cursor to end of word DeleteWordEnd = 503, // Delete from cursor to end of word
ecDeleteWordStart = 504, // Delete from cursor to start of word DeleteWordStart = 504, // Delete from cursor to start of word
ecDeleteBOL = 505, // Delete from cursor to beginning of line DeleteBOL = 505, // Delete from cursor to beginning of line
ecDeleteEOL = 506, // Delete from cursor to end of line DeleteEOL = 506, // Delete from cursor to end of line
ecDeleteLine = 507, // Delete current line DeleteLine = 507, // Delete current line
ecClearAll = 508, // Delete everything ClearAll = 508, // Delete everything
ecLineBreak = 509, // Break line at current position, move caret to new line LineBreak = 509, // Break line at current position, move caret to new line
ecInsertLine = 510, // Break line at current position, leave caret InsertLine = 510, // Break line at current position, leave caret
ecChar = 511, // Insert a character at current position Char = 511, // Insert a character at current position
ecDuplicateLine = 512, // Duplicate current line DuplicateLine = 512, // Duplicate current line
ecMoveSelUp = 513, // Move selection up MoveSelUp = 513, // Move selection up
ecMoveSelDown = 514, // Move selection down MoveSelDown = 514, // Move selection down
ecImeStr = 550, // Insert character(s) from IME ImeStr = 550, // Insert character(s) from IME
ecDeleteWord = 551, // Delete current Word DeleteWord = 551, // Delete current Word
ecUndo = 601, // Perform undo if available Undo = 601, // Perform undo if available
ecRedo = 602, // Perform redo if available Redo = 602, // Perform redo if available
ecCut = 603, // Cut selection to clipboard Cut = 603, // Cut selection to clipboard
ecPaste = 604, // Paste clipboard to current position Paste = 604, // Paste clipboard to current position
ecBlockIndent = 610, // Indent selection BlockIndent = 610, // Indent selection
ecBlockUnindent = 611, // Unindent selection BlockUnindent = 611, // Unindent selection
ecTab = 612, // Tab key Tab = 612, // Tab key
ecShiftTab = 613, // Shift+Tab key ShiftTab = 613, // Shift+Tab key
ecComment = 614, Comment = 614,
ecUncomment = 615, Uncomment = 615,
ecToggleComment = 616, ToggleComment = 616,
ecToggleBlockComment = 617, ToggleBlockComment = 617,
ecUpperCase = 620, // apply to the current or previous word UpperCase = 620, // apply to the current or previous word
ecLowerCase = 621, LowerCase = 621,
ecToggleCase = 622, ToggleCase = 622,
ecTitleCase = 623, TitleCase = 623,
ecUpperCaseBlock = 625, // apply to current selection, or current char if no selection UpperCaseBlock = 625, // apply to current selection, or current char if no selection
ecLowerCaseBlock = 626, LowerCaseBlock = 626,
ecToggleCaseBlock = 627, ToggleCaseBlock = 627,
ecString = 630, //Insert a whole string String = 630, //Insert a whole string
ecZoomOut = 631, //Increase Font Size ZoomOut = 631, //Increase Font Size
ecZoomIn = 632, //Decrease Font Size ZoomIn = 632, //Decrease Font Size
ecLineBreakAtBegin = 651, //add a line break at the begin of the line LineBreakAtBegin = 651, //add a line break at the begin of the line
ecLineBreakAtEnd = 652, LineBreakAtEnd = 652,
TrimTrailingSpaces = 653,
//### Code Folding ### //### Code Folding ###
ecCollapse = 700, Collapse = 700,
ecUncollapse = 701, Uncollapse = 701,
ecCollapseLevel = 702, CollapseLevel = 702,
ecUncollapseLevel = 703, UncollapseLevel = 703,
ecCollapseAll = 704, CollapseAll = 704,
ecUncollapseAll = 705, UncollapseAll = 705,
//### End Code Folding ### //### End Code Folding ###
ecUserFirst = 1001, // Start of user-defined commands UserFirst = 1001, // Start of user-defined commands
}; };
class KeyError: public BaseError { class KeyError: public BaseError {

View File

@ -462,6 +462,65 @@ void SynEdit::addSelectionToUndo()
mBlockEnd,QStringList(),mActiveSelectionMode); mBlockEnd,QStringList(),mActiveSelectionMode);
} }
void SynEdit::doTrimTrailingSpaces()
{
if (mDocument->count()<=0)
return;
if (mSyntaxer) {
for (int i=0;i<mDocument->count();i++) {
if (mDocument->ranges(i).hasTrailingSpaces) {
int line = i+1;
QString oldLine = mDocument->getString(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->getString(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();
}
void SynEdit::beginUpdate() void SynEdit::beginUpdate()
{ {
incPaintLock(); incPaintLock();
@ -2025,8 +2084,6 @@ void SynEdit::doDeleteLastChar()
internalSetCaretX(mDocument->getString(mCaretY - 1).length() + 1); internalSetCaretX(mDocument->getString(mCaretY - 1).length() + 1);
mDocument->deleteAt(mCaretY); mDocument->deleteAt(mCaretY);
doLinesDeleted(mCaretY+1, 1); doLinesDeleted(mCaretY+1, 1);
if (mOptions.testFlag(eoTrimTrailingSpaces))
Temp = trimRight(Temp);
setLineText(lineText() + Temp); setLineText(lineText() + Temp);
helper.append(""); helper.append("");
helper.append(""); helper.append("");
@ -3021,18 +3078,8 @@ void SynEdit::doCopyToClipboard()
bool selected=selAvail(); bool selected=selAvail();
if (!selected) if (!selected)
doSelecteLine(); doSelecteLine();
bool ChangeTrim = (mActiveSelectionMode == SelectionMode::Column) &&
mOptions.testFlag(eoTrimTrailingSpaces);
QString sText; QString sText;
{ sText = selText();
auto action = finally([&,this] {
if (ChangeTrim)
mOptions.setFlag(eoTrimTrailingSpaces);
});
if (ChangeTrim)
mOptions.setFlag(eoTrimTrailingSpaces,false);
sText = selText();
}
internalDoCopyToClipboard(sText); internalDoCopyToClipboard(sText);
if (!selected) { if (!selected) {
setBlockBegin(caretXY()); setBlockBegin(caretXY());
@ -3867,7 +3914,7 @@ EditCommand SynEdit::TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers)
{ {
PEditKeyStroke keyStroke = mKeyStrokes.findKeycode2(mLastKey,mLastKeyModifiers, PEditKeyStroke keyStroke = mKeyStrokes.findKeycode2(mLastKey,mLastKeyModifiers,
key, modifiers); key, modifiers);
EditCommand cmd=EditCommand::ecNone; EditCommand cmd=EditCommand::None;
if (keyStroke) if (keyStroke)
cmd = keyStroke->command(); cmd = keyStroke->command();
else { else {
@ -3875,7 +3922,7 @@ EditCommand SynEdit::TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers)
if (keyStroke) if (keyStroke)
cmd = keyStroke->command(); cmd = keyStroke->command();
} }
if (cmd == EditCommand::ecNone) { if (cmd == EditCommand::None) {
mLastKey = key; mLastKey = key;
mLastKeyModifiers = modifiers; mLastKeyModifiers = modifiers;
} else { } else {
@ -4147,9 +4194,9 @@ void SynEdit::setOptions(const EditorOptions &Value)
//if (!mOptions.testFlag(eoScrollPastEof)) //if (!mOptions.testFlag(eoScrollPastEof))
setTopLine(mTopLine); setTopLine(mTopLine);
bool bUpdateAll = Value.testFlag(eoShowSpecialChars) != mOptions.testFlag(eoShowSpecialChars); bool bUpdateAll =
if (!bUpdateAll) (Value.testFlag(eoShowSpecialChars) != mOptions.testFlag(eoShowSpecialChars))
bUpdateAll = Value.testFlag(eoShowRainbowColor) != mOptions.testFlag(eoShowRainbowColor); || (Value.testFlag(eoShowRainbowColor) != mOptions.testFlag(eoShowRainbowColor));
//bool bUpdateScroll = (Options * ScrollOptions)<>(Value * ScrollOptions); //bool bUpdateScroll = (Options * ScrollOptions)<>(Value * ScrollOptions);
bool bUpdateScroll = true; bool bUpdateScroll = true;
mOptions = Value; mOptions = Value;
@ -4525,7 +4572,7 @@ void SynEdit::doRedoItem()
item->changeEndPos(),item->changeText(), item->changeEndPos(),item->changeText(),
item->changeSelMode(),item->changeNumber()); item->changeSelMode(),item->changeNumber());
setCaretAndSelection(CaretPt, CaretPt, CaretPt); setCaretAndSelection(CaretPt, CaretPt, CaretPt);
commandProcessor(EditCommand::ecLineBreak); processCommand(EditCommand::LineBreak);
break; break;
} }
default: default:
@ -4791,11 +4838,11 @@ bool SynEdit::empty()
return mDocument->empty(); return mDocument->empty();
} }
void SynEdit::commandProcessor(EditCommand Command, QChar AChar, void *pData) void SynEdit::processCommand(EditCommand Command, QChar AChar, void *pData)
{ {
// first the program event handler gets a chance to process the command // first the program event handler gets a chance to process the command
onProcessCommand(Command, AChar, pData); onProcessCommand(Command, AChar, pData);
if (Command != EditCommand::ecNone) if (Command != EditCommand::None)
executeCommand(Command, AChar, pData); executeCommand(Command, AChar, pData);
onCommandProcessed(Command, AChar, pData); onCommandProcessed(Command, AChar, pData);
} }
@ -5306,11 +5353,7 @@ void SynEdit::doLinesInserted(int firstLine, int count)
void SynEdit::properSetLine(int ALine, const QString &ALineText, bool notify) void SynEdit::properSetLine(int ALine, const QString &ALineText, bool notify)
{ {
if (mOptions.testFlag(eoTrimTrailingSpaces)) { mDocument->putString(ALine,ALineText,notify);
mDocument->putString(ALine,trimRight(ALineText),notify);
} else {
mDocument->putString(ALine,ALineText,notify);
}
} }
void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionMode mode)
@ -5520,10 +5563,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
if (bChangeScroll) if (bChangeScroll)
mOptions.setFlag(eoScrollPastEol,false); mOptions.setFlag(eoScrollPastEol,false);
}); });
if (mOptions.testFlag(eoTrimTrailingSpaces) && (sRightSide == "")) { newPos=BufferCoord{str.length() - sRightSide.length()+1,caretY};
newPos=BufferCoord{mDocument->getString(caretY-1).length()+1,caretY};
} else
newPos=BufferCoord{str.length() - sRightSide.length()+1,caretY};
onLinesPutted(startLine-1,result+1); onLinesPutted(startLine-1,result+1);
if (!mUndoing) { if (!mUndoing) {
mUndoList->addChange( mUndoList->addChange(
@ -5699,43 +5739,43 @@ void SynEdit::executeCommand(EditCommand command, QChar ch, void *pData)
}); });
switch(command) { switch(command) {
//horizontal caret movement or selection //horizontal caret movement or selection
case EditCommand::ecLeft: case EditCommand::Left:
case EditCommand::ecSelLeft: case EditCommand::SelLeft:
moveCaretHorz(-1, command == EditCommand::ecSelLeft); moveCaretHorz(-1, command == EditCommand::SelLeft);
break; break;
case EditCommand::ecRight: case EditCommand::Right:
case EditCommand::ecSelRight: case EditCommand::SelRight:
moveCaretHorz(1, command == EditCommand::ecSelRight); moveCaretHorz(1, command == EditCommand::SelRight);
break; break;
case EditCommand::ecPageLeft: case EditCommand::PageLeft:
case EditCommand::ecSelPageLeft: case EditCommand::SelPageLeft:
moveCaretHorz(-mCharsInWindow, command == EditCommand::ecSelPageLeft); moveCaretHorz(-mCharsInWindow, command == EditCommand::SelPageLeft);
break; break;
case EditCommand::ecPageRight: case EditCommand::PageRight:
case EditCommand::ecSelPageRight: case EditCommand::SelPageRight:
moveCaretHorz(mCharsInWindow, command == EditCommand::ecSelPageRight); moveCaretHorz(mCharsInWindow, command == EditCommand::SelPageRight);
break; break;
case EditCommand::ecLineStart: case EditCommand::LineStart:
case EditCommand::ecSelLineStart: case EditCommand::SelLineStart:
moveCaretToLineStart(command == EditCommand::ecSelLineStart); moveCaretToLineStart(command == EditCommand::SelLineStart);
break; break;
case EditCommand::ecLineEnd: case EditCommand::LineEnd:
case EditCommand::ecSelLineEnd: case EditCommand::SelLineEnd:
moveCaretToLineEnd(command == EditCommand::ecSelLineEnd); moveCaretToLineEnd(command == EditCommand::SelLineEnd);
break; break;
// vertical caret movement or selection // vertical caret movement or selection
case EditCommand::ecUp: case EditCommand::Up:
case EditCommand::ecSelUp: case EditCommand::SelUp:
moveCaretVert(-1, command == EditCommand::ecSelUp); moveCaretVert(-1, command == EditCommand::SelUp);
break; break;
case EditCommand::ecDown: case EditCommand::Down:
case EditCommand::ecSelDown: case EditCommand::SelDown:
moveCaretVert(1, command == EditCommand::ecSelDown); moveCaretVert(1, command == EditCommand::SelDown);
break; break;
case EditCommand::ecPageUp: case EditCommand::PageUp:
case EditCommand::ecSelPageUp: case EditCommand::SelPageUp:
case EditCommand::ecPageDown: case EditCommand::PageDown:
case EditCommand::ecSelPageDown: case EditCommand::SelPageDown:
{ {
int counter = mLinesInWindow; int counter = mLinesInWindow;
if (mOptions.testFlag(eoHalfPageScroll)) if (mOptions.testFlag(eoHalfPageScroll))
@ -5745,112 +5785,112 @@ void SynEdit::executeCommand(EditCommand command, QChar ch, void *pData)
} }
if (counter<0) if (counter<0)
break; break;
if (command == EditCommand::ecPageUp || command == EditCommand::ecSelPageUp) { if (command == EditCommand::PageUp || command == EditCommand::SelPageUp) {
counter = -counter; counter = -counter;
} }
moveCaretVert(counter, command == EditCommand::ecSelPageUp || command == EditCommand::ecSelPageDown); moveCaretVert(counter, command == EditCommand::SelPageUp || command == EditCommand::SelPageDown);
break; break;
} }
case EditCommand::ecPageTop: case EditCommand::PageTop:
case EditCommand::ecSelPageTop: case EditCommand::SelPageTop:
moveCaretVert(mTopLine-mCaretY, command == EditCommand::ecSelPageTop); moveCaretVert(mTopLine-mCaretY, command == EditCommand::SelPageTop);
break; break;
case EditCommand::ecPageBottom: case EditCommand::PageBottom:
case EditCommand::ecSelPageBottom: case EditCommand::SelPageBottom:
moveCaretVert(mTopLine+mLinesInWindow-1-mCaretY, command == EditCommand::ecSelPageBottom); moveCaretVert(mTopLine+mLinesInWindow-1-mCaretY, command == EditCommand::SelPageBottom);
break; break;
case EditCommand::ecEditorStart: case EditCommand::EditorStart:
case EditCommand::ecSelEditorStart: case EditCommand::SelEditorStart:
doGotoEditorStart(command == EditCommand::ecSelEditorStart); doGotoEditorStart(command == EditCommand::SelEditorStart);
break; break;
case EditCommand::ecEditorEnd: case EditCommand::EditorEnd:
case EditCommand::ecSelEditorEnd: case EditCommand::SelEditorEnd:
doGotoEditorEnd(command == EditCommand::ecSelEditorEnd); doGotoEditorEnd(command == EditCommand::SelEditorEnd);
break; break;
case EditCommand::ecBlockStart: case EditCommand::BlockStart:
case EditCommand::ecSelBlockStart: case EditCommand::SelBlockStart:
doGotoBlockStart(command == EditCommand::ecSelBlockStart); doGotoBlockStart(command == EditCommand::SelBlockStart);
break; break;
case EditCommand::ecBlockEnd: case EditCommand::BlockEnd:
case EditCommand::ecSelBlockEnd: case EditCommand::SelBlockEnd:
doGotoBlockEnd(command == EditCommand::ecSelBlockEnd); doGotoBlockEnd(command == EditCommand::SelBlockEnd);
break; break;
// goto special line / column position // goto special line / column position
case EditCommand::ecGotoXY: case EditCommand::GotoXY:
case EditCommand::ecSelGotoXY: case EditCommand::SelGotoXY:
if (pData) if (pData)
moveCaretAndSelection(caretXY(), *((BufferCoord *)(pData)), command == EditCommand::ecSelGotoXY); moveCaretAndSelection(caretXY(), *((BufferCoord *)(pData)), command == EditCommand::SelGotoXY);
break; break;
// word selection // word selection
case EditCommand::ecWordLeft: case EditCommand::WordLeft:
case EditCommand::ecSelWordLeft: case EditCommand::SelWordLeft:
{ {
BufferCoord CaretNew = prevWordPos(); BufferCoord CaretNew = prevWordPos();
moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::ecSelWordLeft); moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::SelWordLeft);
break; break;
} }
case EditCommand::ecWordRight: case EditCommand::WordRight:
case EditCommand::ecSelWordRight: case EditCommand::SelWordRight:
{ {
BufferCoord CaretNew = nextWordPos(); BufferCoord CaretNew = nextWordPos();
moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::ecSelWordRight); moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::SelWordRight);
break; break;
} }
case EditCommand::ecSelWord: case EditCommand::SelWord:
setSelWord(); setSelWord();
break; break;
case EditCommand::ecSelectAll: case EditCommand::SelectAll:
doSelectAll(); doSelectAll();
break; break;
case EditCommand::ecExpandSelection: case EditCommand::ExpandSelection:
doExpandSelection(caretXY()); doExpandSelection(caretXY());
break; break;
case EditCommand::ecShrinkSelection: case EditCommand::ShrinkSelection:
doShrinkSelection(caretXY()); doShrinkSelection(caretXY());
break; break;
case EditCommand::ecDeleteLastChar: case EditCommand::DeleteLastChar:
doDeleteLastChar(); doDeleteLastChar();
break; break;
case EditCommand::ecDeleteChar: case EditCommand::DeleteChar:
doDeleteCurrentChar(); doDeleteCurrentChar();
break; break;
case EditCommand::ecDeleteWord: case EditCommand::DeleteWord:
doDeleteWord(); doDeleteWord();
break; break;
case EditCommand::ecDeleteEOL: case EditCommand::DeleteEOL:
doDeleteToEOL(); doDeleteToEOL();
break; break;
case EditCommand::ecDeleteWordStart: case EditCommand::DeleteWordStart:
doDeleteToWordStart(); doDeleteToWordStart();
break; break;
case EditCommand::ecDeleteWordEnd: case EditCommand::DeleteWordEnd:
doDeleteToWordEnd(); doDeleteToWordEnd();
break; break;
case EditCommand::ecDeleteBOL: case EditCommand::DeleteBOL:
doDeleteFromBOL(); doDeleteFromBOL();
break; break;
case EditCommand::ecDeleteLine: case EditCommand::DeleteLine:
doDeleteLine(); doDeleteLine();
break; break;
case EditCommand::ecDuplicateLine: case EditCommand::DuplicateLine:
doDuplicateLine(); doDuplicateLine();
break; break;
case EditCommand::ecMoveSelUp: case EditCommand::MoveSelUp:
doMoveSelUp(); doMoveSelUp();
break; break;
case EditCommand::ecMoveSelDown: case EditCommand::MoveSelDown:
doMoveSelDown(); doMoveSelDown();
break; break;
case EditCommand::ecClearAll: case EditCommand::ClearAll:
clearAll(); clearAll();
break; break;
case EditCommand::ecInsertLine: case EditCommand::InsertLine:
insertLine(false); insertLine(false);
break; break;
case EditCommand::ecLineBreak: case EditCommand::LineBreak:
insertLine(true); insertLine(true);
break; break;
case EditCommand::ecLineBreakAtEnd: case EditCommand::LineBreakAtEnd:
mUndoList->beginBlock(); mUndoList->beginBlock();
addCaretToUndo(); addCaretToUndo();
addSelectionToUndo(); addSelectionToUndo();
@ -5858,98 +5898,102 @@ void SynEdit::executeCommand(EditCommand command, QChar ch, void *pData)
insertLine(true); insertLine(true);
mUndoList->endBlock(); mUndoList->endBlock();
break; break;
case EditCommand::ecTab: case EditCommand::Tab:
doTabKey(); doTabKey();
break; break;
case EditCommand::ecShiftTab: case EditCommand::ShiftTab:
doShiftTabKey(); doShiftTabKey();
break; break;
case EditCommand::ecChar: case EditCommand::Char:
doAddChar(ch); doAddChar(ch);
break; break;
case EditCommand::ecInsertMode: case EditCommand::InsertMode:
if (!mReadOnly) if (!mReadOnly)
setInsertMode(true); setInsertMode(true);
break; break;
case EditCommand::ecOverwriteMode: case EditCommand::OverwriteMode:
if (!mReadOnly) if (!mReadOnly)
setInsertMode(false); setInsertMode(false);
break; break;
case EditCommand::ecToggleMode: case EditCommand::ToggleMode:
if (!mReadOnly) { if (!mReadOnly) {
setInsertMode(!mInserting); setInsertMode(!mInserting);
} }
break; break;
case EditCommand::ecCut: case EditCommand::Cut:
if (!mReadOnly) if (!mReadOnly)
doCutToClipboard(); doCutToClipboard();
break; break;
case EditCommand::ecCopy: case EditCommand::Copy:
doCopyToClipboard(); doCopyToClipboard();
break; break;
case EditCommand::ecPaste: case EditCommand::Paste:
if (!mReadOnly) if (!mReadOnly)
doPasteFromClipboard(); doPasteFromClipboard();
break; break;
case EditCommand::ecImeStr: case EditCommand::ImeStr:
case EditCommand::ecString: case EditCommand::String:
if (!mReadOnly) if (!mReadOnly)
doAddStr(*((QString*)pData)); doAddStr(*((QString*)pData));
break; break;
case EditCommand::ecUndo: case EditCommand::Undo:
if (!mReadOnly) if (!mReadOnly)
doUndo(); doUndo();
break; break;
case EditCommand::ecRedo: case EditCommand::Redo:
if (!mReadOnly) if (!mReadOnly)
doRedo(); doRedo();
break; break;
case EditCommand::ecZoomIn: case EditCommand::ZoomIn:
doZoomIn(); doZoomIn();
break; break;
case EditCommand::ecZoomOut: case EditCommand::ZoomOut:
doZoomOut(); doZoomOut();
break; break;
case EditCommand::ecComment: case EditCommand::Comment:
doComment(); doComment();
break; break;
case EditCommand::ecUncomment: case EditCommand::Uncomment:
doUncomment(); doUncomment();
break; break;
case EditCommand::ecToggleComment: case EditCommand::ToggleComment:
doToggleComment(); doToggleComment();
break; break;
case EditCommand::ecToggleBlockComment: case EditCommand::ToggleBlockComment:
doToggleBlockComment(); doToggleBlockComment();
break; break;
case EditCommand::ecNormalSelect: case EditCommand::NormalSelect:
setSelectionMode(SelectionMode::Normal); setSelectionMode(SelectionMode::Normal);
break; break;
case EditCommand::ecLineSelect: case EditCommand::LineSelect:
setSelectionMode(SelectionMode::Line); setSelectionMode(SelectionMode::Line);
break; break;
case EditCommand::ecColumnSelect: case EditCommand::ColumnSelect:
setSelectionMode(SelectionMode::Column); setSelectionMode(SelectionMode::Column);
break; break;
case EditCommand::ecScrollLeft: case EditCommand::ScrollLeft:
horizontalScrollBar()->setValue(horizontalScrollBar()->value()-mMouseWheelScrollSpeed); horizontalScrollBar()->setValue(horizontalScrollBar()->value()-mMouseWheelScrollSpeed);
break; break;
case EditCommand::ecScrollRight: case EditCommand::ScrollRight:
horizontalScrollBar()->setValue(horizontalScrollBar()->value()+mMouseWheelScrollSpeed); horizontalScrollBar()->setValue(horizontalScrollBar()->value()+mMouseWheelScrollSpeed);
break; break;
case EditCommand::ecScrollUp: case EditCommand::ScrollUp:
verticalScrollBar()->setValue(verticalScrollBar()->value()-mMouseWheelScrollSpeed); verticalScrollBar()->setValue(verticalScrollBar()->value()-mMouseWheelScrollSpeed);
break; break;
case EditCommand::ecScrollDown: case EditCommand::ScrollDown:
verticalScrollBar()->setValue(verticalScrollBar()->value()+mMouseWheelScrollSpeed); verticalScrollBar()->setValue(verticalScrollBar()->value()+mMouseWheelScrollSpeed);
break; break;
case EditCommand::ecMatchBracket: case EditCommand::MatchBracket:
{ {
BufferCoord coord = getMatchingBracket(); BufferCoord coord = getMatchingBracket();
if (coord.ch!=0 && coord.line!=0) if (coord.ch!=0 && coord.line!=0)
internalSetCaretXY(coord); internalSetCaretXY(coord);
} }
break; break;
case EditCommand::TrimTrailingSpaces:
if (!mReadOnly)
doTrimTrailingSpaces();
break;
default: default:
break; break;
} }
@ -6169,13 +6213,13 @@ void SynEdit::keyPressEvent(QKeyEvent *event)
event->accept(); event->accept();
} else { } else {
EditCommand cmd=TranslateKeyCode(event->key(),event->modifiers()); EditCommand cmd=TranslateKeyCode(event->key(),event->modifiers());
if (cmd!=EditCommand::ecNone) { if (cmd!=EditCommand::None) {
commandProcessor(cmd,QChar(),nullptr); processCommand(cmd,QChar(),nullptr);
event->accept(); event->accept();
} else if (!event->text().isEmpty()) { } else if (!event->text().isEmpty()) {
QChar c = event->text().at(0); QChar c = event->text().at(0);
if (c=='\t' || c.isPrint()) { if (c=='\t' || c.isPrint()) {
commandProcessor(EditCommand::ecChar,c,nullptr); processCommand(EditCommand::Char,c,nullptr);
event->accept(); event->accept();
} }
} }
@ -6306,8 +6350,9 @@ void SynEdit::mouseDoubleClickEvent(QMouseEvent *event)
QAbstractScrollArea::mouseDoubleClickEvent(event); QAbstractScrollArea::mouseDoubleClickEvent(event);
QPoint ptMouse = event->pos(); QPoint ptMouse = event->pos();
if (ptMouse.x() >= mGutterWidth + 2) { if (ptMouse.x() >= mGutterWidth + 2) {
setSelWord(); if (mOptions.testFlag(EditorOption::eoSelectWordByDblClick))
mStateFlags.setFlag(StateFlag::sfDblClicked); setSelWord();
mStateFlags.setFlag(StateFlag::sfDblClicked);
} }
} }
@ -6328,7 +6373,7 @@ void SynEdit::inputMethodEvent(QInputMethodEvent *event)
} }
QString s = event->commitString(); QString s = event->commitString();
if (!s.isEmpty()) { if (!s.isEmpty()) {
commandProcessor(EditCommand::ecImeStr,QChar(),&s); processCommand(EditCommand::ImeStr,QChar(),&s);
// for (QChar ch:s) { // for (QChar ch:s) {
// CommandProcessor(SynEditorCommand::ecChar,ch); // CommandProcessor(SynEditorCommand::ecChar,ch);
// } // }

View File

@ -74,36 +74,27 @@ Q_DECLARE_FLAGS(StateFlags,StateFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(StateFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(StateFlags)
enum EditorOption { enum EditorOption {
eoAltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format eoAltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format
eoAutoIndent = 0x00000002, //Will auto calculate the indent when input eoAutoIndent = 0x00000002, //Will auto calculate the indent when input
eoLigatureSupport = 0x00000004, //Support ligaures in fonts like fira code eoLigatureSupport = 0x00000004, //Support ligaures in fonts like fira code
eoDragDropEditing = 0x00000008, //Allows you to select a block of text and drag it within the document to another location eoDragDropEditing = 0x00000008, //Allows you to select a block of text and drag it within the document to another location
eoDropFiles = 0x00000010, //Allows the editor accept OLE file drops eoDropFiles = 0x00000010, //Allows the editor accept OLE file drops
eoEnhanceHomeKey = 0x00000020, //enhances home key positioning, similar to visual studio eoEnhanceHomeKey = 0x00000020, //enhances home key positioning, similar to visual studio
eoEnhanceEndKey = 0x00000040, //enhances End key positioning, similar to JDeveloper eoEnhanceEndKey = 0x00000040, //enhances End key positioning, similar to JDeveloper
eoGroupUndo = 0x00000080, //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately eoGroupUndo = 0x00000080, //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately
eoHalfPageScroll = 0x00000100, //When scrolling with page-up and page-down commands, only scroll a half page at a time eoHalfPageScroll = 0x00000100, //When scrolling with page-up and page-down commands, only scroll a half page at a time
eoHideShowScrollbars =0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead) eoHideShowScrollbars = 0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead)
eoKeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor eoKeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor
eoRightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location eoRightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location
eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less
eoScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker eoScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker
eoScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line eoScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line
eoShowSpecialChars = 0x00008000, //Shows the special Characters eoShowSpecialChars = 0x00008000, //Shows the special Characters
// eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event // eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event
eoTabIndent = 0x00020000, //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected eoTabIndent = 0x00020000, //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected
eoTabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters eoTabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters
eoShowRainbowColor = 0x00080000, eoShowRainbowColor = 0x00080000,
eoTrimTrailingSpaces =0x00100000, //Spaces at the end of lines will be trimmed and not saved eoSelectWordByDblClick= 0x00100000,
eoSelectWordByDblClick=0x00200000,
// eoNoSelection = 0x00400000, //Disables selecting text
//eoAutoSizeMaxScrollWidth = 0x00000008, //Automatically resizes the MaxScrollWidth property when inserting text
//eoDisableScrollArrows = 0x00000010 , //Disables the scroll bar arrow buttons when you can't scroll in that direction any more
// eoScrollHintFollows = 0x00020000, //The scroll hint follows the mouse when scrolling vertically
// eoShowScrollHint = 0x00100000, //Shows a hint of the visible line numbers when scrolling vertically
// eoSmartTabDelete = 0x00400000, //similar to Smart Tabs, but when you delete characters
// eoSmartTabs = 0x00800000, //When tabbing, the cursor will go to the next non-white space character of the previous line
// eoNoCaret = 0x00000800, //Makes it so the caret is never visible
}; };
Q_DECLARE_FLAGS(EditorOptions, EditorOption) Q_DECLARE_FLAGS(EditorOptions, EditorOption)
@ -215,7 +206,7 @@ public:
BufferCoord prevWordPos(); BufferCoord prevWordPos();
BufferCoord prevWordPosEx(const BufferCoord& XY); BufferCoord prevWordPosEx(const BufferCoord& XY);
void commandProcessor(EditCommand Command, QChar AChar = QChar(), void * pData = nullptr); void processCommand(EditCommand Command, QChar AChar = QChar(), void * pData = nullptr);
//Caret //Caret
void showCaret(); void showCaret();
void hideCaret(); void hideCaret();
@ -261,28 +252,31 @@ public:
selectAll(); selectAll();
setSelText(text); setSelText(text);
} }
void trimTrailingSpaces() {
processCommand(EditCommand::TrimTrailingSpaces);
}
//Commands //Commands
virtual void cutToClipboard() { commandProcessor(EditCommand::ecCut);} virtual void cutToClipboard() { processCommand(EditCommand::Cut);}
virtual void copyToClipboard() { commandProcessor(EditCommand::ecCopy);} virtual void copyToClipboard() { processCommand(EditCommand::Copy);}
virtual void pasteFromClipboard() { commandProcessor(EditCommand::ecPaste);} virtual void pasteFromClipboard() { processCommand(EditCommand::Paste);}
virtual void undo() { commandProcessor(EditCommand::ecUndo);} virtual void undo() { processCommand(EditCommand::Undo);}
virtual void redo() { commandProcessor(EditCommand::ecRedo);} virtual void redo() { processCommand(EditCommand::Redo);}
virtual void zoomIn() { commandProcessor(EditCommand::ecZoomIn);} virtual void zoomIn() { processCommand(EditCommand::ZoomIn);}
virtual void zoomOut() { commandProcessor(EditCommand::ecZoomOut);} virtual void zoomOut() { processCommand(EditCommand::ZoomOut);}
virtual void selectAll() { virtual void selectAll() {
commandProcessor(EditCommand::ecSelectAll); processCommand(EditCommand::SelectAll);
} }
virtual void selectWord() { virtual void selectWord() {
commandProcessor(EditCommand::ecSelWord); processCommand(EditCommand::SelWord);
} }
virtual void tab() { commandProcessor(EditCommand::ecTab);} virtual void tab() { processCommand(EditCommand::Tab);}
virtual void shifttab() { commandProcessor(EditCommand::ecShiftTab);} virtual void shifttab() { processCommand(EditCommand::ShiftTab);}
virtual void toggleComment() { commandProcessor(EditCommand::ecToggleComment);} virtual void toggleComment() { processCommand(EditCommand::ToggleComment);}
virtual void toggleBlockComment() { commandProcessor(EditCommand::ecToggleBlockComment);} virtual void toggleBlockComment() { processCommand(EditCommand::ToggleBlockComment);}
virtual void matchBracket() { commandProcessor(EditCommand::ecMatchBracket);} virtual void matchBracket() { processCommand(EditCommand::MatchBracket);}
virtual void moveSelUp(){ commandProcessor(EditCommand::ecMoveSelUp);} virtual void moveSelUp(){ processCommand(EditCommand::MoveSelUp);}
virtual void moveSelDown(){ commandProcessor(EditCommand::ecMoveSelDown);} virtual void moveSelDown(){ processCommand(EditCommand::MoveSelDown);}
virtual void beginUpdate(); virtual void beginUpdate();
virtual void endUpdate(); virtual void endUpdate();
@ -555,6 +549,7 @@ private:
int doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos, int startLine, int endLine); int doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos, int startLine, int endLine);
int doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos); int doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
void doTrimTrailingSpaces();
void deleteFromTo(const BufferCoord& start, const BufferCoord& end); void deleteFromTo(const BufferCoord& start, const BufferCoord& end);
void setSelWord(); void setSelWord();
void setWordBlock(BufferCoord value); void setWordBlock(BufferCoord value);

View File

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

View File

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

View File

@ -242,6 +242,8 @@ void ASMSyntaxer::SpaceProc()
if (mLine[mRun] > 32) if (mLine[mRun] > 32)
break; break;
} }
if (mRun>=mStringLen)
mHasTrailingSpaces = true;
} }
void ASMSyntaxer::StringProc() void ASMSyntaxer::StringProc()
@ -441,17 +443,19 @@ bool ASMSyntaxer::isLastLineStringNotFinished(int /*state*/) const
SyntaxerState ASMSyntaxer::getState() const SyntaxerState ASMSyntaxer::getState() const
{ {
return SyntaxerState(); SyntaxerState state;
state.hasTrailingSpaces = mHasTrailingSpaces;
return state;
} }
void ASMSyntaxer::setState(const SyntaxerState&) void ASMSyntaxer::setState(const SyntaxerState&)
{ {
mHasTrailingSpaces = false;
} }
void ASMSyntaxer::resetState() void ASMSyntaxer::resetState()
{ {
mHasTrailingSpaces = false;
} }
QSet<QString> ASMSyntaxer::keywords() const QSet<QString> ASMSyntaxer::keywords() const

View File

@ -61,6 +61,7 @@ private:
QChar mToIdent; QChar mToIdent;
int mTokenPos; int mTokenPos;
TokenId mTokenID; TokenId mTokenID;
bool mHasTrailingSpaces;
PTokenAttribute mNumberAttribute; PTokenAttribute mNumberAttribute;
PTokenAttribute mDirectiveAttribute; PTokenAttribute mDirectiveAttribute;
PTokenAttribute mRegisterAttribute; PTokenAttribute mRegisterAttribute;

View File

@ -290,20 +290,17 @@ void CppSyntaxer::andSymbolProc()
void CppSyntaxer::ansiCppProc() void CppSyntaxer::ansiCppProc()
{ {
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
if (mRun>=mLineSize) {
nullProc();
if ( (mRun-1<0) || (mLine[mRun-1]!='\\')) {
mRange.state = RangeState::rsUnknown;
}
return;
}
while (mRun<mLineSize) { while (mRun<mLineSize) {
mRun+=1; if (isSpaceChar(mLine[mRun]))
break;
mRun++;
} }
mRange.state = RangeState::rsCppCommentEnded; if (mRun<mLineSize) {
if (mRun == mLineSize-1 && mLine[mRun-1] == '\\' ) { // continues on next line
mRange.state = RangeState::rsCppComment; mRange.state = RangeState::rsCppComment;
} } else if (mRun-1>=0 && mLine[mRun-1] == '\\' ) { // continues on next line
mRange.state = RangeState::rsCppComment;
} else
mRange.state = RangeState::rsUnknown;
} }
void CppSyntaxer::ansiCProc() void CppSyntaxer::ansiCProc()
@ -316,6 +313,9 @@ void CppSyntaxer::ansiCProc()
} }
while (mRun<mLineSize) { while (mRun<mLineSize) {
switch(mLine[mRun].unicode()) { switch(mLine[mRun].unicode()) {
case ' ':
case '\t':
return;
case '*': case '*':
if (mRun+1<mLineSize && mLine[mRun+1] == '/') { if (mRun+1<mLineSize && mLine[mRun+1] == '/') {
mRun += 2; mRun += 2;
@ -449,10 +449,7 @@ void CppSyntaxer::directiveProc()
mRun+=1; mRun+=1;
} }
if (directive == "define") { if (directive == "define") {
while(mRun < mLineSize && isSpaceChar(mLine[mRun]))
mRun++;
mRange.state = RangeState::rsDefineIdentifier; mRange.state = RangeState::rsDefineIdentifier;
return;
} else } else
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
@ -460,6 +457,7 @@ void CppSyntaxer::directiveProc()
void CppSyntaxer::defineIdentProc() void CppSyntaxer::defineIdentProc()
{ {
mTokenId = TokenId::Identifier; mTokenId = TokenId::Identifier;
while(mRun < mLineSize && isIdentChar(mLine[mRun])) while(mRun < mLineSize && isIdentChar(mLine[mRun]))
mRun++; mRun++;
mRange.state = RangeState::rsDefineRemaining; mRange.state = RangeState::rsDefineRemaining;
@ -468,8 +466,11 @@ void CppSyntaxer::defineIdentProc()
void CppSyntaxer::defineRemainingProc() void CppSyntaxer::defineRemainingProc()
{ {
mTokenId = TokenId::Directive; mTokenId = TokenId::Directive;
do { while (mRun<mLineSize) {
switch(mLine[mRun].unicode()) { switch(mLine[mRun].unicode()) {
case ' ':
case '\t':
return;
case '/': //comment? case '/': //comment?
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
switch (mLine[mRun+1].unicode()) { switch (mLine[mRun+1].unicode()) {
@ -491,7 +492,7 @@ void CppSyntaxer::defineRemainingProc()
break; break;
} }
mRun+=1; mRun+=1;
} while (mRun<mLineSize); }
mRange.state=RangeState::rsUnknown; mRange.state=RangeState::rsUnknown;
} }
@ -642,18 +643,7 @@ void CppSyntaxer::notSymbolProc()
void CppSyntaxer::nullProc() void CppSyntaxer::nullProc()
{ {
if ( mTokenId = TokenId::Null;
(mRange.state == RangeState::rsCppComment
|| mRange.state == RangeState::rsDirective
|| mRange.state == RangeState::rsString
|| mRange.state == RangeState::rsMultiLineString
|| mRange.state == RangeState::rsMultiLineDirective)
&& (mRun-1>=0)
&& (mRun-1<mLineSize)
&& isSpaceChar(mLine[mRun-1]) ) {
mRange.state = RangeState::rsUnknown;
} else
mTokenId = TokenId::Null;
} }
void CppSyntaxer::numberProc() void CppSyntaxer::numberProc()
@ -882,22 +872,24 @@ void CppSyntaxer::questionProc()
void CppSyntaxer::rawStringProc() void CppSyntaxer::rawStringProc()
{ {
bool noEscaping = false; bool noEscaping = false;
if (mRange.state == RangeState::rsRawStringNotEscaping)
noEscaping = true;
mTokenId = TokenId::RawString; mTokenId = TokenId::RawString;
mRange.state = RangeState::rsRawString;
while (mRun<mLineSize) { while (mRun<mLineSize) {
if ((!noEscaping) && (mLine[mRun]=='"')) { if (!noEscaping && (mLine[mRun]=='"')) {
mRun+=1; mRun+=1;
break; break;
} }
switch (mLine[mRun].unicode()) { switch (mLine[mRun].unicode()) {
case ' ':
case '\t':
return;
case '(': case '(':
noEscaping = true; if (!noEscaping)
noEscaping = true;
break; break;
case ')': case ')':
noEscaping = false; if (noEscaping)
noEscaping = false;
break; break;
} }
mRun+=1; mRun+=1;
@ -984,7 +976,8 @@ void CppSyntaxer::spaceProc()
mTokenId = TokenId::Space; mTokenId = TokenId::Space;
while (mRun<mLineSize && mLine[mRun]>=1 && mLine[mRun]<=32) while (mRun<mLineSize && mLine[mRun]>=1 && mLine[mRun]<=32)
mRun+=1; mRun+=1;
mRange.state = RangeState::rsUnknown; if (mRun>=mLineSize)
mRange.hasTrailingSpaces = true;
} }
void CppSyntaxer::squareCloseProc() void CppSyntaxer::squareCloseProc()
@ -1015,60 +1008,62 @@ void CppSyntaxer::starProc()
} }
} }
void CppSyntaxer::stringEndProc() //void CppSyntaxer::stringEndProc()
{ //{
mTokenId = TokenId::String; // mTokenId = TokenId::String;
if (mRun>=mLineSize) { // if (mRun>=mLineSize) {
nullProc(); // nullProc();
return; // return;
} // }
mRange.state = RangeState::rsUnknown; // mRange.state = RangeState::rsUnknown;
while (mRun<mLineSize) { // while (mRun<mLineSize) {
if (mLine[mRun]=='"') { // if (mLine[mRun]=='"') {
mRun += 1; // mRun += 1;
break; // break;
} // } else if (isSpaceChar(mLine[mRun])) {
if (mLine[mRun]=='\\') { // mRange.state = RangeState::rsString;
if (mRun == mLineSize-1) { // return;
mRun+=1; // } else if (mLine[mRun]=='\\') {
mRange.state = RangeState::rsMultiLineString; // if (mRun == mLineSize-1) {
return; // mRun+=1;
} // mRange.state = RangeState::rsMultiLineString;
if (mRun+1<mLineSize) { // return;
switch(mLine[mRun+1].unicode()) { // }
case '\'': // if (mRun+1<mLineSize) {
case '"': // switch(mLine[mRun+1].unicode()) {
case '\\': // case '\'':
case '?': // case '"':
case 'a': // case '\\':
case 'b': // case '?':
case 'f': // case 'a':
case 'n': // case 'b':
case 'r': // case 'f':
case 't': // case 'n':
case 'v': // case 'r':
case '0': // case 't':
case '1': // case 'v':
case '2': // case '0':
case '3': // case '1':
case '4': // case '2':
case '5': // case '3':
case '6': // case '4':
case '7': // case '5':
case '8': // case '6':
case '9': // case '7':
case 'x': // case '8':
case 'u': // case '9':
case 'U': // case 'x':
mRange.state = RangeState::rsMultiLineStringEscapeSeq; // case 'u':
return; // case 'U':
} // mRange.state = RangeState::rsMultiLineStringEscapeSeq;
} // return;
} // }
mRun += 1; // }
} // }
} // mRun += 1;
// }
//}
void CppSyntaxer::stringEscapeSeqProc() void CppSyntaxer::stringEscapeSeqProc()
{ {
@ -1156,10 +1151,7 @@ void CppSyntaxer::stringEscapeSeqProc()
break; break;
} }
} }
if (mRange.state == RangeState::rsMultiLineStringEscapeSeq) mRange.state = RangeState::rsString;
mRange.state = RangeState::rsMultiLineString;
else
mRange.state = RangeState::rsString;
} }
void CppSyntaxer::stringProc() void CppSyntaxer::stringProc()
@ -1169,16 +1161,14 @@ void CppSyntaxer::stringProc()
return; return;
} }
mTokenId = TokenId::String; mTokenId = TokenId::String;
mRange.state = RangeState::rsString;
while (mRun < mLineSize) { while (mRun < mLineSize) {
if (mLine[mRun]=='"') { if (mLine[mRun]=='"') {
mRun+=1; mRun++;
break; break;
} } else if (mLine[mRun]=='\\') {
if (mLine[mRun]=='\\') {
if (mRun == mLineSize-1) { if (mRun == mLineSize-1) {
mRun+=1; mRun++;
mRange.state = RangeState::rsMultiLineString; mRange.state = RangeState::rsString;
return; return;
} }
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
@ -1271,10 +1261,6 @@ void CppSyntaxer::processChar()
case '{': case '{':
braceOpenProc(); braceOpenProc();
break; break;
case '\r':
case '\n':
spaceProc();
break;
case ':': case ':':
colonProc(); colonProc();
break; break;
@ -1362,8 +1348,6 @@ void CppSyntaxer::processChar()
default: default:
if (isIdentChar(mLine[mRun])) { if (isIdentChar(mLine[mRun])) {
identProc(); identProc();
} else if (isSpaceChar(mLine[mRun])) {
spaceProc();
} else { } else {
unknownProc(); unknownProc();
} }
@ -1429,7 +1413,7 @@ bool CppSyntaxer::isLastLineCommentNotFinished(int state) const
bool CppSyntaxer::isLastLineStringNotFinished(int state) const bool CppSyntaxer::isLastLineStringNotFinished(int state) const
{ {
return state == RangeState::rsMultiLineString; return state == RangeState::rsString;
} }
bool CppSyntaxer::eol() const bool CppSyntaxer::eol() const
@ -1493,6 +1477,10 @@ void CppSyntaxer::next()
mAsmStart = false; mAsmStart = false;
mTokenPos = mRun; mTokenPos = mRun;
do { do {
if (mRun<mLineSize && isSpaceChar(mLine[mRun])) {
spaceProc();
break;
}
switch (mRange.state) { switch (mRange.state) {
case RangeState::rsAnsiC: case RangeState::rsAnsiC:
case RangeState::rsAnsiCAsm: case RangeState::rsAnsiCAsm:
@ -1513,17 +1501,11 @@ void CppSyntaxer::next()
//qDebug()<<"*3-0-0*"; //qDebug()<<"*3-0-0*";
directiveEndProc(); directiveEndProc();
break; break;
case RangeState::rsMultiLineString: // case RangeState::rsMultiLineString:
//qDebug()<<"*4-0-0*"; // //qDebug()<<"*4-0-0*";
stringEndProc(); // stringEndProc();
break; // break;
case RangeState::rsRawStringEscaping:
case RangeState::rsRawStringNotEscaping:
//qDebug()<<"*5-0-0*";
rawStringProc();
break;
case RangeState::rsStringEscapeSeq: case RangeState::rsStringEscapeSeq:
case RangeState::rsMultiLineStringEscapeSeq:
//qDebug()<<"*6-0-0*"; //qDebug()<<"*6-0-0*";
stringEscapeSeqProc(); stringEscapeSeqProc();
break; break;
@ -1601,6 +1583,7 @@ void CppSyntaxer::setState(const SyntaxerState& rangeState)
mRange.blockEnded = 0; mRange.blockEnded = 0;
mRange.blockEndedLastLine = 0; mRange.blockEndedLastLine = 0;
mRange.firstIndentThisLine = mRange.indents.length(); mRange.firstIndentThisLine = mRange.indents.length();
mRange.hasTrailingSpaces = false;
mRange.matchingIndents.clear(); mRange.matchingIndents.clear();
} }
@ -1617,6 +1600,7 @@ void CppSyntaxer::resetState()
mRange.indents.clear(); mRange.indents.clear();
mRange.firstIndentThisLine = 0; mRange.firstIndentThisLine = 0;
mRange.matchingIndents.clear(); mRange.matchingIndents.clear();
mRange.hasTrailingSpaces = false;
mAsmStart = false; mAsmStart = false;
} }

View File

@ -48,9 +48,9 @@ class CppSyntaxer: public Syntaxer
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm, rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString, rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
rsMultiLineString, rsMultiLineDirective, rsCppComment, rsMultiLineString, rsMultiLineDirective, rsCppComment,
rsStringEscapeSeq, rsMultiLineStringEscapeSeq, rsStringEscapeSeq,
rsRawString, rsSpace,rsRawStringEscaping,rsRawStringNotEscaping,rsChar, rsRawString, rsSpace,rsRawStringNotEscaping,rsRawStringEnd,rsChar,
rsCppCommentEnded, rsDefineStart, rsDefineIdentifier, rsDefineRemaining rsDefineIdentifier, rsDefineRemaining
}; };
public: public:
@ -124,7 +124,7 @@ private:
void squareCloseProc(); void squareCloseProc();
void squareOpenProc(); void squareOpenProc();
void starProc(); void starProc();
void stringEndProc(); // void stringEndProc();
void stringEscapeSeqProc(); void stringEscapeSeqProc();
void stringProc(); void stringProc();
void stringStartProc(); void stringStartProc();

View File

@ -203,13 +203,7 @@ const PTokenAttribute &GLSLSyntaxer::localVarAttribute() const
GLSLSyntaxer::TokenId GLSLSyntaxer::getTokenId() GLSLSyntaxer::TokenId GLSLSyntaxer::getTokenId()
{ {
if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock) return mTokenId;
&& !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space
|| mTokenId == TokenId::Null)) {
return TokenId::Asm;
} else {
return mTokenId;
}
} }
void GLSLSyntaxer::andSymbolProc() void GLSLSyntaxer::andSymbolProc()
@ -259,11 +253,7 @@ void GLSLSyntaxer::ansiCProc()
case '*': case '*':
if (mLine[mRun+1] == '/') { if (mLine[mRun+1] == '/') {
mRun += 2; mRun += 2;
if (mRange.state == RangeState::rsAnsiCAsm) { if (mRange.state == RangeState::rsDirectiveComment &&
mRange.state = RangeState::rsAsm;
} else if (mRange.state == RangeState::rsAnsiCAsmBlock){
mRange.state = RangeState::rsAsmBlock;
} else if (mRange.state == RangeState::rsDirectiveComment &&
mLine[mRun] != 0 && mLine[mRun]!='\r' && mLine[mRun]!='\n') { mLine[mRun] != 0 && mLine[mRun]!='\r' && mLine[mRun]!='\n') {
mRange.state = RangeState::rsMultiLineDirective; mRange.state = RangeState::rsMultiLineDirective;
} else { } else {
@ -307,10 +297,6 @@ void GLSLSyntaxer::braceCloseProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = rsUnknown;
}
mRange.braceLevel -= 1; mRange.braceLevel -= 1;
mRange.blockLevel -= 1; mRange.blockLevel -= 1;
if (mRange.braceLevel<0) { if (mRange.braceLevel<0) {
@ -329,10 +315,6 @@ void GLSLSyntaxer::braceOpenProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRange.state == RangeState::rsAsm) {
mRange.state = RangeState::rsAsmBlock;
mAsmStart = true;
}
mRange.braceLevel += 1; mRange.braceLevel += 1;
mRange.blockLevel += 1; mRange.blockLevel += 1;
mRange.blockStarted += 1; mRange.blockStarted += 1;
@ -836,8 +818,6 @@ void GLSLSyntaxer::semiColonProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRange.state == RangeState::rsAsm)
mRange.state = RangeState::rsUnknown;
while (mRange.getLastIndent() == IndentForStatement) { while (mRange.getLastIndent() == IndentForStatement) {
popIndents(IndentForStatement); popIndents(IndentForStatement);
} }
@ -853,11 +833,7 @@ void GLSLSyntaxer::slashProc()
return; return;
case '*': // C style comment case '*': // C style comment
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
if (mRange.state == RangeState::rsAsm) { if (mRange.state == RangeState::rsDirective) {
mRange.state = RangeState::rsAnsiCAsm;
} else if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = RangeState::rsAnsiCAsmBlock;
} else if (mRange.state == RangeState::rsDirective) {
mRange.state = RangeState::rsDirectiveComment; mRange.state = RangeState::rsDirectiveComment;
} else { } else {
mRange.state = RangeState::rsAnsiC; mRange.state = RangeState::rsAnsiC;
@ -883,6 +859,8 @@ void GLSLSyntaxer::spaceProc()
while (mLine[mRun]>=1 && mLine[mRun]<=32) while (mLine[mRun]>=1 && mLine[mRun]<=32)
mRun+=1; mRun+=1;
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
if (mRun>=mLineSize)
mRange.hasTrailingSpaces=true;
} }
void GLSLSyntaxer::squareCloseProc() void GLSLSyntaxer::squareCloseProc()
@ -1284,8 +1262,6 @@ bool GLSLSyntaxer::getTokenFinished() const
bool GLSLSyntaxer::isLastLineCommentNotFinished(int state) const bool GLSLSyntaxer::isLastLineCommentNotFinished(int state) const
{ {
return (state == RangeState::rsAnsiC || return (state == RangeState::rsAnsiC ||
state == RangeState::rsAnsiCAsm ||
state == RangeState::rsAnsiCAsmBlock ||
state == RangeState::rsDirectiveComment|| state == RangeState::rsDirectiveComment||
state == RangeState::rsCppComment); state == RangeState::rsCppComment);
} }
@ -1353,13 +1329,10 @@ int GLSLSyntaxer::getTokenPos()
void GLSLSyntaxer::next() void GLSLSyntaxer::next()
{ {
mAsmStart = false;
mTokenPos = mRun; mTokenPos = mRun;
do { do {
switch (mRange.state) { switch (mRange.state) {
case RangeState::rsAnsiC: case RangeState::rsAnsiC:
case RangeState::rsAnsiCAsm:
case RangeState::rsAnsiCAsmBlock:
case RangeState::rsDirectiveComment: case RangeState::rsDirectiveComment:
ansiCProc(); ansiCProc();
break; break;
@ -1439,6 +1412,7 @@ void GLSLSyntaxer::setState(const SyntaxerState& rangeState)
mRange.blockEndedLastLine = 0; mRange.blockEndedLastLine = 0;
mRange.firstIndentThisLine = mRange.indents.length(); mRange.firstIndentThisLine = mRange.indents.length();
mRange.matchingIndents.clear(); mRange.matchingIndents.clear();
mRange.hasTrailingSpaces = false;
} }
void GLSLSyntaxer::resetState() void GLSLSyntaxer::resetState()
@ -1454,7 +1428,7 @@ void GLSLSyntaxer::resetState()
mRange.indents.clear(); mRange.indents.clear();
mRange.firstIndentThisLine = 0; mRange.firstIndentThisLine = 0;
mRange.matchingIndents.clear(); mRange.matchingIndents.clear();
mAsmStart = false; mRange.hasTrailingSpaces = false;
} }
QString GLSLSyntaxer::languageName() QString GLSLSyntaxer::languageName()

View File

@ -45,8 +45,7 @@ class GLSLSyntaxer: public Syntaxer
}; };
enum RangeState { enum RangeState {
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm, rsUnknown, rsAnsiC, rsDirective, rsDirectiveComment, rsString,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
rsMultiLineString, rsMultiLineDirective, rsCppComment, rsMultiLineString, rsMultiLineDirective, rsCppComment,
rsStringEscapeSeq, rsMultiLineStringEscapeSeq, rsStringEscapeSeq, rsMultiLineStringEscapeSeq,
rsRawString, rsSpace,rsRawStringEscaping,rsRawStringNotEscaping,rsChar, rsRawString, rsSpace,rsRawStringEscaping,rsRawStringNotEscaping,rsChar,
@ -133,7 +132,6 @@ private:
void pushIndents(int indentType); void pushIndents(int indentType);
private: private:
bool mAsmStart;
SyntaxerState mRange; SyntaxerState mRange;
// SynRangeState mSpaceRange; // SynRangeState mSpaceRange;
QString mLineString; QString mLineString;

View File

@ -201,6 +201,8 @@ void MakefileSyntaxer::procSpace()
mTokenID = TokenId::Space; mTokenID = TokenId::Space;
while (mLine[mRun]!=0 && mLine[mRun]<=32) while (mLine[mRun]!=0 && mLine[mRun]<=32)
mRun++; mRun++;
if (mRun>=mStringLen)
mHasTrailingSpaces = true;
} }
void MakefileSyntaxer::procNumber() void MakefileSyntaxer::procNumber()
@ -666,6 +668,7 @@ SyntaxerState MakefileSyntaxer::getState() const
{ {
SyntaxerState state; SyntaxerState state;
state.state = (int)mState; state.state = (int)mState;
state.hasTrailingSpaces = mHasTrailingSpaces;
return state; return state;
} }
@ -673,12 +676,14 @@ void MakefileSyntaxer::setState(const SyntaxerState & rangeState)
{ {
mState = (RangeState)rangeState.state; mState = (RangeState)rangeState.state;
mStates.clear(); mStates.clear();
mHasTrailingSpaces = false;
} }
void MakefileSyntaxer::resetState() void MakefileSyntaxer::resetState()
{ {
mState = RangeState::Unknown; mState = RangeState::Unknown;
mStates.clear(); mStates.clear();
mHasTrailingSpaces = false;
} }
QSet<QString> MakefileSyntaxer::keywords() const QSet<QString> MakefileSyntaxer::keywords() const

View File

@ -79,6 +79,7 @@ private:
QVector<RangeState> mStates; QVector<RangeState> mStates;
RangeState mState; RangeState mState;
TokenId mTokenID; TokenId mTokenID;
bool mHasTrailingSpaces;
PTokenAttribute mTargetAttribute; PTokenAttribute mTargetAttribute;
PTokenAttribute mCommandAttribute; PTokenAttribute mCommandAttribute;

View File

@ -274,7 +274,8 @@ SyntaxerState::SyntaxerState():
parenthesisLevel(0), parenthesisLevel(0),
// leftBraces(0), // leftBraces(0),
// rightBraces(0), // rightBraces(0),
firstIndentThisLine(0) firstIndentThisLine(0),
hasTrailingSpaces(false)
{ {
} }
} }

View File

@ -51,6 +51,7 @@ struct SyntaxerState {
QVector<int> matchingIndents; /* the indent matched ( and removed ) QVector<int> matchingIndents; /* the indent matched ( and removed )
but not started at this line but not started at this line
(need by auto indent) */ (need by auto indent) */
bool hasTrailingSpaces;
bool operator==(const SyntaxerState& s2); bool operator==(const SyntaxerState& s2);
int getLastIndent(); int getLastIndent();
SyntaxerState(); SyntaxerState();