diff --git a/LibGUI/GAbstractView.cpp b/LibGUI/GAbstractView.cpp index 01872253684..5d672947903 100644 --- a/LibGUI/GAbstractView.cpp +++ b/LibGUI/GAbstractView.cpp @@ -41,3 +41,15 @@ void GAbstractView::did_update_model() void GAbstractView::did_update_selection() { } + +void GAbstractView::did_scroll() +{ + update_edit_widget_position(); +} + +void GAbstractView::update_edit_widget_position() +{ + if (!m_edit_widget) + return; + m_edit_widget->set_relative_rect(m_edit_widget_content_rect.translated(-horizontal_scrollbar().value(), -vertical_scrollbar().value())); +} diff --git a/LibGUI/GAbstractView.h b/LibGUI/GAbstractView.h index f0c33c5bd9b..ac019a673e8 100644 --- a/LibGUI/GAbstractView.h +++ b/LibGUI/GAbstractView.h @@ -29,10 +29,13 @@ public: protected: virtual void model_notification(const GModelNotification&); + virtual void did_scroll() override; + void update_edit_widget_position(); bool m_editable { false }; GModelIndex m_edit_index; GTextBox* m_edit_widget { nullptr }; + Rect m_edit_widget_content_rect; private: RetainPtr m_model; diff --git a/LibGUI/GScrollableWidget.cpp b/LibGUI/GScrollableWidget.cpp index 01d84e7c66b..a4ce1620ca5 100644 --- a/LibGUI/GScrollableWidget.cpp +++ b/LibGUI/GScrollableWidget.cpp @@ -7,6 +7,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent) m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this); m_vertical_scrollbar->set_step(4); m_vertical_scrollbar->on_change = [this] (int) { + did_scroll(); update(); }; @@ -14,6 +15,7 @@ GScrollableWidget::GScrollableWidget(GWidget* parent) m_horizontal_scrollbar->set_step(4); m_horizontal_scrollbar->set_big_step(30); m_horizontal_scrollbar->on_change = [this] (int) { + did_scroll(); update(); }; diff --git a/LibGUI/GScrollableWidget.h b/LibGUI/GScrollableWidget.h index 9d890d820a7..60c80a321fc 100644 --- a/LibGUI/GScrollableWidget.h +++ b/LibGUI/GScrollableWidget.h @@ -39,6 +39,7 @@ public: protected: explicit GScrollableWidget(GWidget* parent); virtual void resize_event(GResizeEvent&) override; + virtual void did_scroll() { } void set_content_size(const Size&); void set_size_occupied_by_fixed_elements(const Size&); diff --git a/LibGUI/GTableView.cpp b/LibGUI/GTableView.cpp index 85b54cc2b6d..65be3d6f579 100644 --- a/LibGUI/GTableView.cpp +++ b/LibGUI/GTableView.cpp @@ -339,8 +339,10 @@ void GTableView::begin_editing(const GModelIndex& index) delete m_edit_widget; m_edit_index = index; m_edit_widget = new GTextBox(this); + m_edit_widget->move_to_back(); m_edit_widget->set_text(model()->data(index, GModel::Role::Display).to_string()); - m_edit_widget->set_relative_rect(cell_content_rect(index)); + m_edit_widget_content_rect = cell_content_rect(index); + update_edit_widget_position(); m_edit_widget->set_focus(true); m_edit_widget->on_return_pressed = [this] { ASSERT(model());