diff options
author | FalseHonesty <thefalsehonesty@gmail.com> | 2020-05-30 02:01:35 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-30 10:18:14 +0200 |
commit | 12fe546be98840a172733fa7d6bad332b2fb36ef (patch) | |
tree | 2a511d8bb9cafa2192949f3005c2c8f0ef157258 | |
parent | 77039e5354e154d7f5333a4cbb22d93e842642b0 (diff) | |
download | serenity-12fe546be98840a172733fa7d6bad332b2fb36ef.zip |
LibGUI+HackStudio: Fix cursor appearance and crash while debugging
HackStudio uses a TreeView to display the list of current variables
while debugging, and when the program completes, it sets that view's
model to a null model. This would trip an assertion if the TreeView
had something selected at the time, so this patch lessens the
assertion into a simple null check.
Additionally, the cursor would look laggy when moving about the
editor because the code was waiting for a window repaint to update
the cursor's look when it makes more sense to update the cursor
when it actually moves. This change also requires the base
GUI::TextEditor to expose a getter to tell if its currently in a drag
selection.
Finally, requesting a context menu in the line ruler on the side of
the editor would also place/remove breakpoints, which was counter
intuitive, so this requires a left click to modify breakpoint placement.
-rw-r--r-- | DevTools/HackStudio/Editor.cpp | 17 | ||||
-rw-r--r-- | DevTools/HackStudio/Editor.h | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/TextEditor.h | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/TreeView.cpp | 3 |
4 files changed, 12 insertions, 11 deletions
diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp index 697d811ceb..9520298a72 100644 --- a/DevTools/HackStudio/Editor.cpp +++ b/DevTools/HackStudio/Editor.cpp @@ -107,11 +107,6 @@ void Editor::paint_event(GUI::PaintEvent& event) painter.draw_rect(rect, palette().selection()); } - if (m_hovering_lines_ruler) - window()->set_override_cursor(GUI::StandardCursor::Arrow); - else if (m_hovering_editor) - window()->set_override_cursor(m_hovering_link && m_holding_ctrl ? GUI::StandardCursor::Hand : GUI::StandardCursor::IBeam); - if (ruler_visible()) { size_t first_visible_line = text_position_at(event.rect().top_left()).line(); size_t last_visible_line = text_position_at(event.rect().bottom_right()).line(); @@ -217,12 +212,16 @@ void Editor::mousemove_event(GUI::MouseEvent& event) if (!highlighter) return; - auto ruler_line_rect = ruler_content_rect(text_position.line()); - m_hovering_lines_ruler = (event.position().x() < ruler_line_rect.width()); - bool hide_tooltip = true; bool is_over_link = false; + auto ruler_line_rect = ruler_content_rect(text_position.line()); + auto hovering_lines_ruler = (event.position().x() < ruler_line_rect.width()); + if (hovering_lines_ruler && !is_in_drag_select()) + window()->set_override_cursor(GUI::StandardCursor::Arrow); + else if (m_hovering_editor) + window()->set_override_cursor(m_hovering_link && m_holding_ctrl ? GUI::StandardCursor::Hand : GUI::StandardCursor::IBeam); + for (auto& span : document().spans()) { if (span.range.contains(m_previous_text_position) && !span.range.contains(text_position)) { if (highlighter->is_navigatable(span.data) && span.is_underlined) { @@ -272,7 +271,7 @@ void Editor::mousedown_event(GUI::MouseEvent& event) auto text_position = text_position_at(event.position()); auto ruler_line_rect = ruler_content_rect(text_position.line()); - if (event.position().x() < ruler_line_rect.width()) { + if (event.button() == GUI::MouseButton::Left && event.position().x() < ruler_line_rect.width()) { if (!m_breakpoint_lines.contains_slow(text_position.line())) { m_breakpoint_lines.append(text_position.line()); on_breakpoint_change(wrapper().filename_label().text(), text_position.line(), BreakpointChange::Added); diff --git a/DevTools/HackStudio/Editor.h b/DevTools/HackStudio/Editor.h index 69561b39ce..0d83145660 100644 --- a/DevTools/HackStudio/Editor.h +++ b/DevTools/HackStudio/Editor.h @@ -77,7 +77,6 @@ private: bool m_hovering_editor { false }; bool m_hovering_link { false }; bool m_holding_ctrl { false }; - bool m_hovering_lines_ruler { false }; Vector<size_t> m_breakpoint_lines; Optional<size_t> m_execution_position; diff --git a/Libraries/LibGUI/TextEditor.h b/Libraries/LibGUI/TextEditor.h index a6138ecde9..901345b7e9 100644 --- a/Libraries/LibGUI/TextEditor.h +++ b/Libraries/LibGUI/TextEditor.h @@ -129,6 +129,8 @@ public: const SyntaxHighlighter* syntax_highlighter() const; void set_syntax_highlighter(OwnPtr<SyntaxHighlighter>); + bool is_in_drag_select() const { return m_in_drag_select; } + protected: explicit TextEditor(Type = Type::MultiLine); diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp index 7c1d62df35..016037d6cb 100644 --- a/Libraries/LibGUI/TreeView.cpp +++ b/Libraries/LibGUI/TreeView.cpp @@ -377,7 +377,8 @@ void TreeView::did_update_model(unsigned flags) void TreeView::did_update_selection() { AbstractView::did_update_selection(); - ASSERT(model()); + if (!model()) + return; auto index = selection().first(); if (!index.is_valid()) return; |