Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Utilized searchString and other parameters for putting multi cursor
Created function selectAllUsingString for this purpose.
  • Loading branch information
njkevlani committed Oct 29, 2019
commit 1982664a2b37a86275a2ab921d784fa4d2840521
14 changes: 14 additions & 0 deletions src/vs/editor/contrib/multicursor/multicursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,20 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
this._setSelections(matches.map(m => new Selection(m.range.startLineNumber, m.range.startColumn, m.range.endLineNumber, m.range.endColumn)));
}
}

public selectAllUsingString(searchString: string, isRegex: boolean, matchCase: boolean, wholeWord: boolean, limitResultCount?: number): void {
if (!this._editor.hasModel()) {
return;
}

let matches: FindMatch[] | null = null;

matches = this._editor.getModel().findMatches(searchString, true, isRegex, matchCase, wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER);

if (matches.length > 0) {
this._setSelections(matches.map(m => new Selection(m.range.startLineNumber, m.range.startColumn, m.range.endLineNumber, m.range.endColumn)));
}
}
}

export abstract class MultiCursorSelectionControllerAction extends EditorAction {
Expand Down
11 changes: 6 additions & 5 deletions src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import { Memento, MementoObject } from 'vs/workbench/common/memento';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { MultiCursorSelectionController } from 'vs/editor/contrib/multicursor/multicursor';
import { CommonFindController } from 'vs/editor/contrib/find/findController';

const $ = dom.$;

Expand Down Expand Up @@ -1541,23 +1540,25 @@ export class SearchView extends ViewletPanel {
}

openEditorWithMultiCursor(element: FileMatchOrMatch): Promise<void> {
const selection = this.getSelectionFrom(element);
const resource = element instanceof Match ? element.parent().resource : (<FileMatch>element).resource;
return this.editorService.openEditor({
resource: resource,
options: {
preserveFocus: false,
pinned: true,
selection,
revealIfVisible: true
}
}).then(editor => {
if (editor) {
let codeEditor = getCodeEditor(editor.getControl());
if (codeEditor) {
let multiCursorController = MultiCursorSelectionController.get(codeEditor);
let findController = CommonFindController.get(codeEditor);
multiCursorController.selectAll(findController);
let isRegex = this.searchWidget.searchInput.getRegex();
let isWholeWords = this.searchWidget.searchInput.getWholeWords();
let isCaseSensitive = this.searchWidget.searchInput.getCaseSensitive();
let contentPattern = this.searchWidget.searchInput.getValue();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming from the search input, not the query, so the user could have changed this without rerunning the search, then it won't be the same, right?

Actually, can we avoid triggering a find, and just select the exact ranges that are in the actual match?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions:

  1. How do I get all the matches in searchView.ts?
  2. Should I create a public wrapper method for _setSelections method and use that in searchView.ts or this task need to be done in some other way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the matches right here in the FileMatchOrMatch

@njkevlani Nilesh Kevlani (njkevlani) Nov 24, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review please roblourens


multiCursorController.selectAllUsingString(contentPattern, isRegex, isCaseSensitive, isWholeWords);
}
}
this.viewModel.searchResult.rangeHighlightDecorations.removeHighlightRange();
Expand Down