Skip to content

Commit 726b7f5

Browse files
authored
enable live preview for last line of document. for that... (microsoft#181029)
- 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
1 parent 92f910f commit 726b7f5

File tree

7 files changed

+38
-29
lines changed

7 files changed

+38
-29
lines changed

src/vs/editor/browser/editorBrowser.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ export interface IViewZone {
3838
* This is relevant for wrapped lines.
3939
*/
4040
afterColumn?: number;
41-
4241
/**
4342
* If the `afterColumn` has multiple view columns, the affinity specifies which one to use. Defaults to `none`.
4443
*/
4544
afterColumnAffinity?: PositionAffinity;
45+
/**
46+
* Render the zone even when its line is hidden.
47+
*/
48+
showInHiddenAreas?: boolean;
49+
/**
50+
* Tiebreaker that is used when multiple view zones want to be after the same line.
51+
* Defaults to `afterColumn` otherwise 10000;
52+
*/
53+
ordinal?: number;
4654
/**
4755
* Suppress mouse down events.
4856
* If set, the editor will attach a mouse down listener to the view zone and .preventDefault on it.

src/vs/editor/browser/viewParts/viewZones/viewZones.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ export class ViewZones extends ViewPart {
137137
// ---- end view event handlers
138138

139139
private _getZoneOrdinal(zone: IViewZone): number {
140-
141-
if (typeof zone.afterColumn !== 'undefined') {
142-
return zone.afterColumn;
143-
}
144-
145-
return 10000;
140+
return zone.ordinal ?? zone.afterColumn ?? 10000;
146141
}
147142

148143
private _computeWhitespaceProps(zone: IViewZone): IComputedViewZoneProps {
@@ -187,7 +182,7 @@ export class ViewZones extends ViewPart {
187182
}
188183

189184
const viewPosition = this._context.viewModel.coordinatesConverter.convertModelPositionToViewPosition(zoneAfterModelPosition, zone.afterColumnAffinity);
190-
const isVisible = this._context.viewModel.coordinatesConverter.modelPositionIsVisible(zoneBeforeModelPosition);
185+
const isVisible = zone.showInHiddenAreas || this._context.viewModel.coordinatesConverter.modelPositionIsVisible(zoneBeforeModelPosition);
191186
return {
192187
isInHiddenArea: !isVisible,
193188
afterViewLineNumber: viewPosition.lineNumber,

src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface IOptions {
2828
frameColor?: Color;
2929
arrowColor?: Color;
3030
keepEditorSelection?: boolean;
31+
32+
ordinal?: number;
33+
showInHiddenAreas?: boolean;
3134
}
3235

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

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

51-
export class ViewZoneDelegate implements IViewZone {
54+
class ViewZoneDelegate implements IViewZone {
5255

5356
domNode: HTMLElement;
5457
id: string = ''; // A valid zone id should be greater than 0
5558
afterLineNumber: number;
5659
afterColumn: number;
5760
heightInLines: number;
61+
readonly showInHiddenAreas: boolean | undefined;
62+
readonly ordinal: number | undefined;
5863

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

6267
constructor(domNode: HTMLElement, afterLineNumber: number, afterColumn: number, heightInLines: number,
6368
onDomNodeTop: (top: number) => void,
64-
onComputedHeight: (height: number) => void
69+
onComputedHeight: (height: number) => void,
70+
showInHiddenAreas: boolean | undefined,
71+
ordinal: number | undefined
6572
) {
6673
this.domNode = domNode;
6774
this.afterLineNumber = afterLineNumber;
6875
this.afterColumn = afterColumn;
6976
this.heightInLines = heightInLines;
77+
this.showInHiddenAreas = showInHiddenAreas;
78+
this.ordinal = ordinal;
7079
this._onDomNodeTop = onDomNodeTop;
7180
this._onComputedHeight = onComputedHeight;
7281
}
@@ -388,7 +397,9 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider {
388397
position.column,
389398
heightInLines,
390399
(top: number) => this._onViewZoneTop(top),
391-
(height: number) => this._onViewZoneHeight(height)
400+
(height: number) => this._onViewZoneHeight(height),
401+
this.options.showInHiddenAreas,
402+
this.options.ordinal
392403
);
393404
this._viewZone.id = accessor.addZone(this._viewZone);
394405
this._overlayWidget = new OverlayWidgetDelegate(WIDGET_ID + this._viewZone.id, this.domNode);

src/vs/monaco.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5045,6 +5045,15 @@ declare namespace monaco.editor {
50455045
* If the `afterColumn` has multiple view columns, the affinity specifies which one to use. Defaults to `none`.
50465046
*/
50475047
afterColumnAffinity?: PositionAffinity;
5048+
/**
5049+
* Render the zone even when its line is hidden.
5050+
*/
5051+
showInHiddenAreas?: boolean;
5052+
/**
5053+
* Tiebreaker that is used when multiple view zones want to be after the same line.
5054+
* Defaults to `afterColumn` otherwise 10000;
5055+
*/
5056+
ordinal?: number;
50485057
/**
50495058
* Suppress mouse down events.
50505059
* If set, the editor will attach a mouse down listener to the view zone and .preventDefault on it.

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,7 @@ export class InteractiveEditorController implements IEditorContribution {
487487
const inputPromise = this._zone.getInput(wholeRange.getEndPosition(), placeholder, value, this._ctsRequest.token);
488488

489489
if (textModel0Changes && editMode === EditMode.LivePreview) {
490-
const diffPosition = diffZone.getEndPositionForChanges(wholeRange, textModel0Changes);
491-
if (diffPosition) {
492-
const newInputPosition = diffPosition.delta(0, 1);
493-
if (wholeRange.getEndPosition().isBefore(newInputPosition)) {
494-
this._zone.updatePosition(newInputPosition);
495-
}
496-
}
490+
497491
diffZone.showDiff(
498492
() => wholeRangeDecoration.getRange(0)!, // TODO@jrieken if it can be null it will be null
499493
textModel0Changes

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorDiffWidget.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class InteractiveEditorDiffWidget extends ZoneWidget {
4141
@IThemeService themeService: IThemeService,
4242
@ILogService private readonly _logService: ILogService,
4343
) {
44-
super(editor, { showArrow: false, showFrame: false, isResizeable: false, isAccessible: true });
44+
super(editor, { showArrow: false, showFrame: false, isResizeable: false, isAccessible: true, showInHiddenAreas: true, ordinal: 10000 + 1 });
4545
super.create();
4646

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

105-
getEndPositionForChanges(range: Range, changes: LineRangeMapping[]): Position | undefined {
106-
assertType(this.editor.hasModel());
107-
108-
const modified = this.editor.getModel();
109-
const ranges = this._computeHiddenRanges(modified, range, changes);
110-
return ranges?.anchor;
111-
}
112-
113105
showDiff(range: () => Range, changes: LineRangeMapping[]): void {
114106
assertType(this.editor.hasModel());
115107
this._sessionStore.clear();
@@ -197,7 +189,7 @@ export class InteractiveEditorDiffWidget extends ZoneWidget {
197189
lineRanges = lineRanges.filter(range => !range.isEmpty);
198190
if (lineRanges.length === 0) {
199191
// todo?
200-
this._logService.debug(`[IE] diff NOTHING to hide for ${String(editor.getModel()?.uri)}`);
192+
this._logService.debug(`[IE] diff NOTHING to hide for ${editor.getId()} with ${String(editor.getModel()?.uri)}`);
201193
} else {
202194
const ranges = lineRanges.map(r => new Range(r.startLineNumber, 1, r.endLineNumberExclusive - 1, 1));
203195
editor.setHiddenAreas(ranges, InteractiveEditorDiffWidget._hideId);

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
499499
@IInstantiationService private readonly _instaService: IInstantiationService,
500500
@IContextKeyService contextKeyService: IContextKeyService,
501501
) {
502-
super(editor, { showFrame: false, showArrow: false, isAccessible: true, className: 'interactive-editor-widget', keepEditorSelection: true });
502+
super(editor, { showFrame: false, showArrow: false, isAccessible: true, className: 'interactive-editor-widget', keepEditorSelection: true, showInHiddenAreas: true, ordinal: 10000 + 3 });
503503

504504
this._ctxVisible = CTX_INTERACTIVE_EDITOR_VISIBLE.bindTo(contextKeyService);
505505
this._ctxCursorPosition = CTX_INTERACTIVE_EDITOR_OUTER_CURSOR_POSITION.bindTo(contextKeyService);

0 commit comments

Comments
 (0)