mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00

This works for C++ syntax highlighted text documents by caching the C++ token type in a new "arbitrary data" member of GTextDocumentSpan. When the cursor is placed immediately before a '{' or immediately after a '}', we highlight both of these brace buddies by changing their corresponding spans to have a different background color. ..and spans can also now have a custom background color. :^)
40 lines
1,003 B
C++
40 lines
1,003 B
C++
#pragma once
|
|
|
|
#include <LibGUI/GTextEditor.h>
|
|
|
|
class EditorWrapper;
|
|
class HtmlView;
|
|
|
|
class Editor final : public GTextEditor {
|
|
C_OBJECT(Editor)
|
|
public:
|
|
virtual ~Editor() override;
|
|
|
|
Function<void()> on_focus;
|
|
|
|
EditorWrapper& wrapper();
|
|
const EditorWrapper& wrapper() const;
|
|
|
|
private:
|
|
virtual void focusin_event(CEvent&) override;
|
|
virtual void focusout_event(CEvent&) override;
|
|
virtual void paint_event(GPaintEvent&) override;
|
|
virtual void mousemove_event(GMouseEvent&) override;
|
|
virtual void cursor_did_change() override;
|
|
|
|
void show_documentation_tooltip_if_available(const String&, const Point& screen_location);
|
|
|
|
explicit Editor(GWidget* parent);
|
|
|
|
RefPtr<GWindow> m_documentation_tooltip_window;
|
|
RefPtr<HtmlView> m_documentation_html_view;
|
|
String m_last_parsed_token;
|
|
|
|
struct BuddySpan {
|
|
int index { -1 };
|
|
GTextDocumentSpan span_backup;
|
|
};
|
|
|
|
bool m_has_brace_buddies { false };
|
|
BuddySpan m_brace_buddies[2];
|
|
};
|