Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Updated: Highlight search feature #2662

Merged
merged 14 commits into from
Feb 8, 2013
Merged

Updated: Highlight search feature #2662

merged 14 commits into from
Feb 8, 2013

Conversation

peterflynn
Copy link
Member

Now ready for review & merge -- color choices have been ok'ed by @GarthDB's.

This is an updated version of #2485, using a hack suggested by NJ to give us a bit more flexibility in highlight colors:

  • Previously, "current result" color = gray selection color on bottom + "generic result" highlight color blended on top
  • Now, "curent result" color = any color we want on bottom + "generic result" highlight color blended on top (this new bg color will never appear "exposed" anywhere -- it's always blended beneath the "generic result" color).

This doesn't give us 100% flexibility -- in particular, the "generic result" color must be transparent and must look good blended atop both the normal editor bg color and atop the "current result" bg color.

I also made a few other changes from the original pull request:

  • Remove border from match style since it causes matches that cover multiple code-coloring spans to look like multiple separate matches instead of one
  • Beef up unit tests: expect exactly the set of marked ranges, nothing extra; and do a quick & dirty check that DOM has the same number of highlights too
  • Lower bailout threshold from ~2MB to 500K (I tested on a 1 MB file and it seemed pretty sluggish).

soswow and others added 11 commits January 7, 2013 22:03
…brackets into soswow-highlight-search-feature

* 'highlight-search-feature' of https://github.com/soswow/brackets:
  Color tweak from GarthDB
  Better tests, yellowish color for matches code refactoring.
  Tests for highlight feature and bug fix for /.*/ regexp.
  Removing highlight when last char deleted from search
  Fixing JSLint test. Add missing spaces.
  Highlight All Find Matches in Editor.

Conflicts:
	src/search/FindReplace.js
* Remove border from match style since it causes matches that cover multiple
  code-coloring spans to look like multiple separate matches instead of one
* Make highlight slightly less opaque so it's easier to tell which is
  current (after discussion with Garth)
* Beef up unit tests: expect exactly the set of marked ranges, no extras;
  do a quick & dirty check that DOM has the same number of highlights too
* Lower bailout threshold from ~2MB to 500K
(the backdrop for the 'current' search result) while highlights are
visible. Safe to do since we revert the color change as soon as focus
leaves the search bar, so the selection color is never seen on its own (i.e.
not overlaid by the search highlight color).

(Colors pending final tweaking from Garth)

Also, change the beginning of findFirst() as suggested in earlier code
review.
@peterflynn
Copy link
Member Author

Note that I could have gone further and actually changed the markText() style on the fly whenever the "current match" changes. This would have given us even more freedom in color choice (100% in fact), but made the code more complex.

It didn't seem worth it, since I'm pretty sure we'll have to do something completely different in the future if we want highlights to stay visible when focus returns to the editor. The fundamental challenge is that CodeMirror draws highlights on top of the selection color, while in most UIs with persistent highlighting (e.g. IntelliJ or Chrome's search bar) it's the opposite. We'd be back to square one in terms of needing colors that look good blended against both the default bg and the selection color bg (in fact two different selection colors -- focused and not). So I think we may need to do something more radical at that point.

@peterflynn
Copy link
Member Author

Note to self: I have a few stashed code cleanups to include in the commit along with Garth's suggested colors whenever I pull those in.

* Fix existing bug where 1-char selection remained after backspacing away
whole query; this causes the "hidden" highlighting bg color to become
exposed since selection is no longer in sync with highlighting. Also added
a unit test for this bug.
* Fix bug where highlighting bg color was visible in large files where
highlighting is disabled.
* Unit test code cleanups; and add test for older bug #2478
@peterflynn
Copy link
Member Author

Note that soswow's original commits were reviewed earlier in #2485. Feel free to review this whole diff anyway, but as a shortcut you could just look at a diff of my changes.

@peterflynn
Copy link
Member Author

Btw -- I've tested this on CMv3 and it works well there too. The merge was a little thorny, so @njx or whoever does the master->cmv3 merges, let me know if you want me to put up a pull request containing my existing local merge of thus stuff.

@redmunds
Copy link
Contributor

redmunds commented Feb 8, 2013

Your comment says "Lower bailout threshold from ~2MB to 500K (I tested on a 1 MB file and it seemed pretty sluggish)", but this pull request raises the threshold from 2k lines to 500k lines. 2m lines was the intermediate threashold set by the @soswow.

@@ -67,7 +67,11 @@ define(function (require, exports, module) {
$(".modal-bar .message").css("display", "inline-block");
$(".modal-bar .error").css("display", "none");
try {
return isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") === -1 ? "" : "i") : query;
if (isRE && isRE[1]) { // Not a regexp or an empty one
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment says the opposite of what the condition is checking.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

@redmunds
Copy link
Contributor

redmunds commented Feb 8, 2013

FYI, merging the latest code fixed the problem with menus.

In case you want to start making changes, I am done with initial review, except for unit tests.

@peterflynn
Copy link
Member Author

Re the bailout threshold: my note above is listed under the heading "changes from the original pull request," and relative to soswow's pull request this patch does indeed lower the threshold. Sorry for any confusion.

…tion;

use forEach() instead of Marijn's old for loop.
@peterflynn
Copy link
Member Author

@redmunds: changes pushed.

@redmunds
Copy link
Contributor

redmunds commented Feb 8, 2013

Looks good. Merging.

redmunds added a commit that referenced this pull request Feb 8, 2013
@redmunds redmunds merged commit 0bd49aa into master Feb 8, 2013
@peterflynn
Copy link
Member Author

Thanks!

@peterflynn peterflynn deleted the pflynn/highlight-search branch February 8, 2013 05:40
@soswow
Copy link
Contributor

soswow commented Feb 8, 2013

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants