Skip to content

Commit

Permalink
enable live preview for last line of document. for that... (#181029)
Browse files Browse the repository at this point in the history
- support `ordinal` and `showInHiddenAreas` for `IViewZone`
- adopt in zoneWidget
- adopt for inline chat widgets
- remove code that isn't needed anymore 👯‍♂️

fixes microsoft/vscode-internalbacklog#4024
  • Loading branch information
jrieken authored Apr 27, 2023
1 parent 92f910f commit 726b7f5
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 29 deletions.
10 changes: 9 additions & 1 deletion src/vs/editor/browser/editorBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ export interface IViewZone {
* This is relevant for wrapped lines.
*/
afterColumn?: number;

/**
* If the `afterColumn` has multiple view columns, the affinity specifies which one to use. Defaults to `none`.
*/
afterColumnAffinity?: PositionAffinity;
/**
* Render the zone even when its line is hidden.
*/
showInHiddenAreas?: boolean;
/**
* Tiebreaker that is used when multiple view zones want to be after the same line.
* Defaults to `afterColumn` otherwise 10000;
*/
ordinal?: number;
/**
* Suppress mouse down events.
* If set, the editor will attach a mouse down listener to the view zone and .preventDefault on it.
Expand Down
9 changes: 2 additions & 7 deletions src/vs/editor/browser/viewParts/viewZones/viewZones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ export class ViewZones extends ViewPart {
// ---- end view event handlers

private _getZoneOrdinal(zone: IViewZone): number {

if (typeof zone.afterColumn !== 'undefined') {
return zone.afterColumn;
}

return 10000;
return zone.ordinal ?? zone.afterColumn ?? 10000;
}

private _computeWhitespaceProps(zone: IViewZone): IComputedViewZoneProps {
Expand Down Expand Up @@ -187,7 +182,7 @@ export class ViewZones extends ViewPart {
}

const viewPosition = this._context.viewModel.coordinatesConverter.convertModelPositionToViewPosition(zoneAfterModelPosition, zone.afterColumnAffinity);
const isVisible = this._context.viewModel.coordinatesConverter.modelPositionIsVisible(zoneBeforeModelPosition);
const isVisible = zone.showInHiddenAreas || this._context.viewModel.coordinatesConverter.modelPositionIsVisible(zoneBeforeModelPosition);
return {
isInHiddenArea: !isVisible,
afterViewLineNumber: viewPosition.lineNumber,
Expand Down
17 changes: 14 additions & 3 deletions src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export interface IOptions {
frameColor?: Color;
arrowColor?: Color;
keepEditorSelection?: boolean;

ordinal?: number;
showInHiddenAreas?: boolean;
}

export interface IStyles {
Expand All @@ -48,25 +51,31 @@ const defaultOptions: IOptions = {

const WIDGET_ID = 'vs.editor.contrib.zoneWidget';

export class ViewZoneDelegate implements IViewZone {
class ViewZoneDelegate implements IViewZone {

domNode: HTMLElement;
id: string = ''; // A valid zone id should be greater than 0
afterLineNumber: number;
afterColumn: number;
heightInLines: number;
readonly showInHiddenAreas: boolean | undefined;
readonly ordinal: number | undefined;

private readonly _onDomNodeTop: (top: number) => void;
private readonly _onComputedHeight: (height: number) => void;

constructor(domNode: HTMLElement, afterLineNumber: number, afterColumn: number, heightInLines: number,
onDomNodeTop: (top: number) => void,
onComputedHeight: (height: number) => void
onComputedHeight: (height: number) => void,
showInHiddenAreas: boolean | undefined,
ordinal: number | undefined
) {
this.domNode = domNode;
this.afterLineNumber = afterLineNumber;
this.afterColumn = afterColumn;
this.heightInLines = heightInLines;
this.showInHiddenAreas = showInHiddenAreas;
this.ordinal = ordinal;
this._onDomNodeTop = onDomNodeTop;
this._onComputedHeight = onComputedHeight;
}
Expand Down Expand Up @@ -388,7 +397,9 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider {
position.column,
heightInLines,
(top: number) => this._onViewZoneTop(top),
(height: number) => this._onViewZoneHeight(height)
(height: number) => this._onViewZoneHeight(height),
this.options.showInHiddenAreas,
this.options.ordinal
);
this._viewZone.id = accessor.addZone(this._viewZone);
this._overlayWidget = new OverlayWidgetDelegate(WIDGET_ID + this._viewZone.id, this.domNode);
Expand Down
9 changes: 9 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5045,6 +5045,15 @@ declare namespace monaco.editor {
* If the `afterColumn` has multiple view columns, the affinity specifies which one to use. Defaults to `none`.
*/
afterColumnAffinity?: PositionAffinity;
/**
* Render the zone even when its line is hidden.
*/
showInHiddenAreas?: boolean;
/**
* Tiebreaker that is used when multiple view zones want to be after the same line.
* Defaults to `afterColumn` otherwise 10000;
*/
ordinal?: number;
/**
* Suppress mouse down events.
* If set, the editor will attach a mouse down listener to the view zone and .preventDefault on it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,7 @@ export class InteractiveEditorController implements IEditorContribution {
const inputPromise = this._zone.getInput(wholeRange.getEndPosition(), placeholder, value, this._ctsRequest.token);

if (textModel0Changes && editMode === EditMode.LivePreview) {
const diffPosition = diffZone.getEndPositionForChanges(wholeRange, textModel0Changes);
if (diffPosition) {
const newInputPosition = diffPosition.delta(0, 1);
if (wholeRange.getEndPosition().isBefore(newInputPosition)) {
this._zone.updatePosition(newInputPosition);
}
}

diffZone.showDiff(
() => wholeRangeDecoration.getRange(0)!, // TODO@jrieken if it can be null it will be null
textModel0Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class InteractiveEditorDiffWidget extends ZoneWidget {
@IThemeService themeService: IThemeService,
@ILogService private readonly _logService: ILogService,
) {
super(editor, { showArrow: false, showFrame: false, isResizeable: false, isAccessible: true });
super(editor, { showArrow: false, showFrame: false, isResizeable: false, isAccessible: true, showInHiddenAreas: true, ordinal: 10000 + 1 });
super.create();

const diffContributions = EditorExtensionsRegistry
Expand Down Expand Up @@ -102,14 +102,6 @@ export class InteractiveEditorDiffWidget extends ZoneWidget {
throw new Error('not supported like this');
}

getEndPositionForChanges(range: Range, changes: LineRangeMapping[]): Position | undefined {
assertType(this.editor.hasModel());

const modified = this.editor.getModel();
const ranges = this._computeHiddenRanges(modified, range, changes);
return ranges?.anchor;
}

showDiff(range: () => Range, changes: LineRangeMapping[]): void {
assertType(this.editor.hasModel());
this._sessionStore.clear();
Expand Down Expand Up @@ -197,7 +189,7 @@ export class InteractiveEditorDiffWidget extends ZoneWidget {
lineRanges = lineRanges.filter(range => !range.isEmpty);
if (lineRanges.length === 0) {
// todo?
this._logService.debug(`[IE] diff NOTHING to hide for ${String(editor.getModel()?.uri)}`);
this._logService.debug(`[IE] diff NOTHING to hide for ${editor.getId()} with ${String(editor.getModel()?.uri)}`);
} else {
const ranges = lineRanges.map(r => new Range(r.startLineNumber, 1, r.endLineNumberExclusive - 1, 1));
editor.setHiddenAreas(ranges, InteractiveEditorDiffWidget._hideId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
@IInstantiationService private readonly _instaService: IInstantiationService,
@IContextKeyService contextKeyService: IContextKeyService,
) {
super(editor, { showFrame: false, showArrow: false, isAccessible: true, className: 'interactive-editor-widget', keepEditorSelection: true });
super(editor, { showFrame: false, showArrow: false, isAccessible: true, className: 'interactive-editor-widget', keepEditorSelection: true, showInHiddenAreas: true, ordinal: 10000 + 3 });

this._ctxVisible = CTX_INTERACTIVE_EDITOR_VISIBLE.bindTo(contextKeyService);
this._ctxCursorPosition = CTX_INTERACTIVE_EDITOR_OUTER_CURSOR_POSITION.bindTo(contextKeyService);
Expand Down

0 comments on commit 726b7f5

Please sign in to comment.