Skip to content

Conversation

@noamyogev84
Copy link
Contributor

@noamyogev84 noamyogev84 commented Oct 19, 2018

Fixes #1654

Description of change

  • Implemented search next/previous starting at current selection.
  • Added ISearchIndex to support search from specific row and column in findInLine
  • Added unit tests to search.test.ts

regex?: boolean;
wholeWord?: boolean;
caseSensitive?: boolean;
matchMultiple?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

I think this should just maybe always be on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, removing from ISearchOptions.

* @param searchOptions search options,
* @return An array of matches or first match.
*/
private _getNextMatch(term: string, searchString: string, row: number, searchOptions: ISearchOptions): ISearchResult {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of reimplementing a bunch of the search stuff, could we start the search at the end of the current selection? Instead of the current master behavior which is to start the search on the line following the selection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not so sure about this one.

Instead of the current master behavior which is to start the search on the line following the selection

The part that starts the search is this -

// Search from ydisp + 1 to end
for (let y = startRow + 1; y < this._terminal._core.buffer.ybase + this._terminal.rows; y++) {
result = this._findInLine(term, y, searchOptions);

I think i'll start by changing this part. then I'll have to somehow ignore the prefix of the line (what comes before the current selection).
@Tyriar , Is this the right direction?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry about the huge delay, I was on vacation. Yes this is the right approach 👍

const find4 = term.searchHelper.findInLine('aa', 1, searchOptions);
const find5 = term.searchHelper.findInLine('aa', 1, searchOptions);
expect(find0).eql({col: 0, row: 0, term: 'aa'});
expect(find1).eql({col: 1, row: 0, term: 'aa'});
Copy link
Member

Choose a reason for hiding this comment

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

My expectation is for the second search to give col: 9. Another example:

Searching aaaa first would highlight the first two, searching again would highlight the last 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, removing the "overlapping term" implementation.

@Tyriar Tyriar added the work-in-progress Do not merge label Nov 24, 2018
start search from current selection.
add unit tests.
@noamyogev84
Copy link
Contributor Author

Hi @Tyriar . I'll appreciate if you can review my PR. some concerns:

  1. Match by regex is a bit tricky. I'm pretty sure this is the nastiest part of the implementation (not very efficient) hope to hear your thoughts.
  2. Added a new wrapper function findFromIndex to search.test.ts. but I should probably change all other tests to use findInLine in its new version. what do you think?

Thanks

@Tyriar
Copy link
Member

Tyriar commented Dec 7, 2018

@noamyogev84 btw it's much easier to review with GitHub when you don't rebase as I can't review just the new changes now.

regex?: boolean;
wholeWord?: boolean;
caseSensitive?: boolean;
reverseSearch?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this being added? Seems to be complicating the changes an awful lot and there isn't a request for such a feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Tyriar Hi...
I removed the reverseSearch option from ISearchOptions. but I have to somehow provide this option to findInLine. don't you agree?

Copy link
Member

@Tyriar Tyriar Dec 9, 2018

Choose a reason for hiding this comment

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

I'm a little confused, we don't want to do any "reverse" searching afaict, say the selection is at (5,5), we want to:

  • Do a search from (5,5) to the end of the line
  • Search all following lines until the end
  • Search each line from the start to (0,5)
  • Search from (0,5) to (4,5)

When a result is hit, we want to do a forward search on the same line from the end of the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly what i do when findNext is called. but what about findPrevious?
What is your expectation if let's say there's a selection on (5,5) and the user is clicking on the find previous button?
I guess what i'm saying is that now, I need to be able to find multiple matches in the same line going backwards, and that logic is within findInLine.

Sorry for the confusion here.... :)

Copy link
Member

Choose a reason for hiding this comment

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

Oh you're totally right, I agree wholeheartedly with this now 😄:

I removed the reverseSearch option from ISearchOptions. but I have to somehow provide this option to findInLine. don't you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Glad to hear that!
So assuming you prefer the option where ISearchOptions doesn't contain reverseSearch, and we pass it separatly to findInLine, Are there any more changes required? I'll appreciate your review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Tyriar pinging you once more. :)
Do you think we can move forward with this? any changes required?

add isReverseSearch argument to findInLine
modify unit tests
@nojvek nojvek mentioned this pull request Dec 11, 2018
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

Thanks for your patience with this, finally got around to looking at it again and merging in the latest changes (some big conflicts with incremental search being added).

if (result) {
break;
// Search startRow
result = this._findInLine(term, { row: startRow, col: startCol }, searchOptions);
Copy link
Member

Choose a reason for hiding this comment

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

I'll make a change to remove the ISearchIndex object and just pass in the raw values. The reason being that a search over 10000 lines would create 10000 objects that basically immediately get discarded, so it's not worth the added niceness of named params.

@Tyriar Tyriar added this to the 3.10.0 milestone Dec 26, 2018
@Tyriar Tyriar removed the work-in-progress Do not merge label Dec 27, 2018
@Tyriar Tyriar merged commit b48f910 into xtermjs:master Dec 27, 2018
@Tyriar
Copy link
Member

Tyriar commented Dec 27, 2018

@noamyogev84 thanks again 😃, pulling into VS Code here microsoft/vscode#65711

@noamyogev84
Copy link
Contributor Author

@Tyriar it was a great experience! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants