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

Wrap line at boundary if it includes a CJK character - #9997

Merged
as-cii merged 7 commits into
masterfrom
as-cjk-wrap-boundary
Dec 15, 2015
Merged

as-cii merged 7 commits into
masterfrom
as-cjk-wrap-boundary

Conversation

@as-cii

@as-cii as-cii commented Dec 10, 2015

Copy link
Copy Markdown
Contributor

Fixes #9447.

This PR provides a different strategy for wrapping lines whenever CJK characters are involved. With this PR we try to detect a CJK character before or exactly at the desired wrap boundary: if we do, we perform the wrap; otherwise, we use the old line-breaking algorithm.

Although not compliant with the Unicode spec, this allows users to mix CJK characters with Latin ones without the need to introduce a complex line breaking logic.

Before:

screen shot 2015-12-10 at 10 29 22

After:

screen shot 2015-12-10 at 10 29 44

/cc: @nathansobo @atom/feedback

@as-cii

as-cii commented Dec 10, 2015

Copy link
Copy Markdown
Contributor Author

@chloerei @yukihop: it would be great to hear what you think and, even more awesome if you could build and try this out. ✨

@chloerei

Copy link
Copy Markdown

Example looks good to me.

I want to test in local, but have a problem with building:

Node: v0.12.9
npm: v3.5.1
Installing build modules...
WARN engine [email protected]: wanted: {"node":">= 0.6.0 < 0.11.0"} (current: {"node":"0.12.9","npm":"3.5.1"})
npm ERR! Linux 3.13.0-67-generic
npm ERR! argv "node" "/usr/local/bin/npm" "--userconfig=/vagrant/build/.npmrc" "install" "--loglevel" "error"
npm ERR! node v0.12.9
npm ERR! npm  v3.5.1
npm ERR! path /vagrant/build/node_modules/npm/node_modules/columnify/node_modules/strip-ansi/cli.js
npm ERR! code ENOENT
npm ERR! errno -2

npm ERR! enoent ENOENT, chmod '/vagrant/build/node_modules/npm/node_modules/columnify/node_modules/strip-ansi/cli.js'
npm ERR! enoent ENOENT, chmod '/vagrant/build/node_modules/npm/node_modules/columnify/node_modules/strip-ansi/cli.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

I'm not familiar with npm, after google I can not find some similar problems, any ideas?

Comment thread spec/text-utils-spec.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.

Style nitpick: isCJKCharacter

@nathansobo

Copy link
Copy Markdown
Contributor

Thanks for jumping on this!

@yukihop

yukihop commented Dec 11, 2015

Copy link
Copy Markdown

@as-cii Thanks, the new screenshot looks perfect to me!

@chloerei

Copy link
Copy Markdown

I success build atom on local by downgrade npm to 1.4.28.

It is a big improvement. But I found it will leave a large space in some situation, for example:

Line length 80

中文中文中文中文中文中文中文中文 English 中文中文中文中文中文中文中文中文中文中文中文中文。En

When add one more English character, it becomes:

中文中文中文中文中文中文中文中文 English
中文中文中文中文中文中文中文中文中文中文中文中文。Eng

@as-cii

as-cii commented Dec 11, 2015

Copy link
Copy Markdown
Contributor Author

@chloerei: what behavior would you expect in that case? Seems like we should wrap at the beginning of the english word, as Chrome does.

I have pushed a couple of commits that refine the previous behavior to address your concerns. Could you pull this again and try it out? Thanks so much for helping out with this, @chloerei! ✨

@chloerei

Copy link
Copy Markdown

👍 I test with my blog posts and feel it's great!

@as-cii

as-cii commented Dec 11, 2015

Copy link
Copy Markdown
Contributor Author

Great, I am going to 🚢 this as soon as the build gets 💚.

Thank you!

@yukihop

yukihop commented Dec 12, 2015

Copy link
Copy Markdown

Hi, I'm still having trouble building Atom on Windows, but judging from the committed code, here's how I feel. I'm totally new to Atom dev, and I've never treated Unicode seriously, so I might be wrong.

  • isJapaneseCharacter function seems to also cover CJK symbols and punctuation, which is not really Japanese-specific.
  • Aside from this, isJapaneseCharacter basically checks if the character is a hiragana or katakana, but hiragana/katakana are only a part of Japanese characters. This function may be renamed to IsJapaneseKanaCharacter or IsJapaneseKana.
  • Shouldn't isCJKUnifiedIdeograph also cover CJK unified ideographs extensions described here? These extensions contain very rare characters (kanji) which are unlikely to cause big problems in real life situations, though.
  • I believe at least one hiragana and one katakana character should be included in the isCJKCharacter test. Naturally-written Japanese sentences consist of many of those characters.
  • Despite what I've said, I kind of feel all the characters at least from U+3000 to U+9FFF in this table can be treated in the same way as ordinary kanji (U+4E00 - U+9FFF) (i.e., line breaks can happen anywhere between these characters)

@as-cii

as-cii commented Dec 12, 2015

Copy link
Copy Markdown
Contributor Author

Thanks @yukihop for writing down these thoughts, I appreciate them a lot! 👍

isJapaneseCharacter function seems to also cover CJK symbols and punctuation, which is not really Japanese-specific.

Aside from this, isJapaneseCharacter basically checks if the character is a hiragana or katakana, but hiragana/katakana are only a part of Japanese characters. This function may be renamed to IsJapaneseKanaCharacter or IsJapaneseKana.

I believe at least one hiragana and one katakana character should be included in the isCJKCharacter test. Naturally-written Japanese sentences consist of many of those characters.

Those are really good points. 👍 I will address them shortly.

Despite what I've said, I kind of feel all the characters at least from U+3000 to U+9FFF in this table can be treated in the same way as ordinary kanji (U+4E00 - U+9FFF) (i.e., line breaks can happen anywhere between these characters)

Shouldn't isCJKUnifiedIdeograph also cover CJK unified ideographs extensions described here? These extensions contain very rare characters (kanji) which are unlikely to cause big problems in real life situations, though.

Yeah, that was basically the reason why I did not include them originally. I think, however, we should add them just to be sure to cover every edge case and be more bulletproof. Will change this PR to fix those as well.

Thanks a lot, @yukihop! Having a second pair of 👀 on CJK characters is definitely awesome!

@as-cii

as-cii commented Dec 14, 2015

Copy link
Copy Markdown
Contributor Author

Okay, I slightly adjusted names and partially extended the ranges checked in isCJKUnifiedIdeograph. I will open another PR after 🚢ping this one which addresses CJK Unified Ideograph Extensions Tables.

as-cii added a commit that referenced this pull request Dec 15, 2015
Wrap line at boundary if it includes a CJK character
@as-cii
as-cii merged commit 14f959e into master Dec 15, 2015
@as-cii
as-cii deleted the as-cjk-wrap-boundary branch December 15, 2015 11:09
@bicycle1885

Copy link
Copy Markdown

@as-cii Thank you! I hope this fix will be included in the next bug fix release. I really need this one 🙏

@as-cii

as-cii commented Dec 15, 2015

Copy link
Copy Markdown
Contributor Author

Yeah, I think we are going to release this one under 1.5.0 and 1.5.0-beta0.

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.

5 participants