未验证 提交 5f58ff53 编写于 作者: A Alexandru Dima 提交者: GitHub

Merge pull request #53963 from 71/focus-on-hover

Added contrib extension to have focus follow mouse (fixes #25685).
......@@ -550,6 +550,10 @@ export interface IEditorOptions {
* Controls fading out of unused variables.
*/
showUnused?: boolean;
/**
* Controls whether editors should be focused on hover.
*/
focusOnHover?: boolean;
/**
* Controls whether to focus the inline editor in the peek widget by default.
* Defaults to false.
......@@ -3156,6 +3160,7 @@ export const enum EditorOption {
fastScrollSensitivity,
find,
fixedOverflowWidgets,
focusOnHover,
folding,
foldingStrategy,
foldingHighlight,
......@@ -3432,6 +3437,10 @@ export const EditorOptions = {
fixedOverflowWidgets: register(new EditorBooleanOption(
EditorOption.fixedOverflowWidgets, 'fixedOverflowWidgets', false,
)),
focusOnHover: register(new EditorBooleanOption(
EditorOption.focusOnHover, 'focusOnHover', false,
{ description: nls.localize('focusOnHover', "Controls whether editors should be focused when hovered.") }
)),
folding: register(new EditorBooleanOption(
EditorOption.folding, 'folding', true,
{ description: nls.localize('folding', "Controls whether the editor has code folding enabled.") }
......
......@@ -195,86 +195,87 @@ export enum EditorOption {
fastScrollSensitivity = 27,
find = 28,
fixedOverflowWidgets = 29,
folding = 30,
foldingStrategy = 31,
foldingHighlight = 32,
fontFamily = 33,
fontInfo = 34,
fontLigatures = 35,
fontSize = 36,
fontWeight = 37,
formatOnPaste = 38,
formatOnType = 39,
glyphMargin = 40,
gotoLocation = 41,
hideCursorInOverviewRuler = 42,
highlightActiveIndentGuide = 43,
hover = 44,
inDiffEditor = 45,
letterSpacing = 46,
lightbulb = 47,
lineDecorationsWidth = 48,
lineHeight = 49,
lineNumbers = 50,
lineNumbersMinChars = 51,
links = 52,
matchBrackets = 53,
minimap = 54,
mouseStyle = 55,
mouseWheelScrollSensitivity = 56,
mouseWheelZoom = 57,
multiCursorMergeOverlapping = 58,
multiCursorModifier = 59,
multiCursorPaste = 60,
occurrencesHighlight = 61,
overviewRulerBorder = 62,
overviewRulerLanes = 63,
parameterHints = 64,
peekWidgetDefaultFocus = 65,
quickSuggestions = 66,
quickSuggestionsDelay = 67,
readOnly = 68,
renderControlCharacters = 69,
renderIndentGuides = 70,
renderFinalNewline = 71,
renderLineHighlight = 72,
renderValidationDecorations = 73,
renderWhitespace = 74,
revealHorizontalRightPadding = 75,
roundedSelection = 76,
rulers = 77,
scrollbar = 78,
scrollBeyondLastColumn = 79,
scrollBeyondLastLine = 80,
selectionClipboard = 81,
selectionHighlight = 82,
selectOnLineNumbers = 83,
semanticHighlighting = 84,
showFoldingControls = 85,
showUnused = 86,
snippetSuggestions = 87,
smoothScrolling = 88,
stopRenderingLineAfter = 89,
suggest = 90,
suggestFontSize = 91,
suggestLineHeight = 92,
suggestOnTriggerCharacters = 93,
suggestSelection = 94,
tabCompletion = 95,
useTabStops = 96,
wordSeparators = 97,
wordWrap = 98,
wordWrapBreakAfterCharacters = 99,
wordWrapBreakBeforeCharacters = 100,
wordWrapColumn = 101,
wordWrapMinified = 102,
wrappingIndent = 103,
wrappingStrategy = 104,
editorClassName = 105,
pixelRatio = 106,
tabFocusMode = 107,
layoutInfo = 108,
wrappingInfo = 109
focusOnHover = 30,
folding = 31,
foldingStrategy = 32,
foldingHighlight = 33,
fontFamily = 34,
fontInfo = 35,
fontLigatures = 36,
fontSize = 37,
fontWeight = 38,
formatOnPaste = 39,
formatOnType = 40,
glyphMargin = 41,
gotoLocation = 42,
hideCursorInOverviewRuler = 43,
highlightActiveIndentGuide = 44,
hover = 45,
inDiffEditor = 46,
letterSpacing = 47,
lightbulb = 48,
lineDecorationsWidth = 49,
lineHeight = 50,
lineNumbers = 51,
lineNumbersMinChars = 52,
links = 53,
matchBrackets = 54,
minimap = 55,
mouseStyle = 56,
mouseWheelScrollSensitivity = 57,
mouseWheelZoom = 58,
multiCursorMergeOverlapping = 59,
multiCursorModifier = 60,
multiCursorPaste = 61,
occurrencesHighlight = 62,
overviewRulerBorder = 63,
overviewRulerLanes = 64,
parameterHints = 65,
peekWidgetDefaultFocus = 66,
quickSuggestions = 67,
quickSuggestionsDelay = 68,
readOnly = 69,
renderControlCharacters = 70,
renderIndentGuides = 71,
renderFinalNewline = 72,
renderLineHighlight = 73,
renderValidationDecorations = 74,
renderWhitespace = 75,
revealHorizontalRightPadding = 76,
roundedSelection = 77,
rulers = 78,
scrollbar = 79,
scrollBeyondLastColumn = 80,
scrollBeyondLastLine = 81,
selectionClipboard = 82,
selectionHighlight = 83,
selectOnLineNumbers = 84,
semanticHighlighting = 85,
showFoldingControls = 86,
showUnused = 87,
snippetSuggestions = 88,
smoothScrolling = 89,
stopRenderingLineAfter = 90,
suggest = 91,
suggestFontSize = 92,
suggestLineHeight = 93,
suggestOnTriggerCharacters = 94,
suggestSelection = 95,
tabCompletion = 96,
useTabStops = 97,
wordSeparators = 98,
wordWrap = 99,
wordWrapBreakAfterCharacters = 100,
wordWrapBreakBeforeCharacters = 101,
wordWrapColumn = 102,
wordWrapMinified = 103,
wrappingIndent = 104,
wrappingStrategy = 105,
editorClassName = 106,
pixelRatio = 107,
tabFocusMode = 108,
layoutInfo = 109,
wrappingInfo = 110
}
/**
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
export class FocusOnHoverController extends Disposable implements IEditorContribution {
public static readonly ID = 'editor.contrib.focusOnHover';
private _editorMouseMoveHandler: IDisposable | null;
constructor(private readonly _editor: ICodeEditor) {
super();
this._editorMouseMoveHandler = null;
this._hookEvents();
this._register(this._editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => {
if (e.hasChanged(EditorOption.focusOnHover)) {
this._unhookEvents();
this._hookEvents();
}
}));
}
private _hookEvents(): void {
if (this._editor.getOption(EditorOption.focusOnHover)) {
this._editorMouseMoveHandler = this._editor.onMouseMove(_ => this._onEditorMouseMove());
}
}
private _unhookEvents(): void {
if (this._editorMouseMoveHandler) {
this._editorMouseMoveHandler.dispose();
this._editorMouseMoveHandler = null;
}
}
private _onEditorMouseMove(): void {
if (!this._editor.hasTextFocus()) {
this._editor.focus();
}
}
public dispose(): void {
super.dispose();
this._unhookEvents();
}
}
registerEditorContribution(FocusOnHoverController.ID, FocusOnHoverController);
......@@ -19,6 +19,7 @@ import 'vs/editor/contrib/contextmenu/contextmenu';
import 'vs/editor/contrib/cursorUndo/cursorUndo';
import 'vs/editor/contrib/dnd/dnd';
import 'vs/editor/contrib/find/findController';
import 'vs/editor/contrib/focusOnHover/focusOnHover';
import 'vs/editor/contrib/folding/folding';
import 'vs/editor/contrib/fontZoom/fontZoom';
import 'vs/editor/contrib/format/formatActions';
......
......@@ -3030,6 +3030,10 @@ declare namespace monaco.editor {
* Controls fading out of unused variables.
*/
showUnused?: boolean;
/**
* Controls whether editors should be focused on hover.
*/
focusOnHover?: boolean;
/**
* Controls whether to focus the inline editor in the peek widget by default.
* Defaults to false.
......@@ -3725,86 +3729,87 @@ declare namespace monaco.editor {
fastScrollSensitivity = 27,
find = 28,
fixedOverflowWidgets = 29,
folding = 30,
foldingStrategy = 31,
foldingHighlight = 32,
fontFamily = 33,
fontInfo = 34,
fontLigatures = 35,
fontSize = 36,
fontWeight = 37,
formatOnPaste = 38,
formatOnType = 39,
glyphMargin = 40,
gotoLocation = 41,
hideCursorInOverviewRuler = 42,
highlightActiveIndentGuide = 43,
hover = 44,
inDiffEditor = 45,
letterSpacing = 46,
lightbulb = 47,
lineDecorationsWidth = 48,
lineHeight = 49,
lineNumbers = 50,
lineNumbersMinChars = 51,
links = 52,
matchBrackets = 53,
minimap = 54,
mouseStyle = 55,
mouseWheelScrollSensitivity = 56,
mouseWheelZoom = 57,
multiCursorMergeOverlapping = 58,
multiCursorModifier = 59,
multiCursorPaste = 60,
occurrencesHighlight = 61,
overviewRulerBorder = 62,
overviewRulerLanes = 63,
parameterHints = 64,
peekWidgetDefaultFocus = 65,
quickSuggestions = 66,
quickSuggestionsDelay = 67,
readOnly = 68,
renderControlCharacters = 69,
renderIndentGuides = 70,
renderFinalNewline = 71,
renderLineHighlight = 72,
renderValidationDecorations = 73,
renderWhitespace = 74,
revealHorizontalRightPadding = 75,
roundedSelection = 76,
rulers = 77,
scrollbar = 78,
scrollBeyondLastColumn = 79,
scrollBeyondLastLine = 80,
selectionClipboard = 81,
selectionHighlight = 82,
selectOnLineNumbers = 83,
semanticHighlighting = 84,
showFoldingControls = 85,
showUnused = 86,
snippetSuggestions = 87,
smoothScrolling = 88,
stopRenderingLineAfter = 89,
suggest = 90,
suggestFontSize = 91,
suggestLineHeight = 92,
suggestOnTriggerCharacters = 93,
suggestSelection = 94,
tabCompletion = 95,
useTabStops = 96,
wordSeparators = 97,
wordWrap = 98,
wordWrapBreakAfterCharacters = 99,
wordWrapBreakBeforeCharacters = 100,
wordWrapColumn = 101,
wordWrapMinified = 102,
wrappingIndent = 103,
wrappingStrategy = 104,
editorClassName = 105,
pixelRatio = 106,
tabFocusMode = 107,
layoutInfo = 108,
wrappingInfo = 109
focusOnHover = 30,
folding = 31,
foldingStrategy = 32,
foldingHighlight = 33,
fontFamily = 34,
fontInfo = 35,
fontLigatures = 36,
fontSize = 37,
fontWeight = 38,
formatOnPaste = 39,
formatOnType = 40,
glyphMargin = 41,
gotoLocation = 42,
hideCursorInOverviewRuler = 43,
highlightActiveIndentGuide = 44,
hover = 45,
inDiffEditor = 46,
letterSpacing = 47,
lightbulb = 48,
lineDecorationsWidth = 49,
lineHeight = 50,
lineNumbers = 51,
lineNumbersMinChars = 52,
links = 53,
matchBrackets = 54,
minimap = 55,
mouseStyle = 56,
mouseWheelScrollSensitivity = 57,
mouseWheelZoom = 58,
multiCursorMergeOverlapping = 59,
multiCursorModifier = 60,
multiCursorPaste = 61,
occurrencesHighlight = 62,
overviewRulerBorder = 63,
overviewRulerLanes = 64,
parameterHints = 65,
peekWidgetDefaultFocus = 66,
quickSuggestions = 67,
quickSuggestionsDelay = 68,
readOnly = 69,
renderControlCharacters = 70,
renderIndentGuides = 71,
renderFinalNewline = 72,
renderLineHighlight = 73,
renderValidationDecorations = 74,
renderWhitespace = 75,
revealHorizontalRightPadding = 76,
roundedSelection = 77,
rulers = 78,
scrollbar = 79,
scrollBeyondLastColumn = 80,
scrollBeyondLastLine = 81,
selectionClipboard = 82,
selectionHighlight = 83,
selectOnLineNumbers = 84,
semanticHighlighting = 85,
showFoldingControls = 86,
showUnused = 87,
snippetSuggestions = 88,
smoothScrolling = 89,
stopRenderingLineAfter = 90,
suggest = 91,
suggestFontSize = 92,
suggestLineHeight = 93,
suggestOnTriggerCharacters = 94,
suggestSelection = 95,
tabCompletion = 96,
useTabStops = 97,
wordSeparators = 98,
wordWrap = 99,
wordWrapBreakAfterCharacters = 100,
wordWrapBreakBeforeCharacters = 101,
wordWrapColumn = 102,
wordWrapMinified = 103,
wrappingIndent = 104,
wrappingStrategy = 105,
editorClassName = 106,
pixelRatio = 107,
tabFocusMode = 108,
layoutInfo = 109,
wrappingInfo = 110
}
export const EditorOptions: {
acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
......@@ -3837,6 +3842,7 @@ declare namespace monaco.editor {
fastScrollSensitivity: IEditorOption<EditorOption.fastScrollSensitivity, number>;
find: IEditorOption<EditorOption.find, EditorFindOptions>;
fixedOverflowWidgets: IEditorOption<EditorOption.fixedOverflowWidgets, boolean>;
focusOnHover: IEditorOption<EditorOption.focusOnHover, boolean>;
folding: IEditorOption<EditorOption.folding, boolean>;
foldingStrategy: IEditorOption<EditorOption.foldingStrategy, 'auto' | 'indentation'>;
foldingHighlight: IEditorOption<EditorOption.foldingHighlight, boolean>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册