mirror of
https://github.com/RGBCube/serenity
synced 2025-06-30 10:32:17 +00:00
LibGUI+HackStudio: Move syntax highlighting from HackStudio to LibGUI
This patch introduces the GUI::SyntaxHighlighter class, which can be attached to a GUI::TextEditor to provide syntax highlighting. The C++ syntax highlighting from HackStudio becomes a new class called GUI::CppSyntaxHighlighter. This will make it possible to get C++ syntax highlighting in any app that uses a GUI::TextEditor. :^) Sidenote: It does feel a bit weird having a C++ lexer in a GUI toolkit library, and we'll probably end up moving this out to a separate place as this functionality grows larger.
This commit is contained in:
parent
6cf49c23d4
commit
bb8e65be41
13 changed files with 277 additions and 170 deletions
|
@ -27,7 +27,6 @@
|
|||
#include <AK/QuickSort.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Clipboard.h>
|
||||
#include <LibGUI/FontDatabase.h>
|
||||
|
@ -35,8 +34,10 @@
|
|||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/ScrollBar.h>
|
||||
#include <LibGUI/SyntaxHighlighter.h>
|
||||
#include <LibGUI/TextEditor.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
@ -1030,6 +1031,8 @@ void TextEditor::set_cursor(const TextPosition& a_position)
|
|||
cursor_did_change();
|
||||
if (on_cursor_change)
|
||||
on_cursor_change();
|
||||
if (m_highlighter)
|
||||
m_highlighter->cursor_did_change();
|
||||
}
|
||||
|
||||
void TextEditor::focusin_event(Core::Event&)
|
||||
|
@ -1198,6 +1201,8 @@ void TextEditor::did_change()
|
|||
return;
|
||||
if (on_change)
|
||||
on_change();
|
||||
if (m_highlighter)
|
||||
m_highlighter->rehighlight();
|
||||
m_has_pending_change_notification = false;
|
||||
});
|
||||
}
|
||||
|
@ -1476,7 +1481,20 @@ void TextEditor::flush_pending_change_notification_if_needed()
|
|||
return;
|
||||
if (on_change)
|
||||
on_change();
|
||||
if (m_highlighter)
|
||||
m_highlighter->rehighlight();
|
||||
m_has_pending_change_notification = false;
|
||||
}
|
||||
|
||||
void TextEditor::set_syntax_highlighter(OwnPtr<SyntaxHighlighter> highlighter)
|
||||
{
|
||||
if (m_highlighter)
|
||||
m_highlighter->detach();
|
||||
m_highlighter = move(highlighter);
|
||||
if (m_highlighter) {
|
||||
m_highlighter->attach(*this);
|
||||
m_highlighter->rehighlight();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue