From 9f8d518e829b1c0b35258f5124c9ca77bd974c88 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Thu, 18 Mar 2021 20:58:58 +0330 Subject: [PATCH] Spreadsheet: Only append new columns/rows every 50ms Fixes #5550. --- .../Spreadsheet/SpreadsheetView.cpp | 24 ++++++++++++++----- .../Spreadsheet/SpreadsheetView.h | 7 ++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp index 019b9b118a..8e49a2b162 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp @@ -69,13 +69,25 @@ void InfinitelyScrollableTableView::did_scroll() TableView::did_scroll(); auto& vscrollbar = vertical_scrollbar(); auto& hscrollbar = horizontal_scrollbar(); - if (vscrollbar.is_visible() && vscrollbar.value() == vscrollbar.max()) { - if (on_reaching_vertical_end) - on_reaching_vertical_end(); + if (!m_vertical_scroll_end_timer->is_active()) { + if (vscrollbar.is_visible() && vscrollbar.value() == vscrollbar.max()) { + m_vertical_scroll_end_timer->on_timeout = [&] { + if (on_reaching_vertical_end) + on_reaching_vertical_end(); + m_vertical_scroll_end_timer->stop(); + }; + m_vertical_scroll_end_timer->start(50); + } } - if (hscrollbar.is_visible() && hscrollbar.value() == hscrollbar.max()) { - if (on_reaching_horizontal_end) - on_reaching_horizontal_end(); + if (!m_horizontal_scroll_end_timer->is_active()) { + if (hscrollbar.is_visible() && hscrollbar.value() == hscrollbar.max()) { + m_horizontal_scroll_end_timer->on_timeout = [&] { + if (on_reaching_horizontal_end) + on_reaching_horizontal_end(); + m_horizontal_scroll_end_timer->stop(); + }; + m_horizontal_scroll_end_timer->start(50); + } } } diff --git a/Userland/Applications/Spreadsheet/SpreadsheetView.h b/Userland/Applications/Spreadsheet/SpreadsheetView.h index bc07d31bc3..2c27ee2748 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetView.h +++ b/Userland/Applications/Spreadsheet/SpreadsheetView.h @@ -86,6 +86,11 @@ public: Function on_reaching_horizontal_end; private: + InfinitelyScrollableTableView() + : m_horizontal_scroll_end_timer(Core::Timer::construct()) + , m_vertical_scroll_end_timer(Core::Timer::construct()) + { + } virtual void did_scroll() override; virtual void mousemove_event(GUI::MouseEvent&) override; virtual void mouseup_event(GUI::MouseEvent&) override; @@ -93,6 +98,8 @@ private: bool m_should_intercept_drag { false }; bool m_has_committed_to_dragging { false }; GUI::ModelIndex m_starting_selection_index; + RefPtr m_horizontal_scroll_end_timer; + RefPtr m_vertical_scroll_end_timer; }; class SpreadsheetView final : public GUI::Widget {