coteditor / CotEditor

Lightweight Plain-Text Editor for macOS
https://coteditor.com
Other
6.24k stars 427 forks source link

Tab character visibility #1531

Closed strauhmanis closed 9 months ago

strauhmanis commented 9 months ago

Hello!

Is your feature request related to a problem? Please describe. Yes. The problem is that sections that are separated by Tab within a line can be hard to discern.

Describe the solution you'd like I would like to see an option that would allow to set a static defined length of a Tab character, please.

Describe alternatives you've considered Can't think of any.

Additional context Please see 1min video at the link below: https://vimeo.com/870628976/a8c13a1f6c

Thank you very much!

ShikiSuen commented 9 months ago

Are you using macOS 14.0 Sonoma?

strauhmanis commented 9 months ago

Are you using macOS 14.0 Sonoma?

Yes, I do.

ShikiSuen commented 9 months ago

@strauhmanis Then I found the prime cause. @1024jp could you please enforce that the editor uses .kern = 0 if it uses any NSAttributedString? macOS 14 has introduced an undocumented change regarding how to compress the CJK puncutations (which is a terrible implementation). Force .kern = 0 can avoid this behavior.

1024jp commented 9 months ago

@strauhmanis Thank you for the report. To test whether the advice by @ShikiSuen works, could you tell me the font settings you are using. I need the status of the antialias and ligature settings as well as the font name and size.

@ShikiSuen Thank you for the advice. It helps me a lot.

strauhmanis commented 9 months ago

@ShikiSuen and @1024jp thank you both for your help!

The name of the font I'm using is "JetBrains Mono Slashed": https://github.com/sharpjs/JetBrainsMonoSlashed Please see a short video to learn about all the settings: https://vimeo.com/872770481/c5d94c9e75

Thank you very much!

1024jp commented 9 months ago

I've studied this phenomenon in the last few days. And figured out:

  1. The issue does not relate to the kerning, which @ShikiSuen suggested. (But thank you @ShikiSuen, I appreciate providing such information that helps debugging.)
  2. The same phenomenon occurs also in macOS 13.
  3. This is a (kind of) issue in TextKit, the high-level text processing framework provided by Apple, due to the error by the floating-point calculation in for the indentation width.

Thus, from my point of view, the third item is the cause of this issue. I figured out that TextKit does not give a full tab width space even if the gap between the characters before and after a tab is (almost) zero in some specific conditions. I suppose the tab width should have the full width in those conditions, at least when the gap is less than 1px. I also explored a way to work around it, but could not find it, at least in an efficient way. So, I'll report this to Apple so that they can handle it in a better way.

Then, looking back on the @strauhmanis's request in the original post:

I would like to see an option that would allow to set a static defined length of a Tab character, please.

Your request is not to avoid this unintuitive character layout, namely the zero-width tab, but to provide a specific fixed width to all tab characters in the editor. However, it is the nature of a tab character that it has not a fixed width but an elastic width. A tab character is not a character that has a wide customizable space. I will not set it fixed even as an optional setting. Moreover, I think this is also not a standard option in text editors other than CotEditor.

To summarize, I need to say:

  1. I reject the original request of this thread.
  2. I confirmed there is an issue that a tab character can be zero-width under specific conditions (character order, font, etc...), but it cannot be workaround at a 3rd party app level.
1024jp commented 9 months ago

@ShikiSuen By the way, the kerning issue you pointed out can be another topic. I suppose this kind of unwanted kerning in monospaced fonts (actually in a fallback font of the monospaced font) should be avoided when the user intentionally uses a monospaced font.

So, could you provide the conditions to reproduce such a problematic kerning with CJK punctuations? I need:

  1. font settings, namely font name and size.
  2. some sample texts that can reproduce the issue.
ShikiSuen commented 9 months ago

@1024jp

image
  1. The font is Sarasa Fixed Slab TC from https://github.com/be5invis/Sarasa-Gothic . I already set CotEditor settings to use Monospace.
  2. The sample is here ( 8 chars per each line):
    八月中秋山林涼,風吹大地草枝擺。
    八八八八八八八八八八八八八八八八
    image

BTW you might want to see this: https://github.com/ShikiSuen/NSAttributedStringKernIssueDemo

1024jp commented 9 months ago

@ShikiSuen Thank you! I've just added [.kern] = 0 for the monospaced font for the editor.

ShikiSuen commented 9 months ago

@1024jp You're welcome. Does it work well?

1024jp commented 9 months ago

@ShikiSuen Yes, yes. It works as you described.