Skip to content

Commit

Permalink
joh/hollow ladybug (microsoft#168978)
Browse files Browse the repository at this point in the history
* focus and select editor when clicking sticky scroll line

* 💄
  • Loading branch information
jrieken authored and mustard-mh committed Dec 14, 2022
1 parent 2abaab8 commit 5333e5c
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/vs/editor/contrib/stickyScroll/browser/stickyScrollWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Position } from 'vs/editor/common/core/position';
import { ClickLinkGesture } from 'vs/editor/contrib/gotoSymbol/browser/link/clickLinkGesture';
import { getDefinitionsAtPosition } from 'vs/editor/contrib/gotoSymbol/browser/goToSymbol';
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { Location } from 'vs/editor/common/languages';
import { goToDefinitionWithLocation } from 'vs/editor/contrib/inlayHints/browser/inlayHintsLocations';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
Expand Down Expand Up @@ -42,7 +41,6 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
private readonly _rootDomNode: HTMLElement = document.createElement('div');
private readonly _disposableStore = this._register(new DisposableStore());

private _lineHeight: number;
private _lineNumbers: number[] = [];
private _lastLineRelativePosition: number = 0;
private _hoverOnLine: number = -1;
Expand All @@ -62,13 +60,6 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
this._rootDomNode.classList.toggle('peek', _editor instanceof EmbeddedCodeEditorWidget);
this._rootDomNode.style.width = `${this._layoutInfo.width - this._layoutInfo.minimap.minimapCanvasOuterWidth - this._layoutInfo.verticalScrollbarWidth}px`;

this._lineHeight = this._editor.getOption(EditorOption.lineHeight);
this._register(this._editor.onDidChangeConfiguration(e => {
if (e.hasChanged(EditorOption.lineHeight)) {
this._lineHeight = this._editor.getOption(EditorOption.lineHeight);
}

}));
this._register(this._updateLinkGesture());
}

Expand Down Expand Up @@ -148,10 +139,14 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
if (this._candidateDefinitionsLength > 1) {
this._editor.revealPosition({ lineNumber: this._hoverOnLine, column: 1 });
}
this._instaService.invokeFunction(goToDefinitionWithLocation, e, this._editor as IActiveCodeEditor, { uri: this._editor.getModel()!.uri, range: this._stickyRangeProjectedOnEditor } as Location);
this._instaService.invokeFunction(goToDefinitionWithLocation, e, this._editor as IActiveCodeEditor, { uri: this._editor.getModel()!.uri, range: this._stickyRangeProjectedOnEditor! });

} else if (!e.isRightClick) {
// Normal click
this._editor.revealPosition({ lineNumber: this._hoverOnLine, column: 1 });
const position = { lineNumber: this._hoverOnLine, column: this._hoverOnColumn };
this._editor.revealPosition(position);
this._editor.setSelection(Range.fromPositions(position));
this._editor.focus();
}
}));
return linkGestureStore;
Expand Down Expand Up @@ -179,7 +174,7 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
this._renderRootNode();
}

private _getChildNode(index: number, line: number): HTMLElement {
private _renderChildNode(index: number, line: number): HTMLElement {

const child = document.createElement('div');
const viewModel = this._editor._getViewModel();
Expand All @@ -198,14 +193,13 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
actualInlineDecorations = [];
}

const renderLineInput: RenderLineInput =
new RenderLineInput(true, true, lineRenderingData.content,
lineRenderingData.continuesWithWrappedLine,

lineRenderingData.isBasicASCII, lineRenderingData.containsRTL, 0,
lineRenderingData.tokens, actualInlineDecorations,
lineRenderingData.tabSize, lineRenderingData.startVisibleColumn,
1, 1, 1, 500, 'none', true, true, null);
const renderLineInput: RenderLineInput = new RenderLineInput(true, true, lineRenderingData.content,
lineRenderingData.continuesWithWrappedLine,
lineRenderingData.isBasicASCII, lineRenderingData.containsRTL, 0,
lineRenderingData.tokens, actualInlineDecorations,
lineRenderingData.tabSize, lineRenderingData.startVisibleColumn,
1, 1, 1, 500, 'none', true, true, null
);

const sb = new StringBuilder(2000);
renderViewLine(renderLineInput, sb);
Expand Down Expand Up @@ -285,10 +279,10 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
return;
}
for (const [index, line] of this._lineNumbers.entries()) {
this._rootDomNode.appendChild(this._getChildNode(index, line));
this._rootDomNode.appendChild(this._renderChildNode(index, line));
}

const widgetHeight: number = this._lineNumbers.length * this._lineHeight + this._lastLineRelativePosition;
const editorLineHeight = this._editor.getOption(EditorOption.lineHeight);
const widgetHeight: number = this._lineNumbers.length * editorLineHeight + this._lastLineRelativePosition;
this._rootDomNode.style.height = widgetHeight.toString() + 'px';
const minimapSide = this._editor.getOption(EditorOption.minimap).side;
if (minimapSide === 'left') {
Expand Down

0 comments on commit 5333e5c

Please sign in to comment.