summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-12-28 20:46:39 +0330
committerAndreas Kling <kling@serenityos.org>2020-12-29 00:58:43 +0100
commitaa5b43a2bc137d0649b341372bb367313a725269 (patch)
tree08b48c93134fc612062d2f5bd63a7e98491b4053
parentb34b68181115a35ea610a998d7c6faeb3259a2d9 (diff)
downloadserenity-aa5b43a2bc137d0649b341372bb367313a725269.zip
Spreadsheet: Highlight the source causing an exception in red
This commit makes the cell editor highlight the likely source of the exception in red.
-rw-r--r--Applications/Spreadsheet/CellSyntaxHighlighter.cpp13
-rw-r--r--Applications/Spreadsheet/CellSyntaxHighlighter.h5
-rw-r--r--Applications/Spreadsheet/SpreadsheetWidget.cpp3
3 files changed, 21 insertions, 0 deletions
diff --git a/Applications/Spreadsheet/CellSyntaxHighlighter.cpp b/Applications/Spreadsheet/CellSyntaxHighlighter.cpp
index 8a3c0a5688..f2202f1d85 100644
--- a/Applications/Spreadsheet/CellSyntaxHighlighter.cpp
+++ b/Applications/Spreadsheet/CellSyntaxHighlighter.cpp
@@ -53,6 +53,19 @@ void CellSyntaxHighlighter::rehighlight(Gfx::Palette palette)
false,
false,
nullptr);
+
+ if (m_cell && m_cell->exception()) {
+ auto range = m_cell->exception()->source_ranges().first();
+ GUI::TextRange text_range { { range.start.line - 1, range.start.column }, { range.end.line - 1, range.end.column - 1 } };
+ m_editor->document().spans().prepend({ text_range,
+ Color::Black,
+ Color::Red,
+ false,
+ false,
+ false,
+ nullptr });
+ }
+ m_editor->update();
}
CellSyntaxHighlighter::~CellSyntaxHighlighter()
diff --git a/Applications/Spreadsheet/CellSyntaxHighlighter.h b/Applications/Spreadsheet/CellSyntaxHighlighter.h
index 4c42630b97..f02f7e2bbb 100644
--- a/Applications/Spreadsheet/CellSyntaxHighlighter.h
+++ b/Applications/Spreadsheet/CellSyntaxHighlighter.h
@@ -26,6 +26,7 @@
#pragma once
+#include "Cell.h"
#include <LibGUI/JSSyntaxHighlighter.h>
#include <LibGUI/SyntaxHighlighter.h>
@@ -37,6 +38,10 @@ public:
virtual ~CellSyntaxHighlighter() override;
virtual void rehighlight(Gfx::Palette) override;
+ void set_cell(const Cell* cell) { m_cell = cell; }
+
+private:
+ const Cell* m_cell { nullptr };
};
}
diff --git a/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Applications/Spreadsheet/SpreadsheetWidget.cpp
index 6e94ed4093..fc78f578da 100644
--- a/Applications/Spreadsheet/SpreadsheetWidget.cpp
+++ b/Applications/Spreadsheet/SpreadsheetWidget.cpp
@@ -142,6 +142,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
update();
};
m_cell_value_editor->set_enabled(true);
+ static_cast<CellSyntaxHighlighter*>(const_cast<GUI::SyntaxHighlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&cell);
return;
}
@@ -169,9 +170,11 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
}
};
m_cell_value_editor->set_enabled(true);
+ static_cast<CellSyntaxHighlighter*>(const_cast<GUI::SyntaxHighlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(cells.first());
};
m_selected_view->on_selection_dropped = [&]() {
m_cell_value_editor->set_enabled(false);
+ static_cast<CellSyntaxHighlighter*>(const_cast<GUI::SyntaxHighlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr);
m_cell_value_editor->set_text("");
m_current_cell_label->set_enabled(false);
m_current_cell_label->set_text("");