Skip to content

Commit

Permalink
term: complete support for IME & CJK rendering
Browse files Browse the repository at this point in the history
this fixes #75 and #47, two bugs originated long long ago.

1. Added support for IME events `compositionstart` `compositionupdate` and `compositionend`.
2. Refactored some code to receive input events from a hidden textarea just as how `xterm.js` now does. This removes the need to set `contentEditable` on the body in order to receive IME compistion events, and also guides the IME input box correctly following the cursor.
3. Fixed CJK rendering. Forces "forceWidth" mode with double width on those known CJK ranges in Unicode. Corrected the placeholder logic of the force width mode. Note that some rare halfwidth CJK characters will still not render correctly without `force-unicode-width` enabled. If you see any issue, please enable the `--force-unicode-width` option.
4. Miscallaneous fixes for some problems after introducing the above change

Tested on Firefox Nightly 62 on Linux and Chromium 67 on Linux, with `fcitx` as input method.
  • Loading branch information
PeterCxy committed Jun 3, 2018
1 parent 41ee5fb commit 34b6287
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 37 deletions.
15 changes: 15 additions & 0 deletions butterfly/sass/_layout.sass
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,20 @@ body
padding: .5em
font-size: .75em

#input-view
position: fixed
z-index: 100
padding: 0
margin: 0
text-decoration: underline

#input-helper
position: fixed
z-index: -100
opacity: 0
white-space: nowrap
overflow: hidden
resize: none

.terminal
outline: none
2 changes: 2 additions & 0 deletions butterfly/static/ext.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions butterfly/static/ext.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions butterfly/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2861,6 +2861,19 @@ body {
display: block;
padding: .5em;
font-size: .75em; }
body #input-view {
position: fixed;
z-index: 100;
padding: 0;
margin: 0;
text-decoration: underline; }
body #input-helper {
position: fixed;
z-index: -100;
opacity: 0;
white-space: nowrap;
overflow: hidden;
resize: none; }

.terminal {
outline: none; }
Expand Down
126 changes: 110 additions & 16 deletions butterfly/static/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions butterfly/static/main.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions butterfly/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
data-force-unicode-width="{{ 'yes' if options.force_unicode_width else 'no' }}"
data-root-path="{{ options.uri_root_path }}"
data-session-token={{ session }}>
<textarea id="input-helper">
</textarea>
<div id="input-view" class="hidden">
</div>
<div id="popup" class="hidden">
</div>
<script src="{{ static_url('html-sanitizer.js') }}"></script>
Expand Down
2 changes: 2 additions & 0 deletions coffees/ext/clipboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

addEventListener 'copy', copy = (e) ->
document.getElementsByTagName('body')[0].contentEditable = false
butterfly.bell "copied"
e.clipboardData.clearData()
sel = getSelection().toString().replace(
Expand All @@ -35,6 +36,7 @@ addEventListener 'copy', copy = (e) ->


addEventListener 'paste', (e) ->
document.getElementsByTagName('body')[0].contentEditable = false
butterfly.bell "pasted"
data = e.clipboardData.getData 'text/plain'
data = data.replace(/\r\n/g, '\n').replace(/\n/g, '\r')
Expand Down
Loading

0 comments on commit 34b6287

Please sign in to comment.