Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Only emit did-update when there are changes; set consistent classes on error #852

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

winstliu
Copy link
Contributor

@winstliu winstliu commented Feb 7, 2017

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions

Description of the Change

Consider the following scenario:

  1. Open a file and enter test.
  2. Search for test and notice that the find box turns green (using the One themes).
  3. Turn on regex mode and add an opening parenthesis to the find pattern.
    At this point, there is contradictory information: a red error message is presented, yet the find box is still green, as if there are results. This is because when an error message is set, it does not remove the has-results class, nor does it add the has-no-results class. Now we do both, and the find box turns red as expected.

In addition, it should fix an edge case where changing nothing would cause error messages to disappear.

Finally, I removed what I think is an incorrect line that nulls out the findError function as soon as markers are updated.

Alternate Designs

None. This seems like a very clean solution to me.

Benefits

No more errors when typing text while there's an invalid find pattern, in addition to improved UX when switching over to an invalid find pattern.

Possible Drawbacks

I'm pretty confident that there will be none.

Applicable Issues

Fixes #851

Consider the following scenario:
1. Turn on regex
2. Search for something simple in the file, eg "this"
3. has-results class appears as expected
4. Add an opening parenthesis to the find pattern
5. Find box is still green?!?!
Step 5 introduces contradicting information: a red error message yet a
green find box with the has-results class.

So now when we set an error message we make sure to remove the
has-results class and add the has-no-results class.

I'm also fairly certain that nulling a function is not a good idea, so I
removed that line.
@@ -224,6 +224,8 @@ class BufferSearch {
}

const newMarkers = this.createMarkers(scanStart, scanEnd);
if(newMarkers === false || !newMarkers.length) return; // Invalid/missing find pattern or no new markers
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if there are no new markers, we still might want to destroy some old markers, and we certainly want to continue processing the other entries in changes, because they might cause us to find new markers.

For example, suppose your editor was in this configuration (cursors represented by |):

1.   one
2.   two|
3.   three
4.   foo|ur

and you were searching for the pattern two|four and typed a backspace. That would destroy the match on line 2 but create a match on line 4.

In that situation, we wouldn't to return early from bufferStoppedChanging just because we didn't find any new markers in the first changed region.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what we might want to do is make the createMarkers return an empty array if no matches were found in the given range.

Copy link
Contributor

Choose a reason for hiding this comment

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

We've fixed this as part of #860. Didn't mean to steal your 🌩 but we're on a spree of uncaught exception fixes after publishing 1.14.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the other part of this PR is still worthwhile though!

Copy link
Contributor Author

@winstliu winstliu Feb 14, 2017

Choose a reason for hiding this comment

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

Yeah I thought I noticed a regression related to that, but didn't realize what the steps to reproduce were.

I'll update this PR to only focus on the UX changes.

@@ -237,7 +239,7 @@ class BufferSearch {
}
}

this.emitter.emit('did-update', this.markers.slice());
if(changes.length) this.emitter.emit('did-update', this.markers.slice());
Copy link
Contributor

@maxbrunsfeld maxbrunsfeld Feb 14, 2017

Choose a reason for hiding this comment

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

👍 This makes a lot of sense.

We don't have JS linting enabled on this repo, but usually we include a space after the word if.

@winstliu winstliu changed the title Check for the existence of new markers before trying to update markers Only emit did-update when there are changes; set consistent classes on error Feb 15, 2017
@@ -237,7 +237,7 @@ class BufferSearch {
}
}

this.emitter.emit('did-update', this.markers.slice());
if (changes.length) this.emitter.emit('did-update', this.markers.slice());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this still be checking for changes then, or should it be checking for changed markers? (Not sure how to do that)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncaught TypeError: (var)[Symbol.iterator] is not a function
2 participants