Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Indent soft wrap - #5567

Merged
nathansobo merged 28 commits into
atom:masterfrom
as-cii:indent-soft-wrap
Feb 26, 2015
Merged

nathansobo merged 28 commits into
atom:masterfrom
as-cii:indent-soft-wrap

Conversation

@as-cii

@as-cii as-cii commented Feb 15, 2015

Copy link
Copy Markdown
Contributor

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#clipScreenPosition worked, 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

@as-cii

as-cii commented Feb 16, 2015

Copy link
Copy Markdown
Contributor Author

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!

Comment thread src/display-buffer.coffee Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, let's try moving it into TokenizedLine and see how it feels. The method isn't part of the public API.

@abe33

abe33 commented Feb 16, 2015

Copy link
Copy Markdown
Contributor

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?

@as-cii

as-cii commented Feb 17, 2015

Copy link
Copy Markdown
Contributor Author

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?

screen shot 2015-02-17 at 09 07 27

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.

@abe33

abe33 commented Feb 17, 2015

Copy link
Copy Markdown
Contributor

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.

@nathansobo

Copy link
Copy Markdown
Contributor

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.

Comment thread src/tokenized-line.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should call this leadingWhitespace or something to clarify it isn't technically a "tab".

@nathansobo

Copy link
Copy Markdown
Contributor

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.

@nathansobo

Copy link
Copy Markdown
Contributor

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.

@jeremy-engel

Copy link
Copy Markdown
Contributor

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.

matching

@nathansobo

Copy link
Copy Markdown
Contributor

@grizzilus You're absolutely right. I'm such a bad QA tester.

@jeremy-engel

Copy link
Copy Markdown
Contributor

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 \n seems to apply to selecting whole lines as well.

...thanks @grizzilus 😄
* 🐎 Check `isSoftWrapped` only once when updating screen lines
@as-cii

as-cii commented Feb 18, 2015

Copy link
Copy Markdown
Contributor Author

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.

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.

@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.

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.

@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.

soft-wrapping

Selection will reach the left and the right edges. How is this different from your suggested approach?

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.

@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).

@jeremy-engel

Copy link
Copy Markdown
Contributor

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.

@nathansobo

Copy link
Copy Markdown
Contributor

@nathansobo @abe33: isn't it like this already?

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
@nathansobo
nathansobo merged commit c9ce9f4 into atom:master Feb 26, 2015
@nathansobo
nathansobo deleted the indent-soft-wrap branch February 26, 2015 02:06
@nathansobo

Copy link
Copy Markdown
Contributor

🎆 Glad to have this in. Everyone be on the lookout for any issues we missed during testing, but I feel pretty good about this.

@douglasdollars

Copy link
Copy Markdown

👍

@wanderingcrow

Copy link
Copy Markdown

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.

@lee-dohm

Copy link
Copy Markdown
Contributor

👏 Great work!

@thomasjo

Copy link
Copy Markdown
Contributor

💖

@ioquatix

Copy link
Copy Markdown

Thanks guys this is bloody brilliant.

@Cangit

Cangit commented Feb 26, 2015

Copy link
Copy Markdown

Built this morning- not looking back. This is great work. 👍

@pierrepavlov

Copy link
Copy Markdown

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? :)

@as-cii

as-cii commented Feb 26, 2015

Copy link
Copy Markdown
Contributor Author

@pierrepavlov v0.184.0 doesn't ship with this yet. v0.185.0 will have it 😉

@Cangit

Cangit commented Feb 26, 2015

Copy link
Copy Markdown

@pierrepavlov you can build your own version of atom if you are impatient. Follow the doc's

@joshrowley

Copy link
Copy Markdown

👏 This is fantastic, nice work.

@kevincoleman

Copy link
Copy Markdown

I’ve gotta jump on and add a big +1 for this work. Stellar, folks.

@aaronransley

Copy link
Copy Markdown

Excellent job, all. @as-cii, @nathansobo especially - thanks for all the hard work.

This one's been a long time coming 👍

@pierrepavlov

Copy link
Copy Markdown

Thanks for info @as-cii and @Cangit!

@jtkiley

jtkiley commented Mar 3, 2015

Copy link
Copy Markdown

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.

@wanderingcrow

Copy link
Copy Markdown

This went live this afternoon, works like a charm. Thanks again guys. Sublime was great, but is now uninstalled. Atom full on. 👍

@chodorowicz

Copy link
Copy Markdown

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?

@as-cii

as-cii commented Mar 14, 2015

Copy link
Copy Markdown
Contributor Author

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):

screen shot 2015-03-14 at 11 52 28

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):

screen shot 2015-03-14 at 11 59 36

@chodorowicz

Copy link
Copy Markdown

@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!

@jtkiley

jtkiley commented Mar 15, 2015

Copy link
Copy Markdown

@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).

@ioquatix

Copy link
Copy Markdown

@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).

@izuzak

izuzak commented Mar 17, 2015

Copy link
Copy Markdown
Contributor

@jtkiley @chodorowicz @ioquatix Let's open a new issue so that we can track that feature request. Sound good?

@jtkiley

jtkiley commented Mar 17, 2015

Copy link
Copy Markdown

@izuzak I'm walking out the door now, but I'll create it when I get back.

@chodorowicz

Copy link
Copy Markdown

good idea!

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.

Softwrap should match indent