Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing to define variable line heights #233110

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Allowing to define variable line heights #233110

wants to merge 45 commits into from

Conversation

aiday-mar
Copy link
Contributor

@aiday-mar aiday-mar commented Nov 5, 2024

fixes #147067

Decorations may affect line wrapping. For example, they make make the
text bold, or increase or decrease font size. This wasn’t originally
taken into account to calculate the the break offsets.
@aiday-mar aiday-mar self-assigned this Nov 5, 2024
@Johndot1
Copy link

Johndot1 commented Jan 7, 2025

Ey

@aiday-mar aiday-mar changed the title Exploration: implementing variable line heights Allowing to define variable line heights Jan 8, 2025
@aiday-mar aiday-mar requested a review from alexdima January 8, 2025 14:13
@aiday-mar aiday-mar marked this pull request as ready for review January 8, 2025 14:13
@aiday-mar aiday-mar enabled auto-merge (squash) January 8, 2025 14:13
@vs-code-engineering vs-code-engineering bot added this to the January 2025 milestone Jan 8, 2025
@aiday-mar aiday-mar removed request for jrieken and mjbvz January 8, 2025 15:05
Comment on lines +221 to +224
/**
* If set, the decoration will override the line height of the lines it spans. This can only increase the line height, not decrease it.
*/
lineHeight?: number | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: why can the line height only be increased?

@@ -97,6 +97,7 @@ export class LinesLayout {
private _lineHeight: number;
private _paddingTop: number;
private _paddingBottom: number;
private _specialLineHeights = new Map<number, number>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's implement this using a more performant data structure which makes things slow only when the feature is exercised. For example, for a file with 100K lines, getting the top position for line 99K will involve querying this _specialLineHeights map 99K times.

It also seems to me that we're not quite keeping this field up to date correctly. If I set a line height of 40 on a line 1000 and then press enter on the first line, will the _specialLineHeights be updated correctly to reflect the edit I did?

@@ -62,6 +62,7 @@ export class RenderLineInput {
public readonly renderWhitespace: RenderWhitespace;
public readonly renderControlCharacters: boolean;
public readonly fontLigatures: boolean;
public readonly lineHeight: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this field added if there are no usages?

@@ -47,6 +47,7 @@ export class ViewportData {
private readonly _model: IViewModel;

public readonly lineHeight: number;
public readonly specialLineHeights: Map<number, number>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add this field. Do not spread out the logic of the special line heights. Let's use a single way to get to it via this._context.viewLayout.getLineHeightForLineNumber

Comment on lines +611 to +616
private _lineHeightForLineNumber(lineNumber: number): number {
if (this._viewportData.specialLineHeights.has(lineNumber)) {
return this._viewportData.specialLineHeights.get(lineNumber)!;
}
return this._viewportData.lineHeight;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to feed in a getter for this data via a new ctor field if necessary. Please don't add the line heights to the viewport data.

/**
* The special line heights
*/
readonly specialLineHeights: Map<number, number>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also remove here


constructor(lineNumber: number, detail: string, injectedText: LineInjectedText[] | null) {
constructor(lineNumber: number, detail: string, injectedText: LineInjectedText[] | null, lineHeight: number | null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please use a new event and not overload the meaning of this one.

*/
export class ModelSpecialLineHeightChangedEvent {

public readonly changes: ModelRawLineChanged[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's transport the changes with a new data type, there is no need to reuse/enlarge ModelRawLineChanged and it will just confuse all users of the event.

Comment on lines +1776 to +1780
private _getLineHeightForLine(lineNumber: number): number | null {
const startOffset = this._buffer.getOffsetAt(lineNumber, 1);
const endOffset = startOffset + this._buffer.getLineLength(lineNumber);
return this._decorationsTree.getLineHeightInInterval(this, startOffset, endOffset, 0);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something not quite correct here. Line heights don't work quite like injected text, because we should allow for line heights of the same line to be different across different editors. For example, if a particular text model is shown in editor1 and editor2, we should allow that a particular line has a particular height in editor1 and a different height in editor2, since line height is a presentation option (which is arguably different than injected text). So I think the decoration ownerId should play a part in this method call, not quite sure who calls it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support variable line heights in the editor
4 participants