Changing soft-wrap point by line style


I’ve been working on a package for working with markup. Pre-Atom 1.1.0, the editor couldn’t correctly position the cursor for lines that had padding applied to create margins. However, with 1.1.0, I was able to do this:

Cursor positioning, copy/paste, etc. all seem to work fine by simplying messing with my styles.less file:

atom-text-editor::shadow {
  padding: 0px 8em;

atom-text-editor::shadow .dialogue {
  padding: 0px 4em;

The only issue I’ve run into is that the soft-wrap guide doesn’t take the padding into account. Is it possible to identify the line classes and change the wrap point to emulate padding/margins to the right of dialogue to get a proper wrap-point? Any other techniques that might be able to achieve this?



Are you talking about the wrap-guide? If so, then no, it assumes that you have a fixed-width font and constant wrap column. But also, there is another setting that the wrap-guide doesn’t take into account which is “Soft Wrap at Preferred Line Length”. If it is unchecked, soft wrap will wrap at the window width. If it is checked, soft wrap will wrap at the column of the Preferred Line Length setting.

It looks like you have Soft Wrap on but Soft Wrap at Preferred Line Length off, based on your screenshot. wrap-guide always shows the preferred line length … not the actual point where soft wrapping will occur.


I tried turning on soft wrap at preferred line length, but it seems like it is also assuming fixed-width without any padding like soft wrap. Changing the window width affects the wrap point, but the wrap point remains too far to the right by the width of the padding. Any idea if it’s possible for a package to implement custom wrapping, or is that something that needs to be done in core packages?


I’m still not entirely sure what the issue is. Are you saying the wrap-guide line is in the wrong place? Or are you saying that the point at which text is wrapped is in the wrong place?


What I understand is that the indentation we see are fake. Bascially the whole file start at column 0, but using clever scoping css, he create indentation.

Soft wrap do not seems to wrap based on pixel, and rather character count. At a fixed character count the end of line would be offset the same way as the start. So he try to set a different softwrap point based on each scope.


Ah, thanks for clarifying, @jeancroy. That makes things much clearer. And yes, soft wrap is either by character count or by window edge. It’s possible that it could be done differently … but another algorithm would have to be added for calculating it. This would further complicate the soft wrap settings, making them more confusing.


BTW @superlou, it looks like markup allow whitespace at the beggining of line.
So instead of faking indentation with padding you could go the autoindent route and create real indentation using tab or spaces.


Jeancroy did a better job explaining my goal than I did. Initially I had been trying to avoid auto-indentation since that modifies the underlying text file. While it’s allowed in Fountain markup, in my experience, I haven’t seen it much. Is it something that could be done by any core auto-indent functionality, or would it have to be custom logic? If soft-wrapping can only be done by character width and not by pixel, I’m probably stuck going that route anyway.

There is some appeal in using tabs and line breaks to create a more script-like output in the final text files, but I was hoping to keep that as an option, and not a requirement.


There is some support for you at the grammar level eg see: increaseIndentPattern
But i do not beleive it will do wild stuff like increase 4 level in one shot in order to center a character name.

Finaly if character & scene name are short, maybe you can leave thing as is and only care about bulk text wrap.


Could I inspect the text near the cursor as the user is typing to create hardwraps and script-like indenting, or would that cause big performance issues?


There are two events:

If onDidChange causes too much of a performance hit, you could use onDidStopChanging instead.


Here’s one example I found where the editor copy (increase?) identation level on newline.