1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibLine: Support applying styles to suggestions

This commit also adds the concept of "anchored" styles, which are
applied to a specific part of the line, and are tracked to always stay
applied to that specific part.

Inserting text in the middle of an anchored style extends it, and
removing the styled substring causes the style to be removed as well.
This commit is contained in:
AnotherTest 2020-05-18 02:25:58 +04:30 committed by Andreas Kling
parent a0f3e3c50e
commit 88f542dc30
3 changed files with 305 additions and 40 deletions

View file

@ -50,11 +50,19 @@ struct CompletionSuggestion {
CompletionSuggestion(const String& completion)
: text(completion)
, trailing_trivia("")
, style()
{
}
CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia)
: text(completion)
, trailing_trivia(trailing_trivia)
, style()
{
}
CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia, Style style)
: text(completion)
, trailing_trivia(trailing_trivia)
, style(style)
{
}
@ -65,6 +73,8 @@ struct CompletionSuggestion {
String text;
String trailing_trivia;
Style style;
size_t token_start_index { 0 };
};
struct Configuration {
@ -157,12 +167,8 @@ public:
void insert(const String&);
void insert(const u32);
void stylize(const Span&, const Style&);
void strip_styles()
{
m_spans_starting.clear();
m_spans_ending.clear();
m_refresh_needed = true;
}
void strip_styles(bool strip_anchored = false);
void suggest(size_t invariant_offset = 0, size_t index = 0) const
{
m_next_suggestion_index = index;
@ -194,8 +200,15 @@ private:
void vt_clear_lines(size_t count_above, size_t count_below = 0);
void vt_move_relative(int x, int y);
void vt_move_absolute(u32 x, u32 y);
void vt_apply_style(const Style&);
void vt_apply_style(const Style&, bool is_starting = true);
Vector<size_t, 2> vt_dsr();
void remove_at_index(size_t);
enum class ModificationKind {
Insertion,
Removal,
};
void readjust_anchored_styles(size_t hint_index, ModificationKind);
Style find_applicable_style(size_t offset) const;
@ -343,6 +356,9 @@ private:
HashMap<u32, HashMap<u32, Style>> m_spans_starting;
HashMap<u32, HashMap<u32, Style>> m_spans_ending;
HashMap<u32, HashMap<u32, Style>> m_anchored_spans_starting;
HashMap<u32, HashMap<u32, Style>> m_anchored_spans_ending;
bool m_initialized { false };
bool m_refresh_needed { false };