mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:27:35 +00:00
LibGUI: Add an optional "automatic" autocomplete feature to TextEditor
This aims to be a "smart" autocomplete that tries to present the user with useful suggestions without being in the way (too much). Here is its current configuration: - Show suggestions 800ms after something is inserted in the editor - if something else is inserted in that period, reset it back to 800ms to allow the user to type uninterrupted - cancel any shown autocomplete (and the timer) on external changes (paste, cut, etc)
This commit is contained in:
parent
60f5f48dd1
commit
a4a238ddc8
3 changed files with 75 additions and 12 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <LibCore/ElapsedTimer.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGUI/ScrollableWidget.h>
|
||||
#include <LibGUI/TextDocument.h>
|
||||
|
@ -163,6 +164,9 @@ public:
|
|||
const AutocompleteProvider* autocomplete_provider() const;
|
||||
void set_autocomplete_provider(OwnPtr<AutocompleteProvider>&&);
|
||||
|
||||
bool should_autocomplete_automatically() const { return m_autocomplete_timer; }
|
||||
void set_should_autocomplete_automatically(bool);
|
||||
|
||||
bool is_in_drag_select() const { return m_in_drag_select; }
|
||||
|
||||
protected:
|
||||
|
@ -212,6 +216,8 @@ private:
|
|||
void defer_reflow();
|
||||
void undefer_reflow();
|
||||
|
||||
void try_show_autocomplete();
|
||||
|
||||
int icon_size() const { return 16; }
|
||||
int icon_padding() const { return 2; }
|
||||
|
||||
|
@ -323,8 +329,12 @@ private:
|
|||
OwnPtr<SyntaxHighlighter> m_highlighter;
|
||||
OwnPtr<AutocompleteProvider> m_autocomplete_provider;
|
||||
OwnPtr<AutocompleteBox> m_autocomplete_box;
|
||||
bool m_should_keep_autocomplete_box { false };
|
||||
size_t m_automatic_autocomplete_delay_ms { 800 };
|
||||
|
||||
RefPtr<Core::Timer> m_automatic_selection_scroll_timer;
|
||||
RefPtr<Core::Timer> m_autocomplete_timer;
|
||||
|
||||
Gfx::IntPoint m_last_mousemove_position;
|
||||
|
||||
RefPtr<Gfx::Bitmap> m_icon;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue