Skip to content

Change terminal link hover widget position to be consistent#83175

Merged
Tyriar merged 8 commits intomicrosoft:masterfrom
jmbockhorst:link
Oct 25, 2019
Merged

Change terminal link hover widget position to be consistent#83175
Tyriar merged 8 commits intomicrosoft:masterfrom
jmbockhorst:link

Conversation

@jmbockhorst
Copy link
Contributor

The PR changes the terminal link tooltip position to be consistent with the rest of the editor. This is part of #78647, and is the first step for #77964.

Currently, the tooltip position is where the mouse position is, and it sometimes creates unexpected behaviors.

linkBefore

With the pull request, the tooltip position is based on where the link position is.

linkAfter

To do this, I had to change the terminalWidgetManager to render Widgets using bottom position, since the terminal is snapped to the bottom of the container and has no knowledge about the extra space at the top between the actual terminal and the container. Since link tooltips are the only thing I found that uses the terminalWidgetManager, I figured it would be okay. I also added a new parameter that controls whether or not the bottom position is to the top or bottom of the widget.

I tested it for both renderers and with increased letter spacing and line heights.

@Tyriar Tyriar added this to the October 2019 milestone Oct 23, 2019
@Tyriar Tyriar self-assigned this Oct 23, 2019
@jmbockhorst jmbockhorst changed the title Change link hover widget position to be consistent Change terminal link hover widget position to be consistent Oct 23, 2019
}

public showMessage(left: number, top: number, text: string): void {
public showMessage(left: number, bottom: number, text: string, positionIsTopOfWidget: boolean = false): void {
Copy link
Member

Choose a reason for hiding this comment

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

This could be a little nicer is bottom was renamed to y and we used something like this:

enum VerticalAlignment {
  Bottom,
  Top
}

let offsetRow = this._xterm.rows - location.start.row + 1;
let useTopPosition = false;

// Handle a link on the top row
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Handle a link on the top row
// Show the tooltip on the top of the next row to avoid obscuring the first row

Comment on lines 107 to 115
if (this._configHelper.config.rendererType === 'dom') {
const target = (e.target as HTMLElement);
this._widgetManager.showMessage(target.offsetLeft, target.offsetTop, this._getLinkHoverString());
const font = this._configHelper.getFont();
const charWidth = font.charWidth;
const charHeight = font.charHeight;

const leftPosition = (location.start.col - 1) * (charWidth! + (font.letterSpacing / window.devicePixelRatio));
const bottomPosition = offsetRow * (charHeight! * font.lineHeight);

this._widgetManager.showMessage(leftPosition, bottomPosition, this._getLinkHoverString(), useTopPosition);
Copy link
Member

Choose a reason for hiding this comment

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

Got it in this state with the dom renderer when zoomed in (ctrl/cmd++)

image

@jmbockhorst
Copy link
Contributor Author

Thanks for the feedback. I made the requested changes and fixed the issue when zoomed.

@Tyriar
Copy link
Member

Tyriar commented Oct 24, 2019

The bottom row doesn't get positions correctly:

image

this._domNode.style.bottom = `${Math.max(_y, WIDGET_HEIGHT) - WIDGET_HEIGHT}px`;
} else {
// Y position is to the bottom of the widget
this._domNode.style.bottom = `${Math.min(Math.max(_y, WIDGET_HEIGHT), _container.offsetHeight - WIDGET_HEIGHT)}px`;
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is the problem, we need the row height to be passed through and used for the very bottom row.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't actually want to check the max of _y and WIDGET_HEIGHT when y is to the bottom of the widget, since even y = 0 will still be in the viewport.

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

Works great, thanks 👍

@Tyriar Tyriar merged commit 342f812 into microsoft:master Oct 25, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants