1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

LibGUI: Standardize automatic scrolling in TextEditor+GlyphMapWidget

Both widgets now make use of their base class's scrolling timer and
now always accept drag selection updates on mousemove_event().

This guarantees much snappier feeling selections when actively moving
the mouse.
This commit is contained in:
thankyouverycool 2022-12-25 15:51:04 -05:00 committed by Andreas Kling
parent d938b9effe
commit 804baa42f9
4 changed files with 45 additions and 30 deletions

View file

@ -69,10 +69,6 @@ TextEditor::TextEditor(Type type)
}
vertical_scrollbar().set_step(line_height());
m_cursor = { 0, 0 };
m_automatic_selection_scroll_timer = add<Core::Timer>(100, [this] {
automatic_selection_scroll_timer_fired();
});
m_automatic_selection_scroll_timer->stop();
create_actions();
set_editing_engine(make<RegularEditingEngine>());
}
@ -309,8 +305,9 @@ void TextEditor::mouseup_event(MouseEvent& event)
void TextEditor::mousemove_event(MouseEvent& event)
{
m_last_mousemove_position = event.position();
if (m_in_drag_select && (rect().contains(event.position()) || !m_automatic_selection_scroll_timer->is_active())) {
set_cursor(text_position_at(event.position()));
if (m_in_drag_select) {
auto constrained = event.position().constrained(widget_inner_rect());
set_cursor(text_position_at(constrained));
m_selection.set_end(m_cursor);
did_update_selection();
update();
@ -332,10 +329,10 @@ void TextEditor::select_current_line()
did_update_selection();
}
void TextEditor::automatic_selection_scroll_timer_fired()
void TextEditor::automatic_scrolling_timer_did_fire()
{
if (!m_in_drag_select) {
m_automatic_selection_scroll_timer->stop();
set_automatic_scrolling_timer_active(false);
return;
}
set_cursor(text_position_at(m_last_mousemove_position));
@ -1736,13 +1733,13 @@ void TextEditor::hide_autocomplete()
void TextEditor::enter_event(Core::Event&)
{
m_automatic_selection_scroll_timer->stop();
set_automatic_scrolling_timer_active(false);
}
void TextEditor::leave_event(Core::Event&)
{
if (m_in_drag_select)
m_automatic_selection_scroll_timer->start();
set_automatic_scrolling_timer_active(true);
}
void TextEditor::did_change(AllowCallback allow_callback)