Skip to content

Commit

Permalink
Fix microsoft#20768: Don't seed search without selection
Browse files Browse the repository at this point in the history
This makes CMD/CTRL+F consistent with other editors/IDEs.
  • Loading branch information
wkornewald committed Sep 6, 2019
1 parent 503c36d commit 33cd8a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
16 changes: 5 additions & 11 deletions src/vs/editor/contrib/find/findController.ts
Expand Up @@ -36,17 +36,11 @@ export function getSelectionSearchString(editor: ICodeEditor): string | null {

const selection = editor.getSelection();
// if selection spans multiple lines, default search string to empty
if (selection.startLineNumber === selection.endLineNumber) {
if (selection.isEmpty()) {
let wordAtPosition = editor.getModel().getWordAtPosition(selection.getStartPosition());
if (wordAtPosition) {
return wordAtPosition.word;
}
} else {
if (editor.getModel().getValueLengthInRange(selection) < SEARCH_STRING_MAX_LENGTH) {
return editor.getModel().getValueInRange(selection);
}
}
if (selection.startLineNumber === selection.endLineNumber
&& !selection.isEmpty()
&& editor.getModel().getValueLengthInRange(selection) < SEARCH_STRING_MAX_LENGTH
) {
return editor.getModel().getValueInRange(selection);
}

return null;
Expand Down
9 changes: 2 additions & 7 deletions src/vs/editor/contrib/find/test/find.test.ts
Expand Up @@ -20,17 +20,12 @@ suite('Find', () => {

// The cursor is at the very top, of the file, at the first ABC
let searchStringAtTop = getSelectionSearchString(editor);
assert.equal(searchStringAtTop, 'ABC');
assert.equal(searchStringAtTop, null);

// Move cursor to the end of ABC
editor.setPosition(new Position(1, 3));
let searchStringAfterABC = getSelectionSearchString(editor);
assert.equal(searchStringAfterABC, 'ABC');

// Move cursor to DEF
editor.setPosition(new Position(1, 5));
let searchStringInsideDEF = getSelectionSearchString(editor);
assert.equal(searchStringInsideDEF, 'DEF');
assert.equal(searchStringAfterABC, null);

});
});
Expand Down
8 changes: 5 additions & 3 deletions src/vs/editor/contrib/find/test/findController.test.ts
Expand Up @@ -218,9 +218,11 @@ suite('FindController', () => {
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
let nextMatchFindAction = new NextMatchFindAction();

editor.setPosition({
lineNumber: 1,
column: 9
editor.setSelection({
startLineNumber: 1,
startColumn: 8,
endLineNumber: 1,
endColumn: 11
});

nextMatchFindAction.run(null, editor);
Expand Down

0 comments on commit 33cd8a0

Please sign in to comment.