feat: add the ability to toggle scrollbar visibility (#7314)

This commit is contained in:
Beka Westberg
2023-07-28 08:35:29 -07:00
committed by GitHub
parent 9dc293b762
commit c3aa970107
2 changed files with 25 additions and 3 deletions

View File

@@ -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_();

View File

@@ -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.