Fix output sizing for multiline evaluation result (#162101)

Fix output sizing for multiline evaluation resul
Fix #151768
This commit is contained in:
Rob Lourens 2022-09-27 21:09:30 -07:00 committed by GitHub
parent c2a2ad4f63
commit 7b7f5a0466
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -312,18 +312,21 @@ export class ReplDelegate extends CachedListVirtualDelegate<IReplElement> {
return super.getHeight(element);
}
/**
* With wordWrap enabled, this is an estimate. With wordWrap disabled, this is the real height that the list will use.
*/
protected estimateHeight(element: IReplElement, ignoreValueLength = false): number {
const lineHeight = this.replOptions.replConfiguration.lineHeight;
const countNumberOfLines = (str: string) => Math.max(1, (str && str.match(/\r\n|\n/g) || []).length);
const countNumberOfLines = (str: string) => str.match(/\n/g)?.length ?? 0;
const hasValue = (e: any): e is { value: string } => typeof e.value === 'string';
// Calculate a rough overestimation for the height
// For every 70 characters increase the number of lines needed beyond the first
if (hasValue(element) && !isNestedVariable(element)) {
const value = element.value;
const valueRows = countNumberOfLines(value) + (ignoreValueLength ? 0 : Math.floor(value.length / 70));
const valueRows = countNumberOfLines(value)
+ (ignoreValueLength ? 0 : Math.floor(value.length / 70)) // Make an estimate for wrapping
+ (element instanceof SimpleReplElement ? 0 : 1); // A SimpleReplElement ends in \n if it's a complete line
return valueRows * lineHeight;
return Math.max(valueRows, 1) * lineHeight;
}
return lineHeight;