Fix #58604. Do not update search scope when it is empty.

This commit is contained in:
rebornix
2018-09-14 11:06:18 -07:00
parent 067ed91b79
commit fb2f7039e9
2 changed files with 50 additions and 1 deletions

View File

@@ -266,7 +266,10 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}
if (opts.updateSearchScope) {
stateChanges.searchScope = this._editor.getSelection();
let currentSelection = this._editor.getSelection();
if (!currentSelection.isEmpty()) {
stateChanges.searchScope = currentSelection;
}
}
this._state.change(stateChanges, false);

View File

@@ -492,4 +492,50 @@ suite('FindController query options persistence', () => {
assert.deepEqual(findController.getState().searchScope, new Selection(1, 1, 2, 1));
});
});
test('issue #58604: Do not update searchScope if it is empty', () => {
withTestCodeEditor([
'var x = (3 * 5)',
'var y = (3 * 5)',
'var z = (3 * 5)',
], { serviceCollection: serviceCollection, find: { autoFindInSelection: true, globalFindClipboard: false } }, (editor, cursor) => {
// clipboardState = '';
editor.setSelection(new Range(1, 2, 1, 2));
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
findController.start({
forceRevealReplace: false,
seedSearchStringFromSelection: false,
seedSearchStringFromGlobalClipboard: false,
shouldFocus: FindStartFocusAction.NoFocusChange,
shouldAnimate: false,
updateSearchScope: true
});
assert.deepEqual(findController.getState().searchScope, null);
});
});
test('issue #58604: Update searchScope if it is not empty', () => {
withTestCodeEditor([
'var x = (3 * 5)',
'var y = (3 * 5)',
'var z = (3 * 5)',
], { serviceCollection: serviceCollection, find: { autoFindInSelection: true, globalFindClipboard: false } }, (editor, cursor) => {
// clipboardState = '';
editor.setSelection(new Range(1, 2, 1, 3));
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
findController.start({
forceRevealReplace: false,
seedSearchStringFromSelection: false,
seedSearchStringFromGlobalClipboard: false,
shouldFocus: FindStartFocusAction.NoFocusChange,
shouldAnimate: false,
updateSearchScope: true
});
assert.deepEqual(findController.getState().searchScope, new Selection(1, 2, 1, 3));
});
});
});