Fix issue with CodeEditor update emmission
Previously, QPlainTextEdit::textChanged was connected to by various
widgets instead of the intended delayed text change signal of the
CodeEditor.
MODIFY
src/editor/codeeditor.cpp
src/editor/codeeditor.cpp
@@ -50,11 +50,12 @@ void CodeEditor::setupChangedTimer() {
// configures the change-timer and assembler connectivity with Parser
m_changeTimer->setInterval(500);
m_changeTimer->setSingleShot(true);
+
// 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));
- connect(m_changeTimer, &QTimer::timeout, this, &CodeEditor::textChanged);
+ connect(m_changeTimer, &QTimer::timeout, this, &CodeEditor::timedTextChanged);
}
int CodeEditor::lineNumberAreaWidth() {

MODIFY
src/editor/codeeditor.h
src/editor/codeeditor.h
@@ -33,7 +33,14 @@ public:
bool syntaxAccepted() const { return m_highlighter->acceptsSyntax(); }
signals:
- void textChanged();
+ /**
+ * @brief timedTextChanged
+ * Using m_changeTimer, timedTextChanged will be emitted whenever the user has stopped editing the text document for
+ * some time.
+ * The signal may be used as an alternative to QPlainTextEdit::textChanged(), to reduce the amount of updates
+ * performed wrt. text changes.
+ */
+ void timedTextChanged();
protected:
void resizeEvent(QResizeEvent* event) override;

MODIFY
src/edittab.cpp
src/edittab.cpp
@@ -26,7 +26,7 @@ EditTab::EditTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent)
m_assembler = std::make_unique<Assembler>();
- connect(m_ui->codeEditor, &CodeEditor::textChanged, this, &EditTab::sourceCodeChanged);
+ connect(m_ui->codeEditor, &CodeEditor::timedTextChanged, this, &EditTab::sourceCodeChanged);
connect(m_ui->setAssemblyInput, &QRadioButton::toggled, this, &EditTab::sourceTypeChanged);
connect(m_ui->setCInput, &QRadioButton::toggled, this, &EditTab::sourceTypeChanged);
@@ -165,7 +165,7 @@ void EditTab::compile() {
} else {
QMessageBox compileErrorMsg(this);
compileErrorMsg.setWindowTitle("Compile error");
- compileErrorMsg.setText("Compilation failed. View detailed text for compiler output.");
+ compileErrorMsg.setText("Compilation failed.\nView detailed text for compiler output.");
compileErrorMsg.setDetailedText(CCManager::getError());
compileErrorMsg.exec();
}
@@ -201,12 +201,12 @@ void EditTab::updateProgramViewer() {
}
void EditTab::enableEditor() {
- connect(m_ui->codeEditor, &CodeEditor::textChanged, this, &EditTab::sourceCodeChanged);
+ connect(m_ui->codeEditor, &CodeEditor::timedTextChanged, this, &EditTab::sourceCodeChanged);
m_ui->editorStackedWidget->setCurrentIndex(0);
}
void EditTab::disableEditor() {
- disconnect(m_ui->codeEditor, &CodeEditor::textChanged, this, &EditTab::sourceCodeChanged);
+ disconnect(m_ui->codeEditor, &CodeEditor::timedTextChanged, this, &EditTab::sourceCodeChanged);
m_ui->editorStackedWidget->setCurrentIndex(1);
clearAssemblyEditor();
m_editorEnabled = false;

Fix issue with CodeEditor update emmission

Previously, QPlainTextEdit::textChanged was connected to by various
widgets instead of the intended delayed text change signal of the
CodeEditor.