Use QTextDocument::contentsChange as code editor modified signal
MODIFY
src/editor/codeeditor.cpp
src/editor/codeeditor.cpp
@@ -54,8 +54,13 @@ void CodeEditor::setupChangedTimer() {
// A change in the document will start the timer - when the timer elapses, the contents will be assembled if there
// is no syntax error. By doing this, the timer is restartet each time a change occurs (ie. a user is continuously
- // typing)
- connect(this, &QPlainTextEdit::textChanged, m_changeTimer, QOverload<>::of(&QTimer::start));
+ // typing).
+ // Note, QTextDocument::contentsChange seems to be the only signal in the stack of QPlainTextEdit etc. which
+ // (contrary to documentation) does not emit a change signal when formatting is applied. This is required to avoid a
+ // signal loop in the case of:
+ // (content change -> assemble -> assembling fails -> rehighlight to reflect assembler error -> content change)
+ connect(this->document(), &QTextDocument::contentsChange, [this](int, int, int) { m_changeTimer->start(); });
+
connect(m_changeTimer, &QTimer::timeout, this, &CodeEditor::timedTextChanged);
}

MODIFY
src/edittab.cpp
src/edittab.cpp
@@ -214,9 +214,9 @@ void EditTab::assemble() {
m_activeProgram = std::make_shared<Program>(res.program);
emitProgramChanged();
} else {
- // Errors occured; rehighlight to reflect current m_sourceErrors in the editor
- m_ui->codeEditor->rehighlight();
+ // Errors occured; rehighlight will reflect current m_sourceErrors in the editor
}
+ m_ui->codeEditor->rehighlight();
}
void EditTab::compile() {

Use QTextDocument::contentsChange as code editor modified signal