debt - make editor smart select a "real" editor option

This commit is contained in:
Johannes Rieken 2020-11-02 15:23:43 +01:00
parent 9d936d51f3
commit 8600d333fc
4 changed files with 110 additions and 79 deletions

View file

@ -370,6 +370,10 @@ export interface IEditorOptions {
* Suggest options.
*/
suggest?: ISuggestOptions;
/**
* Smart select opptions;
*/
smartSelect?: ISmartSelectOptions;
/**
*
*/
@ -3430,6 +3434,44 @@ class EditorSuggest extends BaseEditorOption<EditorOption.suggest, InternalSugge
//#endregion
//#region smart select
export interface ISmartSelectOptions {
selectLeadingAndTrailingWhitespace?: boolean
}
export type SmartSelectOptions = Readonly<Required<ISmartSelectOptions>>;
class SmartSelect extends BaseEditorOption<EditorOption.smartSelect, SmartSelectOptions> {
constructor() {
super(
EditorOption.smartSelect, 'smartSelect',
{
selectLeadingAndTrailingWhitespace: true
},
{
'editor.smartSelect.selectLeadingAndTrailingWhitespace': {
description: nls.localize('selectLeadingAndTrailingWhitespace', "Whether leading and trailing whitespace should always be selected."),
default: true,
type: 'boolean'
}
}
);
}
public validate(input: any): Readonly<Required<ISmartSelectOptions>> {
if (!input || typeof input !== 'object') {
return this.defaultValue;
}
return {
selectLeadingAndTrailingWhitespace: EditorBooleanOption.boolean((input as ISmartSelectOptions).selectLeadingAndTrailingWhitespace, this.defaultValue.selectLeadingAndTrailingWhitespace)
};
}
}
//#endregion
//#region tabFocusMode
class EditorTabFocusMode extends ComputedEditorOption<EditorOption.tabFocusMode, boolean> {
@ -3646,6 +3688,7 @@ export const enum EditorOption {
showFoldingControls,
showUnused,
snippetSuggestions,
smartSelect,
smoothScrolling,
stopRenderingLineAfter,
suggest,
@ -4165,6 +4208,7 @@ export const EditorOptions = {
description: nls.localize('snippetSuggestions', "Controls whether snippets are shown with other suggestions and how they are sorted.")
}
)),
smartSelect: register(new SmartSelect()),
smoothScrolling: register(new EditorBooleanOption(
EditorOption.smoothScrolling, 'smoothScrolling', false,
{ description: nls.localize('smoothScrolling', "Controls whether the editor will scroll using an animation.") }

View file

@ -261,31 +261,32 @@ export enum EditorOption {
showFoldingControls = 91,
showUnused = 92,
snippetSuggestions = 93,
smoothScrolling = 94,
stopRenderingLineAfter = 95,
suggest = 96,
suggestFontSize = 97,
suggestLineHeight = 98,
suggestOnTriggerCharacters = 99,
suggestSelection = 100,
tabCompletion = 101,
tabIndex = 102,
unusualLineTerminators = 103,
useTabStops = 104,
wordSeparators = 105,
wordWrap = 106,
wordWrapBreakAfterCharacters = 107,
wordWrapBreakBeforeCharacters = 108,
wordWrapColumn = 109,
wordWrapMinified = 110,
wrappingIndent = 111,
wrappingStrategy = 112,
showDeprecated = 113,
editorClassName = 114,
pixelRatio = 115,
tabFocusMode = 116,
layoutInfo = 117,
wrappingInfo = 118
smartSelect = 94,
smoothScrolling = 95,
stopRenderingLineAfter = 96,
suggest = 97,
suggestFontSize = 98,
suggestLineHeight = 99,
suggestOnTriggerCharacters = 100,
suggestSelection = 101,
tabCompletion = 102,
tabIndex = 103,
unusualLineTerminators = 104,
useTabStops = 105,
wordSeparators = 106,
wordWrap = 107,
wordWrapBreakAfterCharacters = 108,
wordWrapBreakBeforeCharacters = 109,
wordWrapColumn = 110,
wordWrapMinified = 111,
wrappingIndent = 112,
wrappingStrategy = 113,
showDeprecated = 114,
editorClassName = 115,
pixelRatio = 116,
tabFocusMode = 117,
layoutInfo = 118,
wrappingInfo = 119
}
/**

View file

@ -23,9 +23,7 @@ import { WordSelectionRangeProvider } from 'vs/editor/contrib/smartSelect/wordSe
import { BracketSelectionRangeProvider } from 'vs/editor/contrib/smartSelect/bracketSelections';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { onUnexpectedExternalError } from 'vs/base/common/errors';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfigurationService';
import { ConfigurationScope, Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
class SelectionRanges {
@ -56,18 +54,11 @@ class SmartSelectController implements IEditorContribution {
return editor.getContribution<SmartSelectController>(SmartSelectController.ID);
}
private readonly _editor: ICodeEditor;
private _state?: SelectionRanges[];
private _selectionListener?: IDisposable;
private _ignoreSelection: boolean = false;
constructor(
editor: ICodeEditor,
@ITextResourceConfigurationService private readonly _configService: ITextResourceConfigurationService,
) {
this._editor = editor;
}
constructor(private readonly _editor: ICodeEditor) { }
dispose(): void {
this._selectionListener?.dispose();
@ -90,9 +81,7 @@ class SmartSelectController implements IEditorContribution {
if (!this._state) {
const selectLeadingAndTrailingWhitespace = this._configService.getValue<boolean>(model.uri, 'editor.smartSelect.selectLeadingAndTrailingWhitespace') ?? true;
promise = provideSelectionRanges(model, selections.map(s => s.getPosition()), { selectLeadingAndTrailingWhitespace }, CancellationToken.None).then(ranges => {
promise = provideSelectionRanges(model, selections.map(s => s.getPosition()), this._editor.getOption(EditorOption.smartSelect), CancellationToken.None).then(ranges => {
if (!arrays.isNonEmptyArray(ranges) || ranges.length !== selections.length) {
// invalid result
return;
@ -186,21 +175,6 @@ class GrowSelectionAction extends AbstractSmartSelect {
}
}
//todo@jrieken use proper editor config instead. however, to keep the number
// of changes low use the quick config definition
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
id: 'editor',
properties: {
'editor.smartSelect.selectLeadingAndTrailingWhitespace': {
scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,
description: nls.localize('selectLeadingAndTrailingWhitespace', "Weather leading and trailing whitespace should always be selected."),
default: true,
type: 'boolean'
}
}
});
// renamed command id
CommandsRegistry.registerCommandAlias('editor.action.smartSelect.grow', 'editor.action.smartSelect.expand');

62
src/vs/monaco.d.ts vendored
View file

@ -2909,6 +2909,10 @@ declare namespace monaco.editor {
* Suggest options.
*/
suggest?: ISuggestOptions;
/**
* Smart select opptions;
*/
smartSelect?: ISmartSelectOptions;
/**
*
*/
@ -3821,6 +3825,12 @@ declare namespace monaco.editor {
export type InternalSuggestOptions = Readonly<Required<ISuggestOptions>>;
export interface ISmartSelectOptions {
selectLeadingAndTrailingWhitespace?: boolean;
}
export type SmartSelectOptions = Readonly<Required<ISmartSelectOptions>>;
/**
* Describes how to indent wrapped lines.
*/
@ -3945,31 +3955,32 @@ declare namespace monaco.editor {
showFoldingControls = 91,
showUnused = 92,
snippetSuggestions = 93,
smoothScrolling = 94,
stopRenderingLineAfter = 95,
suggest = 96,
suggestFontSize = 97,
suggestLineHeight = 98,
suggestOnTriggerCharacters = 99,
suggestSelection = 100,
tabCompletion = 101,
tabIndex = 102,
unusualLineTerminators = 103,
useTabStops = 104,
wordSeparators = 105,
wordWrap = 106,
wordWrapBreakAfterCharacters = 107,
wordWrapBreakBeforeCharacters = 108,
wordWrapColumn = 109,
wordWrapMinified = 110,
wrappingIndent = 111,
wrappingStrategy = 112,
showDeprecated = 113,
editorClassName = 114,
pixelRatio = 115,
tabFocusMode = 116,
layoutInfo = 117,
wrappingInfo = 118
smartSelect = 94,
smoothScrolling = 95,
stopRenderingLineAfter = 96,
suggest = 97,
suggestFontSize = 98,
suggestLineHeight = 99,
suggestOnTriggerCharacters = 100,
suggestSelection = 101,
tabCompletion = 102,
tabIndex = 103,
unusualLineTerminators = 104,
useTabStops = 105,
wordSeparators = 106,
wordWrap = 107,
wordWrapBreakAfterCharacters = 108,
wordWrapBreakBeforeCharacters = 109,
wordWrapColumn = 110,
wordWrapMinified = 111,
wrappingIndent = 112,
wrappingStrategy = 113,
showDeprecated = 114,
editorClassName = 115,
pixelRatio = 116,
tabFocusMode = 117,
layoutInfo = 118,
wrappingInfo = 119
}
export const EditorOptions: {
acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
@ -4067,6 +4078,7 @@ declare namespace monaco.editor {
showUnused: IEditorOption<EditorOption.showUnused, boolean>;
showDeprecated: IEditorOption<EditorOption.showDeprecated, boolean>;
snippetSuggestions: IEditorOption<EditorOption.snippetSuggestions, 'none' | 'top' | 'bottom' | 'inline'>;
smartSelect: IEditorOption<EditorOption.smartSelect, any>;
smoothScrolling: IEditorOption<EditorOption.smoothScrolling, boolean>;
stopRenderingLineAfter: IEditorOption<EditorOption.stopRenderingLineAfter, number>;
suggest: IEditorOption<EditorOption.suggest, InternalSuggestOptions>;