mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:37:44 +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
39
Libraries/LibGUI/SyntaxHighlighter.h
Normal file
39
Libraries/LibGUI/SyntaxHighlighter.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibGUI/TextDocument.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class TextEditor;
|
||||
|
||||
class SyntaxHighlighter {
|
||||
AK_MAKE_NONCOPYABLE(SyntaxHighlighter);
|
||||
AK_MAKE_NONMOVABLE(SyntaxHighlighter);
|
||||
|
||||
public:
|
||||
virtual ~SyntaxHighlighter();
|
||||
|
||||
virtual void rehighlight() = 0;
|
||||
virtual void highlight_matching_token_pair() = 0;
|
||||
|
||||
void attach(TextEditor& editor);
|
||||
void detach();
|
||||
void cursor_did_change();
|
||||
|
||||
protected:
|
||||
SyntaxHighlighter() {}
|
||||
|
||||
WeakPtr<TextEditor> m_editor;
|
||||
|
||||
struct BuddySpan {
|
||||
int index { -1 };
|
||||
GUI::TextDocumentSpan span_backup;
|
||||
};
|
||||
|
||||
bool m_has_brace_buddies { false };
|
||||
BuddySpan m_brace_buddies[2];
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue