Skip to content

Commit

Permalink
Fix #20768. seedSearchStringFromSelection is now an option.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed May 23, 2017
1 parent 87c24f2 commit 79be3ae
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Expand Up @@ -257,6 +257,11 @@ const editorConfiguration: IConfigurationNode = {
'default': EDITOR_DEFAULTS.viewInfo.minimap.maxColumn,
'description': nls.localize('minimap.maxColumn', "Limit the width of the minimap to render at most a certain number of columns")
},
'editor.find.seedSearchStringFromSelection': {
'type': 'boolean',
'default': EDITOR_DEFAULTS.contribInfo.find.seedSearchStringFromSelection,
'description': nls.localize('find.seedSearchStringFromSelection', "")
},
'editor.wordWrap': {
'type': 'string',
'enum': ['off', 'on', 'wordWrapColumn', 'bounded'],
Expand Down
42 changes: 42 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Expand Up @@ -74,6 +74,13 @@ export interface IEditorScrollbarOptions {
horizontalSliderSize?: number;
}

/**
* Configuration options for editor find widget
*/
export interface IEditorFindOptions {
seedSearchStringFromSelection?: boolean;
}

/**
* Configuration options for editor minimap
*/
Expand Down Expand Up @@ -186,6 +193,10 @@ export interface IEditorOptions {
* Control the behavior and rendering of the minimap.
*/
minimap?: IEditorMinimapOptions;
/**
* Control the behavior of the find widget.
*/
find?: IEditorFindOptions;
/**
* Display overflow widgets as `fixed`.
* Defaults to `false`.
Expand Down Expand Up @@ -672,6 +683,10 @@ export interface InternalEditorMinimapOptions {
readonly maxColumn: number;
}

export interface InternalEditorFindOptions {
readonly seedSearchStringFromSelection: boolean;
}

export interface EditorWrappingInfo {
readonly inDiffEditor: boolean;
readonly isDominatedByLongLines: boolean;
Expand Down Expand Up @@ -738,6 +753,7 @@ export interface EditorContribOptions {
readonly folding: boolean;
readonly showFoldingControls: 'always' | 'mouseover';
readonly matchBrackets: boolean;
readonly find: InternalEditorFindOptions;
}

/**
Expand Down Expand Up @@ -1004,6 +1020,16 @@ export class InternalEditorOptions {
return true;
}

/**
* @internal
*/

private static _equalFindOptions(a: InternalEditorFindOptions, b: InternalEditorFindOptions): boolean {
return (
a.seedSearchStringFromSelection === b.seedSearchStringFromSelection
);
}

/**
* @internal
*/
Expand Down Expand Up @@ -1048,6 +1074,7 @@ export class InternalEditorOptions {
&& a.folding === b.folding
&& a.showFoldingControls === b.showFoldingControls
&& a.matchBrackets === b.matchBrackets
&& this._equalFindOptions(a.find, b.find)
);
}

Expand Down Expand Up @@ -1413,6 +1440,16 @@ export class EditorOptionsValidator {
};
}

private static _santizeFindOpts(opts: IEditorFindOptions, defaults: InternalEditorFindOptions): InternalEditorFindOptions {
if (typeof opts !== 'object') {
return defaults;
}

return {
seedSearchStringFromSelection: _boolean(opts.seedSearchStringFromSelection, defaults.seedSearchStringFromSelection)
};
}

private static _sanitizeViewInfo(opts: IEditorOptions, defaults: InternalEditorViewOptions): InternalEditorViewOptions {

let rulers: number[] = [];
Expand Down Expand Up @@ -1524,6 +1561,7 @@ export class EditorOptionsValidator {
} else {
quickSuggestions = _boolean(opts.quickSuggestions, defaults.quickSuggestions);
}
const find = this._santizeFindOpts(opts.find, defaults.find);
return {
selectionClipboard: _boolean(opts.selectionClipboard, defaults.selectionClipboard),
hover: _boolean(opts.hover, defaults.hover),
Expand All @@ -1547,6 +1585,7 @@ export class EditorOptionsValidator {
folding: !performanceCritical && _boolean(opts.folding, defaults.folding),
showFoldingControls: _stringSet<'always' | 'mouseover'>(opts.showFoldingControls, defaults.showFoldingControls, ['always', 'mouseover']),
matchBrackets: !performanceCritical && _boolean(opts.matchBrackets, defaults.matchBrackets),
find: find
};
}
}
Expand Down Expand Up @@ -1955,5 +1994,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
folding: true,
showFoldingControls: 'mouseover',
matchBrackets: true,
find: {
seedSearchStringFromSelection: true
}
},
};
2 changes: 2 additions & 0 deletions src/vs/editor/contrib/find/browser/findWidget.ts
Expand Up @@ -246,8 +246,10 @@ export class FindWidget extends Widget implements IOverlayWidget {
}
if (e.isRevealed) {
if (this._state.isRevealed) {
console.log('open find widget');
this._reveal(true);
} else {
console.log('close find widget');
this._hide(true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/find/common/findController.ts
Expand Up @@ -235,7 +235,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
};

// Consider editor selection and overwrite the state with it
if (opts.seedSearchStringFromSelection) {
if (opts.seedSearchStringFromSelection && this._editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection) {
let selectionSearchString = this.getSelectionSearchString();
if (selectionSearchString) {
if (this._state.isRegex) {
Expand Down
16 changes: 16 additions & 0 deletions src/vs/monaco.d.ts
Expand Up @@ -2627,6 +2627,13 @@ declare module monaco.editor {
horizontalSliderSize?: number;
}

/**
* Configuration options for editor find widget
*/
export interface IEditorFindOptions {
seedSearchStringFromSelection?: boolean;
}

/**
* Configuration options for editor minimap
*/
Expand Down Expand Up @@ -2734,6 +2741,10 @@ declare module monaco.editor {
* Control the behavior and rendering of the minimap.
*/
minimap?: IEditorMinimapOptions;
/**
* Control the behavior of the find widget.
*/
find?: IEditorFindOptions;
/**
* Display overflow widgets as `fixed`.
* Defaults to `false`.
Expand Down Expand Up @@ -3153,6 +3164,10 @@ declare module monaco.editor {
readonly maxColumn: number;
}

export interface InternalEditorFindOptions {
readonly seedSearchStringFromSelection: boolean;
}

export interface EditorWrappingInfo {
readonly inDiffEditor: boolean;
readonly isDominatedByLongLines: boolean;
Expand Down Expand Up @@ -3223,6 +3238,7 @@ declare module monaco.editor {
readonly folding: boolean;
readonly showFoldingControls: 'always' | 'mouseover';
readonly matchBrackets: boolean;
readonly find: InternalEditorFindOptions;
}

/**
Expand Down

0 comments on commit 79be3ae

Please sign in to comment.