-
Notifications
You must be signed in to change notification settings - Fork 194
add settings for context lines, show context in match view #847
Conversation
I removed the "[WIP]" prefix from the title since the feature is "complete" now. While there are still failing specs to address I think it would be good to review this first to ensure there is a consensus on the approach. |
@dirk-thomas Thanks for this! Could you provide screenshots or animated GIFs showing what this new UI look like? One concern: I'm not sure that a config setting is the best way for the user to specify how many context lines they want. I would think that you'd want to vary these numbers on a search-by-search basis. For me personally, I usually wouldn't want any lines of context, but in certain searches, I'd want to see some preceding and/or following context, depending on what I'm looking for. So I would think that we might actually want some kind of UI for specifying the amount of context. What do you think? /cc @simurai @atom/feedback |
I kept the UI changes minimal for now so that the PR is easier to review. Please see the current results with 2 lines of context above and below. The matched line is highlighted in white (new to better distinguish the matched lines from the context line) and the matched text is highlighted with a blue box (as it was before). While the PR only adds package settings for the number of context lines the API is designed to provide the arguments for each query. So it should be easy to customize the UI to configure it for every search. I am not familiar with the UI elements in Atom. Maybe someone could suggest how to setup the additional elements beside the existing search options. For the search results I could see a few enhancements to improvement the view (specific to the new context):
Besides there a other possible improvements but they also apply to the result without the context:
|
I like this option the best. Just scanning the screenshot it's very hard to tell where a jump in the file occurs. |
@50Wliu I added a second commit (747c91e) which simply modifies the css. The result is definitely easier to "parse" visually: |
What about something similar like the "blue expanding button" on github.com. So you could get context for a specific line. Maybe each click increases context by 5 extra lines. Then there could also be a Scroll position would probably quickly get out of hand. Anyways, just some ideas. It could also be considered in a follow-up PR to keep this one smaller in scope. |
@simurai The advantage of this PR over the other approaches is that it relies on As you mentioned it could be considered in a follow up PR. |
Oh, I see. Ok, another naive idea 😇.. what about always get some extra context and then hide it when initially shown? Maybe keep the context in memory or add to the DOM and hide with CSS? Then when expanding it would be instantly available. Of course, this only makes sense if the extra context doesn't significantly slow down search. |
@dirk-thomas The horizontal rules are a little noisy visually. How about using ellipses in place of a line number instead? I also snuck in some highlighting on matching line numbers, but don't mind me :) |
@simurai The optional folding / unfolding of the context was what I tried to suggest earlier. @mherodev The ellipses will be trivial to implement instead of the horizontal line. I will rather wait until we have a consensus in which direction this should go before updating the PR. Your picture shows well how it could look like. |
@maxbrunsfeld Can you please change the label from "work-in-progress" to "needs-review". |
Since the beta of 1.15 was just released it would great if this long awaited feature could be integrated (after a decision on how it should "look" like has been made) in order to become available in the next beta (1.16). |
@dirk-thomas I say go with the horizontal lines and we can iterate on it once it has been merged. |
@lee-dohm Sounds good to me. That matches the current state of the patch. |
@dirk-thomas Everything is good for final review then? |
@lee-dohm I would say yes. If this gets a +1 I would update the specs to match the new html structure if that is ok. |
@dirk-thomas you have a go 🚀 |
AFAIK, it's built into the search mechanism that we will never produce overlapping matches, so I don't think this will be an issue for us.
The behavior should be that the selected result stays in the same position within the viewport, not necessarily at the top of the view. This is what happens on master, and I thought that I saw this working fine on my branch after the merge. Let me take another 👀 .
Yeah, I'd actually rather not introduce the horizontal line yet. The reason is that I'm ambivalent as to whether it's visually helpful, and it complicates the implementation a little bit, because in order to get good scrolling performance, we now are responsible for calculating heights and positions of search results manually. Sorry for not mentioning that. |
So it might become a problem in the future. Once the search mechanism is "fixed" 😉 But we can think about that when that is the case...
That is totally fine by me. |
The current behavior on your branch scrolls by the But regarding the newly selected match: Let's assume that the search results all have the same height so the same number of context lines, which means no matches close to the top or bottom of a file. And further assume that the client height is not close to a multiple of each results height but something in between, e.g. 3.5 result heights. So after scrolling a page down the newly selected result must be either ~ half result height further up or down than the previously selected item. Therefore currently the selection slowly drifts when triggering pageDown repeatedly. It seems if the fractional part of the client height / result height is < 0.5 it drifts in one direction, if is > 0.5 it drifts in the other direction. I am not sure what to do about it and what a "better" / expected behavior would be. I just think the current behavior sometimes looks "random" to the user and the specs could only check of the new selection is within a certain range from the previous one which is kind of fuzzy... |
Yeah, I agree; it's not ideal. But the I guess an ideal solution would be to store off some kind of 'goal offset` for the selected match, so that we could continue to round in the correct direction when paging up and down. That said, I don't think we need to do that as part of this PR. What would you like to do? |
The challenge is that the current behavior is not that easy to test in a spec. I could try to update the specs to check for some kind of valid "range" around there the new selection is supposed to be (probably the old location plus / minus the height of the largest possible result height). If you think this is "good enough" for now we can tackle the scrolling behavior separately if that is already the case on master. |
I think that when testing |
Probably, but then we wouldn't really test that the behavior still does something reasonable with context 😉 |
I updated the
With this state all specs pass for me locally:
I assume the CI won't pass since the other PRs haven't been merged and released yet? |
I updated the patch in 47dd521 to use the same option names as in atom/text-buffer#195 (comment). |
@maxbrunsfeld Is this still being considered for Atom 1.17 beta? |
I'm going to bring it up in the team meeting first thing on Monday.
…On Thu, Apr 6, 2017 at 12:40 PM, Dirk Thomas ***@***.***> wrote:
@maxbrunsfeld <https://github.com/maxbrunsfeld> Is this still being
considered for Atom 1.17 beta?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#847 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_XKdXn9Nr39IJy_Cz5SmpkOuydRgVIks5rtT-5gaJpZM4Lw578>
.
|
@dirk-thomas Thanks for all your hard work and patience on this. I talked to the team about this PR in the team meeting this morning. What we would need for this to be merged and go out with v1.17:
I understand that CI will pass soon enough as the features that this PR depend on make it out to Stable on their own. So we fully intend to integrate this PR, it just won't be with v1.17 without additional work. Let me know if you have any questions! |
@lee-dohm What is the timeline for 1.17? When does this need to be ready in order to be merged in time? Regarding the compatibility with stable (old API) as well as the upcoming beta (new API): as far as I can see the patch would require conditionals in many many lines / places. Is that really the intention here? I would argue that it makes the code much worse to read / maintain. What is the appropriate condition to check for the Atom version I should use all over the place? |
The idea is not to place version checks in the code but in the tests. The condition to check would be |
@dirk-thomas What I had imagined was something like: if (parseFloat(atom.getVersion()) >= 1.17) {
describe('when context lines are enabled', () => {
// tests for the context line behavior
})
} I realize that we'd also need some conditional like this when we call |
@lee-dohm I don't know what exactly "very, very soon" means but probably only a few days? I will try but I can't promise to find the necessary spare time to work on updating this PR today (tomorrow?). If anybody else would like to rebase the PR and add the conditions please feel free to do so. It would be really sad if this great feature would be left out for yet another cycle... |
@lee-dohm @maxbrunsfeld I rebased the patch and used the Atom version to distinguish the signature of the |
Thanks for all your hard work and perseverance on this @dirk-thomas! |
🚢 Awesome. Looking forward for the upcoming beta! |
@dirk-thomas thank you so much, you rock!! |
Requirements
Description of the Change
The patch adds two new options
searchContextLineCountBefore
andsearchContextLineCountAfter
which are passed down toscandal
to return matches with context lines around the matched line. The match view is being modified that each match does not contain a singleli
but a whole list which itself contains all context lines before, the matching line, and the context lines after.To allow the context lines and the match line to be distinguished visually the color of the match line has been updated. Also the way the ".selected" item is being determined is updated to highlight the match line rather then the first context line in the sub list.
Alternate Designs
Other approaches:
In contrast to these this PR does not rely on requiring a
TextBuffer
for each search result. Instead it uses an extended version ofscadal
to provide the context directly in the returned match objects.Benefits
It implements the long desired feature described in #190. The approach requires less resources as the listed other approaches.
Possible Drawbacks
The new settings default to
0
lines of context before and after which is the same behavior as previously. But since the view structure has been updated to accommodate the optional context lines that might affect compatibility. I don't have any experience with Atom views and therefore can't estimate how high the chances for this are.Applicable Issues / Remaining Todos
In the current state when the search results list a file which is not opened yet and you click on the result the match is being updated and looses the context information. This is due to the fact that the search is being repeated in the buffer (instead of usingThis has been address with the PR to thescandal
through the workspace API. In order to address this theTextBuffer.scan
needs to be extended to support the same new options as in the referencedscandal
ticket. Therefore I have prefixed the title with[WIP]
for now.text-buffer
package.The current settings don't use a custom
order
attribute and are therefore in alphabetical order. Since it is a bit confusing that thebefore
option comes after theafter
option it might be good to add explicitorder
attributes to all options.Add test coverage / update existing specs as soon as there is a consensus on the selected approach and the feature works.
Related Stuff
The following items would all be nice to have but already a problem in the current state and I consider them orthogonal to this PR. They can be improved / addressed in the future in separate PRs: