Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Ctrl+D/Cmd+D temporary overwriting for find widget toggles #36682

Merged
merged 8 commits into from
Oct 23, 2017
639 changes: 3 additions & 636 deletions src/vs/editor/contrib/find/common/findController.ts

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/vs/editor/contrib/find/common/findModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ export const FIND_IDS = {
PreviousMatchFindAction: 'editor.action.previousMatchFindAction',
NextSelectionMatchFindAction: 'editor.action.nextSelectionMatchFindAction',
PreviousSelectionMatchFindAction: 'editor.action.previousSelectionMatchFindAction',
AddSelectionToNextFindMatchAction: 'editor.action.addSelectionToNextFindMatch',
AddSelectionToPreviousFindMatchAction: 'editor.action.addSelectionToPreviousFindMatch',
MoveSelectionToNextFindMatchAction: 'editor.action.moveSelectionToNextFindMatch',
MoveSelectionToPreviousFindMatchAction: 'editor.action.moveSelectionToPreviousFindMatch',
StartFindReplaceAction: 'editor.action.startFindReplaceAction',
CloseFindWidgetCommand: 'closeFindWidget',
ToggleCaseSensitiveCommand: 'toggleFindCaseSensitive',
Expand Down
71 changes: 53 additions & 18 deletions src/vs/editor/contrib/find/common/findState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,36 @@ export interface FindReplaceStateChangedEvent {
currentMatch: boolean;
}

export const enum FindOptionOverride {
NotSet = 0,
True = 1,
False = 2
}

export interface INewFindReplaceState {
searchString?: string;
replaceString?: string;
isRevealed?: boolean;
isReplaceRevealed?: boolean;
isRegex?: boolean;
isRegexOverride?: FindOptionOverride;
wholeWord?: boolean;
wholeWordOverride?: FindOptionOverride;
matchCase?: boolean;
matchCaseOverride?: FindOptionOverride;
searchScope?: Range;
}

function effectiveOptionValue(override: FindOptionOverride, value: boolean): boolean {
if (override === FindOptionOverride.True) {
return true;
}
if (override === FindOptionOverride.False) {
return false;
}
return value;
}

export class FindReplaceState implements IDisposable {

private static _CHANGED_EVENT = 'changed';
Expand All @@ -45,8 +64,11 @@ export class FindReplaceState implements IDisposable {
private _isRevealed: boolean;
private _isReplaceRevealed: boolean;
private _isRegex: boolean;
private _isRegexOverride: FindOptionOverride;
private _wholeWord: boolean;
private _wholeWordOverride: FindOptionOverride;
private _matchCase: boolean;
private _matchCaseOverride: FindOptionOverride;
private _searchScope: Range;
private _matchesPosition: number;
private _matchesCount: number;
Expand All @@ -57,9 +79,9 @@ export class FindReplaceState implements IDisposable {
public get replaceString(): string { return this._replaceString; }
public get isRevealed(): boolean { return this._isRevealed; }
public get isReplaceRevealed(): boolean { return this._isReplaceRevealed; }
public get isRegex(): boolean { return this._isRegex; }
public get wholeWord(): boolean { return this._wholeWord; }
public get matchCase(): boolean { return this._matchCase; }
public get isRegex(): boolean { return effectiveOptionValue(this._isRegexOverride, this._isRegex); }
public get wholeWord(): boolean { return effectiveOptionValue(this._wholeWordOverride, this._wholeWord); }
public get matchCase(): boolean { return effectiveOptionValue(this._matchCaseOverride, this._matchCase); }
public get searchScope(): Range { return this._searchScope; }
public get matchesPosition(): number { return this._matchesPosition; }
public get matchesCount(): number { return this._matchesCount; }
Expand All @@ -71,8 +93,11 @@ export class FindReplaceState implements IDisposable {
this._isRevealed = false;
this._isReplaceRevealed = false;
this._isRegex = false;
this._isRegexOverride = FindOptionOverride.NotSet;
this._wholeWord = false;
this._wholeWordOverride = FindOptionOverride.NotSet;
this._matchCase = false;
this._matchCaseOverride = FindOptionOverride.NotSet;
this._searchScope = null;
this._matchesPosition = 0;
this._matchesCount = 0;
Expand Down Expand Up @@ -155,6 +180,10 @@ export class FindReplaceState implements IDisposable {
};
let somethingChanged = false;

const oldEffectiveIsRegex = this.isRegex;
const oldEffectiveWholeWords = this.wholeWord;
const oldEffectiveMatchCase = this.matchCase;

if (typeof newState.searchString !== 'undefined') {
if (this._searchString !== newState.searchString) {
this._searchString = newState.searchString;
Expand Down Expand Up @@ -184,25 +213,13 @@ export class FindReplaceState implements IDisposable {
}
}
if (typeof newState.isRegex !== 'undefined') {
if (this._isRegex !== newState.isRegex) {
this._isRegex = newState.isRegex;
changeEvent.isRegex = true;
somethingChanged = true;
}
this._isRegex = newState.isRegex;
}
if (typeof newState.wholeWord !== 'undefined') {
if (this._wholeWord !== newState.wholeWord) {
this._wholeWord = newState.wholeWord;
changeEvent.wholeWord = true;
somethingChanged = true;
}
this._wholeWord = newState.wholeWord;
}
if (typeof newState.matchCase !== 'undefined') {
if (this._matchCase !== newState.matchCase) {
this._matchCase = newState.matchCase;
changeEvent.matchCase = true;
somethingChanged = true;
}
this._matchCase = newState.matchCase;
}
if (typeof newState.searchScope !== 'undefined') {
if (!Range.equalsRange(this._searchScope, newState.searchScope)) {
Expand All @@ -212,6 +229,24 @@ export class FindReplaceState implements IDisposable {
}
}

// Overrides get set when they explicitly come in and get reset anytime something else changes
this._isRegexOverride = (typeof newState.isRegexOverride !== 'undefined' ? newState.isRegexOverride : FindOptionOverride.NotSet);
this._wholeWordOverride = (typeof newState.wholeWordOverride !== 'undefined' ? newState.wholeWordOverride : FindOptionOverride.NotSet);
this._matchCaseOverride = (typeof newState.matchCaseOverride !== 'undefined' ? newState.matchCaseOverride : FindOptionOverride.NotSet);

if (oldEffectiveIsRegex !== this.isRegex) {
somethingChanged = true;
changeEvent.isRegex = true;
}
if (oldEffectiveWholeWords !== this.wholeWord) {
somethingChanged = true;
changeEvent.wholeWord = true;
}
if (oldEffectiveMatchCase !== this.matchCase) {
somethingChanged = true;
changeEvent.matchCase = true;
}

if (somethingChanged) {
this._eventEmitter.emit(FindReplaceState._CHANGED_EVENT, changeEvent);
}
Expand Down
Loading