Skip to content

Commit 7b7f5a0

Browse files
authored
Fix output sizing for multiline evaluation result (microsoft#162101)
Fix output sizing for multiline evaluation resul Fix microsoft#151768
1 parent c2a2ad4 commit 7b7f5a0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/vs/workbench/contrib/debug/browser/replViewer.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,21 @@ export class ReplDelegate extends CachedListVirtualDelegate<IReplElement> {
312312
return super.getHeight(element);
313313
}
314314

315+
/**
316+
* With wordWrap enabled, this is an estimate. With wordWrap disabled, this is the real height that the list will use.
317+
*/
315318
protected estimateHeight(element: IReplElement, ignoreValueLength = false): number {
316319
const lineHeight = this.replOptions.replConfiguration.lineHeight;
317-
const countNumberOfLines = (str: string) => Math.max(1, (str && str.match(/\r\n|\n/g) || []).length);
320+
const countNumberOfLines = (str: string) => str.match(/\n/g)?.length ?? 0;
318321
const hasValue = (e: any): e is { value: string } => typeof e.value === 'string';
319322

320-
// Calculate a rough overestimation for the height
321-
// For every 70 characters increase the number of lines needed beyond the first
322323
if (hasValue(element) && !isNestedVariable(element)) {
323324
const value = element.value;
324-
const valueRows = countNumberOfLines(value) + (ignoreValueLength ? 0 : Math.floor(value.length / 70));
325+
const valueRows = countNumberOfLines(value)
326+
+ (ignoreValueLength ? 0 : Math.floor(value.length / 70)) // Make an estimate for wrapping
327+
+ (element instanceof SimpleReplElement ? 0 : 1); // A SimpleReplElement ends in \n if it's a complete line
325328

326-
return valueRows * lineHeight;
329+
return Math.max(valueRows, 1) * lineHeight;
327330
}
328331

329332
return lineHeight;

0 commit comments

Comments
 (0)