From c3aa97010788c2890709bb05859ed0db05d9b29c Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 28 Jul 2023 08:35:29 -0700 Subject: [PATCH] feat: add the ability to toggle scrollbar visibility (#7314) --- core/scrollbar.ts | 18 +++++++++++++++--- core/scrollbar_pair.ts | 10 ++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/scrollbar.ts b/core/scrollbar.ts index 2a7984a72..b1209c5f4 100644 --- a/core/scrollbar.ts +++ b/core/scrollbar.ts @@ -657,13 +657,25 @@ export class Scrollbar { * @param visible True if visible. */ setVisible(visible: boolean) { - const visibilityChanged = visible !== this.isVisible(); - // Ideally this would also apply to scrollbar pairs, but that's a bigger - // headache (due to interactions with the corner square). + // headache (due to interactions with the corner square), and the fact + // that telling the pair to resize itself would cause circular dependencies. if (this.pair) { throw Error('Unable to toggle visibility of paired scrollbars.'); } + this.setVisibleInternal(visible); + } + + /** + * Set whether the scrollbar is visible. Bypasses checking whether this + * scrollbar is part of a pair so that it can be toggled by the scrollbar + * pair. + * + * @param visible True if visible. + * @internal + */ + setVisibleInternal(visible: boolean) { + const visibilityChanged = visible !== this.isVisible(); this.isHandleVisible = visible; if (visibilityChanged) { this.updateDisplay_(); diff --git a/core/scrollbar_pair.ts b/core/scrollbar_pair.ts index 5b8ede4e7..8bb2b3d3a 100644 --- a/core/scrollbar_pair.ts +++ b/core/scrollbar_pair.ts @@ -306,6 +306,16 @@ export class ScrollbarPair { return isVisible; } + /** + * Sets the visibility of any existing scrollbars. + * + * @param visible True if visible. + */ + setVisible(visible: boolean) { + if (this.hScroll) this.hScroll.setVisibleInternal(visible); + if (this.vScroll) this.vScroll.setVisibleInternal(visible); + } + /** * Recalculates the scrollbars' locations within their path and length. * This should be called when the contents of the workspace have changed.