Inserting 'fake' blank lines in the editor (like softwrap)


#1

I’m interested in showing inline popovers in my package, but at the moment they hide the text below them. As I understand it I can’t really add inline-block elements to the TextEditor itself because all the line display stuff is finely tuned. However it seems the editor can insert ‘fake’ extra lines (that are part of the view but not the buffer) in order to do Soft Wrap. Does any one know if its possible to insert these from a package, so I could just add some vertical space temporarily to make room for the overlay and delete it when the overlay is closed?


#2

You could use css transforms on the .tile and the .line elements:

// move 30px down
element.style.transform += 'translateY(30px)';

// move back up
element.style.transform.replace('translateY(30px)', '');

This also allows for a nice animation of the lines by temporarily setting something like transition: transform 400ms; on them :smile:


#3

Oops, I see now that tiles and lines are ordered at random, so my idea might be very difficult to get right…


#4

As far as I know, it is not currently possible to insert these virtual lines from a package. Perhaps @as_cii has some ideas?


#5

As of today it’s not really possible to do it, at least not through an abstraction provided by Atom. You could definitely move tiles around, as suggested by @olmokramer, although all the solutions you could come up with will be subject to changes on the rendering layer, which could break them quite easily.

We have talked about a similar abstraction during CodeConf and I feel like it’s gonna land in Atom at some point, but the implementation hasn’t started yet.

To get some inspiration for a temporary stopgap workaround, you may have a look at Nuclide’s DiffView which, as far as I know, adopts some similar hacks to render blank lines (it basically replaces a core method on DisplayBuffer, https://github.com/facebook/nuclide/blob/master/pkg/nuclide/diff-view/lib/DiffViewEditor.js#L31).


#6

However it seems the editor can insert ‘fake’ extra lines (that are part of the view but not the buffer)

Why not put real line lines in the buffer? You would just have to keep track of them and remove them later.

Edit: The one problem I can think of with that is the line numbering would get screwed up. But it would only be temporary while the additional text is showing.


#7

Yeah, I was thinking along the same lines: a massive amount of spaces to fill up a few lines. It would keep the line numbers correct, but it wouldn’t work when softwrapping is disabled…


#8

Yeah I guess I could add regular extra lines. Perhaps it’s not that much of an issue for now - the preview actually looks ok, just obviously you can’t really type underneath it but i think it’s still useable enough if you see the screenshot: (Preview Inline)


#9

Is there an issue to track this by chance?

I would love to have this available for Omnsharp Atom, to add some virtual lines for references and things like that.


#10

Don’t think so, might be worth doing…