提交 be298bfd 编写于 作者: S Sandeep Somavarapu

fix #9326

上级 8eeb1f6d
......@@ -19,7 +19,7 @@ import { LeftRightWidget, IRenderer } from 'vs/base/browser/ui/leftRightWidget/l
import { ITree, IElementCallback, IDataSource, ISorter, IAccessibilityProvider, IFilter } from 'vs/base/parts/tree/browser/tree';
import {ClickBehavior, DefaultController} from 'vs/base/parts/tree/browser/treeDefaults';
import { ContributableActionProvider } from 'vs/workbench/browser/actionBarRegistry';
import { Match, SearchResult, FileMatch, FileMatchOrMatch } from 'vs/workbench/parts/search/common/searchModel';
import { Match, SearchResult, FileMatch, FileMatchOrMatch, SearchModel } from 'vs/workbench/parts/search/common/searchModel';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { Range } from 'vs/editor/common/core/range';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
......@@ -167,8 +167,9 @@ export class SearchRenderer extends ActionsRenderer {
elements.push('<span>');
elements.push(strings.escape(preview.before));
let searchModel: SearchModel= (<SearchResult>tree.getInput()).searchModel;
let showReplaceText= (<SearchResult>tree.getInput()).searchModel.hasReplaceString();
let showReplaceText= searchModel.isReplaceActive() && !!searchModel.replaceString;
elements.push('</span><span class="' + (showReplaceText ? 'replace ' : '') + 'findInFileMatch">');
elements.push(strings.escape(preview.inside));
if (showReplaceText) {
......
......@@ -290,7 +290,7 @@ export class SearchViewlet extends Viewlet {
this.toUnbind.push(this.searchWidget.onReplaceToggled(() => this.onReplaceToggled()));
this.toUnbind.push(this.searchWidget.onReplaceStateChange((state) => {
this.viewModel.replaceString= this.searchWidget.getReplaceValue();
this.viewModel.replaceActive= state;
this.tree.refresh();
}));
this.toUnbind.push(this.searchWidget.onReplaceValueChanged((value) => {
......@@ -902,7 +902,7 @@ export class SearchViewlet extends Viewlet {
this.telemetryService.publicLog('searchResultChosen');
return this.viewModel.hasReplaceString() ? this.openReplacePreviewEditor(lineMatch, preserveFocus, sideBySide, pinned) : this.open(lineMatch, preserveFocus, sideBySide, pinned);
return (this.viewModel.isReplaceActive() && !!this.viewModel.replaceString) ? this.openReplacePreviewEditor(lineMatch, preserveFocus, sideBySide, pinned) : this.open(lineMatch, preserveFocus, sideBySide, pinned);
}
public open(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
......
......@@ -89,8 +89,8 @@ export class SearchWidget extends Widget {
private _onReplaceToggled = this._register(new Emitter<void>());
public onReplaceToggled: Event<void> = this._onReplaceToggled.event;
private _onReplaceStateChange = this._register(new Emitter<void>());
public onReplaceStateChange: Event<void> = this._onReplaceStateChange.event;
private _onReplaceStateChange = this._register(new Emitter<boolean>());
public onReplaceStateChange: Event<boolean> = this._onReplaceStateChange.event;
private _onReplaceValueChanged = this._register(new Emitter<string>());
public onReplaceValueChanged: Event<string> = this._onReplaceValueChanged.event;
......@@ -143,7 +143,7 @@ export class SearchWidget extends Widget {
}
public getReplaceValue():string {
return this.isReplaceActive() ? this.replaceInput.value : null;
return this.replaceInput.value;
}
public toggleReplace(show?:boolean): void {
......@@ -229,8 +229,8 @@ export class SearchWidget extends Widget {
let currentState= this.isReplaceActive();
let newState= this.isReplaceShown() && this.replaceAllAction.enabled;
if (currentState !== newState) {
this.replaceActive.set(this.isReplaceShown() && this.replaceAllAction.enabled);
this._onReplaceStateChange.fire();
this.replaceActive.set(newState);
this._onReplaceStateChange.fire(newState);
}
}
......
......@@ -407,6 +407,7 @@ export class SearchModel extends Disposable {
private _searchResult: SearchResult;
private _searchQuery: ISearchQuery= null;
private _replaceActive: boolean= false;
private _replaceString: string= null;
private _replacePattern: ReplacePattern= null;
......@@ -420,30 +421,22 @@ export class SearchModel extends Disposable {
this._searchResult= this.instantiationService.createInstance(SearchResult, this);
}
/**
* Return true if replace is enabled otherwise false
*/
public isReplaceActive():boolean {
return this._replaceString !== null && this._replaceString !== void 0;
return this._replaceActive;
}
/**
* Return true if replace is enabled and replace text is not empty, otherwise false.
* This is necessary in cases handling empty replace text when replace is active.
*/
public hasReplaceString():boolean {
return this.isReplaceActive() && !!this._replaceString;
public set replaceActive(replaceActive: boolean) {
this._replaceActive= replaceActive;
}
/**
* Returns the text to replace.
* Can be null if replace is not enabled. Use replace() before.
* Can be empty.
*/
public get replacePattern(): ReplacePattern {
return this._replacePattern;
}
public get replaceString(): string {
return this._replaceString;
}
public set replaceString(replaceString: string) {
this._replaceString= replaceString;
if (this._searchQuery) {
......
......@@ -222,74 +222,6 @@ suite('SearchModel', () => {
assert.ok(target.calledOnce);
});
test('Search Model: isReplaceActive return false if no replace text is set', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
assert.ok(!testObject.isReplaceActive());
});
test('Search Model: isReplaceActive return false if replace text is set to null', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= null;
assert.ok(!testObject.isReplaceActive());
});
test('Search Model: isReplaceActive return false if replace text is set to undefined', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= void 0;
assert.ok(!testObject.isReplaceActive());
});
test('Search Model: isReplaceActive return true if replace text is set to empty string', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= '';
assert.ok(testObject.isReplaceActive());
});
test('Search Model: isReplaceActive return true if replace text is set to non empty string', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= 'some value';
assert.ok(testObject.isReplaceActive());
});
test('Search Model: hasReplaceText return false if no replace text is set', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
assert.ok(!testObject.hasReplaceString());
});
test('Search Model: hasReplaceText return false if replace text is set to null', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= null;
assert.ok(!testObject.hasReplaceString());
});
test('Search Model: hasReplaceText return false if replace text is set to undefined', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= void 0;
assert.ok(!testObject.hasReplaceString());
});
test('Search Model: hasReplaceText return false if replace text is set to empty string', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= '';
assert.ok(!testObject.hasReplaceString());
});
test('Search Model: hasReplaceText return true if replace text is set to non empty string', function () {
let testObject:SearchModel= instantiationService.createInstance(SearchModel);
testObject.replaceString= 'some value';
assert.ok(testObject.hasReplaceString());
});
function aRawMatch(resource: string, ...lineMatches: ILineMatch[]): IFileMatch {
return { resource: URI.parse(resource), lineMatches };
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册