Remove race condition when painting error message, and remove newline characters from error message

pull/170/head
James Ball 2023-12-20 19:22:59 +00:00
rodzic 1eb0c4956f
commit 0d4f461503
2 zmienionych plików z 11 dodań i 10 usunięć

Wyświetl plik

@ -3,7 +3,7 @@
#include "../lua/LuaParser.h"
#include "../PluginProcessor.h"
class ErrorCodeEditorComponent : public juce::CodeEditorComponent, public ErrorListener {
class ErrorCodeEditorComponent : public juce::CodeEditorComponent, public ErrorListener, public juce::AsyncUpdater {
public:
ErrorCodeEditorComponent(juce::CodeDocument& document, juce::CodeTokeniser* codeTokeniser, OscirenderAudioProcessor& p, juce::String fileName) : juce::CodeEditorComponent(document, codeTokeniser), audioProcessor(p), document(document), fileName(fileName) {
audioProcessor.addErrorListener(this);
@ -73,7 +73,7 @@ class ErrorCodeEditorComponent : public juce::CodeEditorComponent, public ErrorL
juce::CodeEditorComponent::mouseMove(event);
if (errorLine != -1) {
errorLineHovered = getErrorLineBounds().contains(event.getPosition());
repaint(getErrorRepaintBounds());
repaint();
}
}
@ -84,20 +84,18 @@ class ErrorCodeEditorComponent : public juce::CodeEditorComponent, public ErrorL
return juce::Rectangle<int>(gutterWidth, getLineHeight() * (errorLine - 1 - firstVisibleLine), getWidth() - gutterWidth, getLineHeight());
}
juce::Rectangle<int> getErrorRepaintBounds() {
auto lineBounds = getErrorLineBounds();
return juce::Rectangle<int>(lineBounds.getX(), lineBounds.getY(), lineBounds.getWidth(), lineBounds.getHeight() * 2);
}
bool keyPressed(const juce::KeyPress& key) override {
void handleAsyncUpdate() override {
repaint();
return juce::CodeEditorComponent::keyPressed(key);
}
private:
void onError(int lineNumber, juce::String error) override {
int oldErrorLine = errorLine;
errorLine = lineNumber;
errorText = error;
if (errorLine != -1 || errorLine != oldErrorLine) {
triggerAsyncUpdate();
}
}
juce::String getFileName() override {

Wyświetl plik

@ -33,9 +33,12 @@ void LuaParser::reportError(const char* errorChars) {
return;
}
// remove any newlines from error message
error = std::regex_replace(error, std::regex(R"(\n|\r)"), "");
// remove script content from error message
error = std::regex_replace(error, std::regex(R"(^\[string ".*"\]:)"), "");
// extract line number from start of error message
std::regex lineRegex(R"((\d+): )");
std::regex lineRegex(R"(^(\d+): )");
std::smatch lineMatch;
std::regex_search(error, lineMatch, lineRegex);