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

Extra lines of context above/below search results #190

Closed
andrewchilds opened this issue Apr 25, 2014 · 53 comments
Closed

Extra lines of context above/below search results #190

andrewchilds opened this issue Apr 25, 2014 · 53 comments

Comments

@andrewchilds
Copy link

ST includes two lines above and below search results for context, which I regularly found useful and would love to see included in Atom.

Ideally the line count would be a setting instead of hardcoded:

[ ] Focus Editor After Search
[ ] Open Project Find Results In Right Pane
[2] Lines of Context Above/Below Search Results

🍻

@bryanrite
Copy link

👍

4 similar comments
@jkornobis
Copy link

👍

@mbillard
Copy link

👍

@zenlambda
Copy link

👍

@MWeeden43
Copy link

👍

@gabmontes
Copy link

Would be awesome to have this enhancement in.

I think most of us can give it a try send a PR, anyway. It should be updated in at least the following locations: in the class MatchView to render the extended results and where the search results are generated. I followed it up to ResultsView.initialize(). It receives a ResutlsModel that has to have the context lines added. Where is it generated?

@jayasurian123
Copy link

This is really a missing item. 👍

@wcurtis
Copy link

wcurtis commented Jul 10, 2015

👍 As a fresh convert from Sublime Text I'd love to see this added to Atom. The extra few lines of context really make a difference. Here's a comparison for reference.

Atom 1.0
screen shot 2015-07-10 at 4 39 40 pm

Sublime Text 3
screen shot 2015-07-10 at 4 44 19 pm

@cvogt
Copy link

cvogt commented Jul 10, 2015

+1

@zombiecrab
Copy link

👍 Really need this.

@lukeaus
Copy link

lukeaus commented Jul 28, 2015

+1

1 similar comment
@barteko
Copy link

barteko commented Jul 29, 2015

+1

@antidiestro
Copy link

+1 PARFAVAR

@kaushikgopal
Copy link

+1

@inelsonrocha
Copy link

👍 (as this is the only real argument preventing global atom adoption in my company... instead of ST)

@DouweM
Copy link

DouweM commented Oct 31, 2015

👍

@807811b0-1373-11e5-b60b-1697f925ec7b

If anyone has a fork of Find and Replace that adds this functionality, please comment.

@rosepuppy
Copy link

👍

5 similar comments
@seedofjoy
Copy link

👍

@oleksandr-kuzmenko
Copy link

👍

@davydov-d
Copy link

+1

@antonpaisov
Copy link

👍

@jchlu
Copy link

jchlu commented Feb 29, 2016

+1

@borb
Copy link

borb commented Feb 29, 2016

+1

This would be incredibly useful - right now, I drop to a shell and use grep -A3 -B3.

@maprihoda
Copy link

+1

@dmo-odoo
Copy link

Hello,

This will nearly be 2 years since this issue has been opened, and it is still the most bothering everyday problem with atom in my opinion.

Could you please at least aknowledge this issue, even the answer is "we think it's useless and we won't do it" ?

Thank you,
David

@nim-odoo
Copy link

That's definitively THE missing feature of atom...

@kaushikgopal
Copy link

@dmo-odoo this has been tagged as an "enhancement" which basically means don't hold your breath for this to get "fixed". Unless it's a bug there can't be an expectation for it to be fixed.

Below is complete speculation on my part:

There could be performance considerations which is why this feature is not built in. I mean, it's clear that the folks at Atom have noticed this feature in Sublime Text. If it's not already there, there's a reason why.

Even better: it's totally open source! you can see the parts of the code that enable this feature. Add the enhancement yourself and send in a PR. That should kick start the process again. If you're not sure how, you'll have to be patient for someone else to do it. That's unfortunately how the game works.

@MartinMuzatko
Copy link

https://github.com/atom/find-and-replace/blob/master/lib%2Fproject%2Fmatch-view.coffee#L11-L12

This is where you can change the display of the lines. I'll give it a shot but I'm not familiar with the build system of atom packages and I found no documentation so far.

Found it!

https://discuss.atom.io/t/load-developing-package/2554

This is how the ResultsModel looks like. The problem is, that the match (lineText) only includes the line of the matched text.
image

@MartinMuzatko
Copy link

I got the extra lines, now I only need to properly format it.
If someone can give me some pointers, I'd be very happy to PR this in no time.

