Repository navigation
Indent soft wrap - #5567
Indent soft wrap#5567
Conversation
|
The bug mentioned above was just fixed. This code needs some ❤️, but I think we are on the right track (at least I hope so!) 😄 Please, feel free to leave opinions and critics about the approach I suggested. Thank you! |
There was a problem hiding this comment.
This method seems a bit Feature Envy (it deals mostly with another class internals). Shall we move it into TokenizedLine? I am not sure if this is part of the public API, thus it may need to stay nevertheless (at least as a middle man, e.g. it simply calls TokenizedLine#findWrapColumn, which in turn handles everything).
There was a problem hiding this comment.
Yeah, let's try moving it into TokenizedLine and see how it feels. The method isn't part of the public API.
|
This is great to see this issue in the process of being fixed! 👏 Out of curiosity, how does it plays with decorations? Does a selection spanning the wrapped line includes the phantom token? |
😊
Yes, it does. I wondered whether it should be included or not and, to be honest, I am not sure I know the answer 😅 I have a gut feeling that it shouldn't be selected at all, but I'd like to have some feedback before proceeding to change how selection works. |
IMO, given that selections go all the way to the right edge of the buffer when spanning many lines, it would make sense it includes the phantom token to start the new line selection from the left edge of the buffer. |
|
The code looks reasonable at first glance. I'm going to build and play with this now. It concerns me that there's no test coverage however. For each addition to the code, there should be a spec that fails if that addition isn't present. |
There was a problem hiding this comment.
I think we should call this leadingWhitespace or something to clarify it isn't technically a "tab".
|
Okay, after test driving this everything is looking good. Really nice work @as-cii. We just need thorough test coverage... like I mentioned, no part of this diff should be able to be reverted without a spec failing. |
|
Sorry, I should also add that I agree with @abe33 about selection rendering. I think the selection going all the way to the left is the right approach. |
|
Glad to see this is progressing. One small issue: if the leading whitespace is set to display, then the phantom tokens render as spaces, even if the document uses hard tabs. See the screenshot below. I don't know what the best behavior would be (not showing those character, showing a matching whitespace character for the document, or something else), but I don't think this is the best option. |
|
@grizzilus You're absolutely right. I'm such a bad QA tester. |
|
Also, I just want to throw out there that I don't think the selection should go to the left edge. It makes it less obvious when selecting a large chunk of text whether you are selecting multiple indented lines or a single soft-wrapped indented line. Line numbers and maybe some modifications to the way the whitespace on the left edge of the soft-wrapped indented line help the situation, but it still seems a bit off. I know highlighting the selection to the left edge would match the highlighting to the right edge, but that may not necessarily be the correct approach either. There is a similar discussion in atom/find-and-replace#130. The reasoning there for searching for |
...thanks @grizzilus 😄
...thanks @nathansobo
* 🐎 Check `isSoftWrapped` only once when updating screen lines
|
First of all, let me say that I am really happy to see such involvement into this pull-request: thank you guys for testing and reporting issues.
@nathansobo: thanks for pointing this out, that's a concern for me too. I'll make sure to write some new specs (e.g. phantom token should be invisible, phantom token shouldn't be reachable by the cursor, etc.) as well as fixing the failing ones that are currently checking the soft wrapping behavior.
@nathansobo @abe33: isn't it like this already? Just to make sure I have understood, here's another screenshot which illustrates how it works right now. Selection will reach the left and the right edges. How is this different from your suggested approach?
@grizzilus: nice observation (indeed, that was part of the reason why I didn't stick with one approach or another). On the other hand, if you display invisibles you'll be able to understand whether indentation comes from real tabs or it is simply carried from a wrapped line (see previous screenshot). |
|
I understand that looking at the invisibles or the line numbers makes it simple to tell the difference between a soft-wrapped indented line and multiple indented lines,but I still think the selection should match what does into the selection buffer without the extra padding to the right or the left. So I guess it is less an issue of this PR and more a design issue (since selections extend to the right edge). One other small issue: I think the indent guide should appear on the soft-wrapped lines. I think hiding the leading invisibles on the soft-wrapped lines also hides the indent guide. |
Yes, it is. I was just saying I think this is the correct behavior. This is all subjective, but my strong preference is to keep the behavior consistent with our treatment on the right hand side. When selections wrap between 2 locations on screen, they should always extend to either edge. If we change this on the left, we should change it on the right, but then we'd be inconsistent with selection rendering in most other editors. Ping me when you have a green core spec suite and test coverage for all aspects of this. I'm very excited to get it merged. ✨ |
This prevents a weird behavior that affects selection. Before this commit, when moving the cursor down, if it was inside a real (soft|hard)-tab of a soft wrapped line, it would reach the end of the line rather than the beginning of the next wrapped line. /cc: @nathansobo
|
🎆 Glad to have this in. Everyone be on the lookout for any issues we missed during testing, but I feel pretty good about this. |
|
👍 |
|
Outstanding. Thanks much for the work on this. This was the one issue for me which made Atom an unpleasant experience (otherwise it's been fantastic). When this update ships it's going to be a good day. |
|
👏 Great work! |
|
💖 |
|
Thanks guys this is bloody brilliant. |
|
Built this morning- not looking back. This is great work. 👍 |
|
Really looking forward to this feature! How do I get it to work though? I'm on 0.184.0 but can't get it to work. Am I missing something? :) |
|
@pierrepavlov v0.184.0 doesn't ship with this yet. v0.185.0 will have it 😉 |
|
@pierrepavlov you can build your own version of atom if you are impatient. Follow the doc's |
|
👏 This is fantastic, nice work. |
|
I’ve gotta jump on and add a big +1 for this work. Stellar, folks. |
|
Excellent job, all. @as-cii, @nathansobo especially - thanks for all the hard work. This one's been a long time coming 👍 |
|
Is there a way to get hanging indents for soft–wrapped lines? It would be nice to have continued lines display one tab stop in from the original line. |
|
This went live this afternoon, works like a charm. Thanks again guys. Sublime was great, but is now uninstalled. Atom full on. 👍 |
|
Is there a way to indent the wrapped line a bit more, e.g. two spaces? So it's more clear that it's part of previous line, not a new one? |
Nope, I'd say that the only way to visually understand that a line is the continuation of the previous one is to look at the sidebar (please, note the dot instead of the line number): I have never found this particularly annoying, though, and, for what is worth, Sublime Text behaves the same way (it hasn't dots, but expands the line number all the way down to the last wrapped line): |
|
@as-cii Thanks for reply. Yeah, it's not a big thing, I suppose just a matter of noticing the dot and lack of empty characters. thanks! |
|
@chodorowicz @as-cii I'd also like a setting for further indenting wrapped lines. It's not as big of a deal for a lot of code (at least that I use), as many languages have both style norms and a set of syntax features that enable hard wrapping lines (e.g. PEP8). However, it's a huge convenience for LaTeX when you're working on documents that get a lot of editing. It's nice to have sentences on individual lines for diffs, and those single breaks get ignored when the document is typeset. The wrapping makes it very easy to find specific sentences and to edit sentence-by-sentence. Other editors do this, and I miss it a lot. I'd be thrilled to see it added, as I use Atom almost exclusively now. I'd just add a variable to the length of the wrapped indent, and give users a setting for "Soft Wrap Hanging Indent" that provides the value (perhaps defaulting to zero). |
|
@jtkiley Yes it would be nice if there were support for a hanging indent, I prefer it when reading code. +1 your proposal, hanging indent should be multiples of the files existing indentation character(s). |
|
@jtkiley @chodorowicz @ioquatix Let's open a new issue so that we can track that feature request. Sound good? |
|
@izuzak I'm walking out the door now, but I'll create it when I get back. |
|
good idea! |





This fixes #1125.
It still needs a lot of refactoring (and some test cases too), but I just wanted to evaluate the approach that me and @nathansobo agreed on the aforementioned issue. To recap, the following is a brief explanation of how the solution works.
When lines with an indentation are soft wrapped, they are prepended with a phantom token which is as long as the indentation of the original line. This token is not selectable, nor reachable by the cursor. I had to change how
DisplayBuffer#clipScreenPositionworked, since I could not treat the phantom token as an hard tab. I'd like to remark that this is still experimental code, but based on my tests I can confirm it works pretty well.There's a subtle bug, though, which needs to be addressed and which I'll be looking at soon after creating this pull request. When a line is indented but no space is present, Atom freezes: I am quite sure this is due to how soft wrapping works on lines without spaces (namely, lines without words). I am quite sure this can be fixed easily, it just needs some more attention (and a better knowledge of the codebase).Thanks everyone in advance for the support!
/cc: @atom/core