• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision14d693b8a8ad77af24f48f1aa371b7efb35a3356 (tree)
Time2020-10-04 06:27:48
Authordyknon <dyknon@user...>
Commiterdyknon

Log Message

simplify

Change Summary

Incremental Difference

--- a/extroot/extension.js
+++ b/extroot/extension.js
@@ -133,10 +133,11 @@ function connect_signals(candidate_popup){
133133 _preedit_handle_id = candidate_popup._panelService.connect(
134134 "update-preedit-text",
135135 (ps, text, cursorPosition, visible) => {
136- // cursorPosition: index start from 0; counting Unicode characters.
137- // XXX: How about combining characters?
138- // text.get_text(): Javascript string object.
139- // Its indexes are based on UTF-16 code units.
136+ // Text length and position representations
137+ // iBus: index start from 0; counting Unicode characters.
138+ // XXX: How about combining characters?
139+ // Javascript: Counts UTF-16 code units.
140+ // Pango: Counts UTF-8 bytes.
140141 const text_string = text.get_text();
141142 let newstring = text_string;
142143 const attrs = text.get_attributes();
@@ -145,16 +146,23 @@ function connect_signals(candidate_popup){
145146 let unicode_count = 0;
146147 let utf16_count = 0;
147148 let utf8_count = 0;
148- while(utf16_count < text_string.length){
149- if(_cursor_letter !== void 0 && cursorPosition == unicode_count){
150- if(!_cursor_combining || unicode_count){
149+ let cursor = () => {};
150+ if(_cursor_letter !== void 0){
151+ cursor = () => {
152+ if(
153+ cursorPosition == unicode_count
154+ && (!_cursor_combining || unicode_count)
155+ ){
151156 newstring = "";
152157 newstring += text_string.substring(0, utf16_count);
153158 newstring += _cursor_letter;
154159 newstring += text_string.substring(utf16_count);
155160 utf8_count += _cursor_utf8_cnt;
156161 }
157- }
162+ };
163+ }
164+ while(utf16_count < text_string.length){
165+ cursor();
158166
159167 const code = text_string.codePointAt(utf16_count);
160168 if(code > 0xffff){
@@ -168,15 +176,7 @@ function connect_signals(candidate_popup){
168176
169177 utf8i.push(utf8_count);
170178 }
171- if(_cursor_letter !== void 0 && cursorPosition == unicode_count){
172- if(!_cursor_combining || unicode_count){
173- newstring = "";
174- newstring += text_string.substring(0, utf16_count);
175- newstring += _cursor_letter;
176- newstring += text_string.substring(utf16_count);
177- utf8_count += _cursor_utf8_cnt;
178- }
179- }
179+ cursor();
180180 }
181181
182182 candidate_popup._preeditText.text = newstring;