提交 5c96e9fe 编写于 作者: A Alex Dima

Fixes #47660: Trigger hover even when the mouse is very close to the content text

上级 12e96793
...@@ -35,6 +35,7 @@ export interface IMarginData { ...@@ -35,6 +35,7 @@ export interface IMarginData {
export interface IEmptyContentData { export interface IEmptyContentData {
isAfterLines: boolean; isAfterLines: boolean;
horizontalDistanceToText?: number;
} }
interface IETextRange { interface IETextRange {
...@@ -415,7 +416,13 @@ class HitTestRequest extends BareHitTestRequest { ...@@ -415,7 +416,13 @@ class HitTestRequest extends BareHitTestRequest {
} }
const EMPTY_CONTENT_AFTER_LINES: IEmptyContentData = { isAfterLines: true }; const EMPTY_CONTENT_AFTER_LINES: IEmptyContentData = { isAfterLines: true };
const EMPTY_CONTENT_IN_LINES: IEmptyContentData = { isAfterLines: false };
function createEmptyContentDataInLines(horizontalDistanceToText: number): IEmptyContentData {
return {
isAfterLines: false,
horizontalDistanceToText: horizontalDistanceToText
};
}
export class MouseTargetFactory { export class MouseTargetFactory {
...@@ -639,7 +646,9 @@ export class MouseTargetFactory { ...@@ -639,7 +646,9 @@ export class MouseTargetFactory {
if (ElementPath.isStrictChildOfViewLines(request.targetPath)) { if (ElementPath.isStrictChildOfViewLines(request.targetPath)) {
const lineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset); const lineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset);
if (ctx.model.getLineLength(lineNumber) === 0) { if (ctx.model.getLineLength(lineNumber) === 0) {
return request.fulfill(MouseTargetType.CONTENT_EMPTY, new Position(lineNumber, 1), void 0, EMPTY_CONTENT_IN_LINES); const lineWidth = ctx.getLineWidth(lineNumber);
const detail = createEmptyContentDataInLines(request.mouseContentHorizontalOffset - lineWidth);
return request.fulfill(MouseTargetType.CONTENT_EMPTY, new Position(lineNumber, 1), void 0, detail);
} }
} }
...@@ -713,9 +722,11 @@ export class MouseTargetFactory { ...@@ -713,9 +722,11 @@ export class MouseTargetFactory {
if (request.mouseContentHorizontalOffset > lineWidth) { if (request.mouseContentHorizontalOffset > lineWidth) {
if (browser.isEdge && pos.column === 1) { if (browser.isEdge && pos.column === 1) {
// See https://github.com/Microsoft/vscode/issues/10875 // See https://github.com/Microsoft/vscode/issues/10875
return request.fulfill(MouseTargetType.CONTENT_EMPTY, new Position(lineNumber, ctx.model.getLineMaxColumn(lineNumber)), void 0, EMPTY_CONTENT_IN_LINES); const detail = createEmptyContentDataInLines(request.mouseContentHorizontalOffset - lineWidth);
return request.fulfill(MouseTargetType.CONTENT_EMPTY, new Position(lineNumber, ctx.model.getLineMaxColumn(lineNumber)), void 0, detail);
} }
return request.fulfill(MouseTargetType.CONTENT_EMPTY, pos, void 0, EMPTY_CONTENT_IN_LINES); const detail = createEmptyContentDataInLines(request.mouseContentHorizontalOffset - lineWidth);
return request.fulfill(MouseTargetType.CONTENT_EMPTY, pos, void 0, detail);
} }
const visibleRange = ctx.visibleRangeForPosition2(lineNumber, column); const visibleRange = ctx.visibleRangeForPosition2(lineNumber, column);
......
...@@ -23,6 +23,7 @@ import { registerThemingParticipant, IThemeService } from 'vs/platform/theme/com ...@@ -23,6 +23,7 @@ import { registerThemingParticipant, IThemeService } from 'vs/platform/theme/com
import { editorHoverHighlight, editorHoverBackground, editorHoverBorder, textLinkForeground, textCodeBlockBackground } from 'vs/platform/theme/common/colorRegistry'; import { editorHoverHighlight, editorHoverBackground, editorHoverBorder, textLinkForeground, textCodeBlockBackground } from 'vs/platform/theme/common/colorRegistry';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer'; import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
import { IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget';
export class ModesHoverController implements editorCommon.IEditorContribution { export class ModesHoverController implements editorCommon.IEditorContribution {
...@@ -114,8 +115,8 @@ export class ModesHoverController implements editorCommon.IEditorContribution { ...@@ -114,8 +115,8 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
} }
private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void { private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void {
var targetType = mouseEvent.target.type; let targetType = mouseEvent.target.type;
var stopKey = platform.isMacintosh ? 'metaKey' : 'ctrlKey'; let stopKey = platform.isMacintosh ? 'metaKey' : 'ctrlKey';
if (this._isMouseDown && this._hoverClicked && this.contentWidget.isColorPickerVisible()) { if (this._isMouseDown && this._hoverClicked && this.contentWidget.isColorPickerVisible()) {
return; return;
...@@ -131,6 +132,15 @@ export class ModesHoverController implements editorCommon.IEditorContribution { ...@@ -131,6 +132,15 @@ export class ModesHoverController implements editorCommon.IEditorContribution {
return; return;
} }
if (targetType === MouseTargetType.CONTENT_EMPTY) {
const epsilon = this._editor.getConfiguration().fontInfo.typicalHalfwidthCharacterWidth / 2;
const data = <IEmptyContentData>mouseEvent.target.detail;
if (data && !data.isAfterLines && typeof data.horizontalDistanceToText === 'number' && data.horizontalDistanceToText < epsilon) {
// Let hover kick in even when the mouse is technically in the empty area after a line, given the distance is small enough
targetType = MouseTargetType.CONTENT_TEXT;
}
}
if (this._editor.getConfiguration().contribInfo.hover && targetType === MouseTargetType.CONTENT_TEXT) { if (this._editor.getConfiguration().contribInfo.hover && targetType === MouseTargetType.CONTENT_TEXT) {
this.glyphWidget.hide(); this.glyphWidget.hide();
this.contentWidget.startShowingAt(mouseEvent.target.range, false); this.contentWidget.startShowingAt(mouseEvent.target.range, false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册