Path: blob/main/extensions/copilot/test/simulation/fixtures/edit-add-toString2/index.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IBoundarySashes, ISashEvent, Orientation, Sash, SashState } from 'vs/base/browser/ui/sash/sash';6import { Disposable } from 'vs/base/common/lifecycle';7import { IObservable, IReader, autorun, derived, observableValue } from 'vs/base/common/observable';8import { DiffEditorOptions } from './diffEditorOptions';910export class DiffEditorSash extends Disposable {11private readonly _sashRatio = observableValue<number | undefined>(this, undefined);1213public readonly sashLeft = derived(this, reader => {14const ratio = this._sashRatio.read(reader) ?? this._options.splitViewDefaultRatio.read(reader);15return this._computeSashLeft(ratio, reader);16});1718private readonly _sash = this._register(new Sash(this._domNode, {19getVerticalSashTop: (_sash: Sash): number => 0,20getVerticalSashLeft: (_sash: Sash): number => this.sashLeft.get(),21getVerticalSashHeight: (_sash: Sash): number => this._dimensions.height.get(),22}, { orientation: Orientation.VERTICAL }));2324private _startSashPosition: number | undefined = undefined;2526constructor(27private readonly _options: DiffEditorOptions,28private readonly _domNode: HTMLElement,29private readonly _dimensions: { height: IObservable<number>; width: IObservable<number> },30) {31super();3233this._register(this._sash.onDidStart(() => {34this._startSashPosition = this.sashLeft.get();35}));36this._register(this._sash.onDidChange((e: ISashEvent) => {37const contentWidth = this._dimensions.width.get();38const sashPosition = this._computeSashLeft((this._startSashPosition! + (e.currentX - e.startX)) / contentWidth, undefined);39this._sashRatio.set(sashPosition / contentWidth, undefined);40}));41this._register(this._sash.onDidEnd(() => this._sash.layout()));42this._register(this._sash.onDidReset(() => this._sashRatio.set(undefined, undefined)));4344this._register(autorun(reader => {45/** @description update sash layout */46const enabled = this._options.enableSplitViewResizing.read(reader);47this._sash.state = enabled ? SashState.Enabled : SashState.Disabled;48this.sashLeft.read(reader);49this._dimensions.height.read(reader);50this._sash.layout();51}));52}53545556setBoundarySashes(sashes: IBoundarySashes): void {57this._sash.orthogonalEndSash = sashes.bottom;58}5960/** @pure */61private _computeSashLeft(desiredRatio: number, reader: IReader | undefined): number {62const contentWidth = this._dimensions.width.read(reader);63const midPoint = Math.floor(this._options.splitViewDefaultRatio.read(reader) * contentWidth);64const sashLeft = this._options.enableSplitViewResizing.read(reader) ? Math.floor(desiredRatio * contentWidth) : midPoint;6566const MINIMUM_EDITOR_WIDTH = 100;67if (contentWidth <= MINIMUM_EDITOR_WIDTH * 2) {68return midPoint;69}70if (sashLeft < MINIMUM_EDITOR_WIDTH) {71return MINIMUM_EDITOR_WIDTH;72}73if (sashLeft > contentWidth - MINIMUM_EDITOR_WIDTH) {74return contentWidth - MINIMUM_EDITOR_WIDTH;75}76return sashLeft;77}78}798081