mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
HackStudio: Abstract over syntax highlighter
This commit is contained in:
parent
bacd3dd57a
commit
137d68a2ae
5 changed files with 32 additions and 16 deletions
|
@ -31,7 +31,6 @@
|
|||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/CppLexer.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/ScrollBar.h>
|
||||
#include <LibGUI/SyntaxHighlighter.h>
|
||||
|
@ -184,13 +183,16 @@ void Editor::mousemove_event(GUI::MouseEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
auto highlighter = wrapper().editor().syntax_highlighter();
|
||||
if (!highlighter)
|
||||
return;
|
||||
|
||||
bool hide_tooltip = true;
|
||||
bool is_over_header = false;
|
||||
bool is_over_link = false;
|
||||
|
||||
for (auto& span : document().spans()) {
|
||||
if (span.range.contains(m_previous_text_position) && !span.range.contains(text_position)) {
|
||||
auto token = static_cast<GUI::CppToken::Type>(reinterpret_cast<size_t>(span.data));
|
||||
if (token == GUI::CppToken::Type::IncludePath && span.is_underlined) {
|
||||
if (highlighter->is_navigatable(span.data) && span.is_underlined) {
|
||||
span.is_underlined = false;
|
||||
wrapper().editor().update();
|
||||
}
|
||||
|
@ -204,15 +206,15 @@ void Editor::mousemove_event(GUI::MouseEvent& event)
|
|||
dbg() << "Hovering: " << adjusted_range << " \"" << hovered_span_text << "\"";
|
||||
#endif
|
||||
|
||||
auto token = static_cast<GUI::CppToken::Type>(reinterpret_cast<size_t>(span.data));
|
||||
if (token == GUI::CppToken::Type::IncludePath) {
|
||||
is_over_header = true;
|
||||
if (highlighter->is_navigatable(span.data)) {
|
||||
is_over_link = true;
|
||||
bool was_underlined = span.is_underlined;
|
||||
span.is_underlined = event.modifiers() & Mod_Ctrl;
|
||||
if (span.is_underlined != was_underlined) {
|
||||
wrapper().editor().update();
|
||||
}
|
||||
} else if (token == GUI::CppToken::Type::Identifier) {
|
||||
}
|
||||
if (highlighter->is_identifier(span.data)) {
|
||||
show_documentation_tooltip_if_available(hovered_span_text, event.position().translated(screen_relative_rect().location()));
|
||||
hide_tooltip = false;
|
||||
}
|
||||
|
@ -223,13 +225,13 @@ void Editor::mousemove_event(GUI::MouseEvent& event)
|
|||
if (hide_tooltip)
|
||||
m_documentation_tooltip_window->hide();
|
||||
|
||||
m_hovering_link = is_over_header && (event.modifiers() & Mod_Ctrl);
|
||||
m_hovering_link = is_over_link && (event.modifiers() & Mod_Ctrl);
|
||||
}
|
||||
|
||||
void Editor::mousedown_event(GUI::MouseEvent& event)
|
||||
{
|
||||
auto highlighter = wrapper().editor().syntax_highlighter();
|
||||
if (!highlighter || highlighter->language() != GUI::SyntaxLanguage::Cpp) {
|
||||
if (!highlighter) {
|
||||
GUI::TextEditor::mousedown_event(event);
|
||||
return;
|
||||
}
|
||||
|
@ -247,8 +249,7 @@ void Editor::mousedown_event(GUI::MouseEvent& event)
|
|||
|
||||
for (auto& span : document().spans()) {
|
||||
if (span.range.contains(text_position)) {
|
||||
auto token = static_cast<GUI::CppToken::Type>(reinterpret_cast<size_t>(span.data));
|
||||
if (token != GUI::CppToken::Type::IncludePath) {
|
||||
if (!highlighter->is_navigatable(span.data)) {
|
||||
GUI::TextEditor::mousedown_event(event);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue