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

Add selection highlight decorations to minimap #80596

Merged
merged 4 commits into from
Sep 11, 2019

Conversation

RMacfarlane
Copy link
Contributor

@RMacfarlane RMacfarlane commented Sep 9, 2019

For #21404

This adds minimap decorations matching the current editor selections, and introduces a minimap.selectionHighlight theme color.

Screen Shot 2019-09-09 at 4 31 01 PM

@RMacfarlane RMacfarlane self-assigned this Sep 9, 2019
@RMacfarlane RMacfarlane requested a review from alexdima September 9, 2019 23:22
Copy link
Member

@alexdima alexdima left a comment

Choose a reason for hiding this comment

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

This is implemented in a very smart way, without touching any editor rendering code, but maintaining N decorations in sync with the N editor selections is IMHO an overkill solution for this problem. There could be cases where there are thousands of selections and adding/removing/updating all of these decorations is IMHO not efficient. IMHO it is possible to implement this directly in the minimap and limit the performance cost of rendering to only the visible area of the minimap (by intersecting it with the selections...)

I suggest instead that the minimap directly paints the selection. The minimap can immediately read the selection every time it changes by adding a new listener here after the configuration change listener:

	public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
		this._selections = e.selections;
		return true;
	}

The minimap can capture the view selections in a field and then use the stored selections in the renderDecorations method. In that method, you can loop also over selections and invoke renderDecorationOnLine... I think this could be doable only with minor changes to renderDecorationOnLine to allow a range and a color to be passed in instead of a ViewModelDecoration instance.

@RMacfarlane
Copy link
Contributor Author

Nice, your proposal makes the code change very small! :)

Copy link
Member

@alexdima alexdima left a comment

Choose a reason for hiding this comment

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

👍 Looks great! I just left a couple of small suggestions ...

@@ -453,6 +455,8 @@ export class Minimap extends ViewPart {
private _options: MinimapOptions;
private _lastRenderData: RenderData | null;
private _lastDecorations: ViewModelDecoration[] | undefined;
private _selections: Selection[] = [];
private _selectionColor: Color | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

small nitpick: please use null instead of undefined (to keep in spirit the existing code style)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, in this case the undefined is from the return type of getColor, so will leave as is

// Only bother calling render if decorations are currently shown
this._renderDecorations = !!this._lastDecorations;
return !!this._lastDecorations;
this._renderDecorations = !!this._lastDecorations || !!this._selections.length;
Copy link
Member

Choose a reason for hiding this comment

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

this._selections.length is always >= 1 ... (the editor will always have at least 1 selection), so we might as well say this._renderDecorations = true;

@RMacfarlane
Copy link
Contributor Author

Thanks for the review! Addressed feedback, merging this in now.

@RMacfarlane RMacfarlane merged commit 67dc534 into master Sep 11, 2019
@RMacfarlane RMacfarlane deleted the rmacfarlane/selectionDecorations branch September 11, 2019 17:06
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 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