I could find no documentation about the View elements :/
Only this styleguide: https://github.com/atom/styleguide/blob/master/lib/styleguide-view.coffee
That kinda showcases how to use these @span elements

    lines = atom.project.findBufferForPath(filePath)?.lines

    prefixLines = lines.slice(range.start.row - 2, range.start.row)
    suffixLines = lines.slice(range.end.row, range.end.row + 2)
    # if range.start.row <= 2
    #   prefixLines = lines.slice(0, range.start.row)
    # if range.end.row >= lines.length - 2
    #   suffixLines = lines.slice(range.end.row, lines.length)

    @li class: 'search-result list-item', =>
      @span range.start.row + 1, class: 'line-number text-subtle'
      @span => @raw prefixLines.join('<br>')
      @span class: 'preview', outlet: 'preview', =>
        @span prefix
        @span match.matchText, class: 'match highlight-info', outlet: 'matchText'
        @span match.matchText, class: 'replacement highlight-success', outlet: 'replacementText'
        @span suffix
      @span => @raw suffixLines.join('<br>')

I actually did it! it's not nice, but we will refactor it in the PR then.

@MartinMuzatko
Copy link

Like this :D

f r2

@DouweM
Copy link

DouweM commented Apr 8, 2016

@MartinMuzatko You make me very happy

@cvogt
Copy link

cvogt commented Apr 8, 2016

@MartinMuzatko You are awesome!

@MartinMuzatko
Copy link

😊 thanks guys, I do my best to fix this.

@fiz
Copy link

fiz commented Jun 10, 2016

👍

@rga-odoo
Copy link

👍 it's really missing feature

@alexhudici
Copy link

👍

@isuraed
Copy link

isuraed commented Jun 22, 2016

That looks great! Hope it's in the product soon.

@MartinMuzatko
Copy link

@isuraed it is not that easy, there are a lot of things to take care of, but it is possible.

@brian-slate
Copy link

👍 💝

@rahlzel
Copy link

rahlzel commented Aug 9, 2016

👍

@thebarty
Copy link

thebarty commented Dec 1, 2016

+1 PLEASSEEEEEEEE 👍

@MartinMuzatko
Copy link

I think I'll try it again during my winter vacation. As said: there are a few more aspects to it. but maybe finally I can finish it up.

@thebarty
Copy link

thebarty commented Dec 6, 2016

@MartinMuzatko: oh man that would be sooooo nice!!!! 👍 I am really missing this after switching over from sublime. Sublime does such a great job at this. It is just so much easier to find the right places you are searching for.

@thebarty
Copy link

thebarty commented Dec 6, 2016

Just thinking: a good reference on how to layout the results is the way that github displays search restults, p.e. here https://github.com/meteor/todos/search?utf8=%E2%9C%93&q=.call

@spencerhakim
Copy link

Not sure if it's truly related to this issue, but I hate seeing the same line printed twice (or more) when the word I'm searching for just happens to appear twice (or more) in the same line. Example:
capturfiles-201612341_111240
I really want to see the surrounding lines in my search results, but it would be really annoying if instead of seeing the same one line printed twice, I see the same five lines printed twice.

Just something to keep in mind for whoever ends up working on this (and a pre-emptive Thanks to @MartinMuzatko if you do end up working on this over the holidays)

@winstliu
Copy link
Contributor

winstliu commented Dec 6, 2016

@spencerhakim That was already discussed and I believe the consensus was that code-wise, it would be the most logical to tackle it separately from this one.

@spencerhakim
Copy link

@50Wliu Ah, that's what I get for not reading through all the comments. Thanks for getting me up to date.

@winstliu
Copy link
Contributor

winstliu commented Dec 6, 2016

No problem. I think the discussion actually happened on the PR anyway.

@dirk-thomas
Copy link
Contributor

I thought about the way PR #702 is implementing the feature and am a bit worried that the overhead due to opening a buffer for every result might be high in cases of large scale (many search result / search results in large files). Therefore I described an alternative approach In #827. Any feedback on this would be highly welcome - especially any experience on the overhead of creating buffers for each result would be valuable to make an informed decision.

@PixelT
Copy link

PixelT commented Jan 17, 2017

👍 👍 👍

@dirk-thomas
Copy link
Contributor

This has been implemented in #847 which has been merged for the upcoming beta of Atom 1.17. So I think this can be closed.

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

Successfully merging a pull request may close this issue.