• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

コミットメタ情報

リビジョンa2cd2b640e4a16710e53798556a03281640b0f7d (tree)
日時2020-10-03 19:11:44
作者dyknon <dyknon@user...>
コミッターdyknon

ログメッセージ

カーソルが見える。

変更サマリ

差分

--- a/extroot/extension.js
+++ b/extroot/extension.js
@@ -28,12 +28,31 @@ const IBusManager = imports.misc.ibusManager;
2828
2929 const {IBus, Pango, St} = imports.gi;
3030
31+var _cursor_letter = "|"; //"\u20ed";
32+var _cursor_combining = false;
33+var _cursor_utf8_cnt;
34+
3135 var _style_pango_attributes;
3236 var _preedit_handle_id = void 0;
3337 var _style_handle_id = void 0;
3438 const _disablers = [];
3539
40+function utf8_len(c){
41+ if(c < 0x80){
42+ return 1;
43+ }else if(c < 0x800){
44+ return 2;
45+ }else if(c < 0x10000){
46+ return 3;
47+ }else{
48+ return 4;
49+ }
50+}
51+
3652 function init(){
53+ if(_cursor_letter !== void 0){
54+ _cursor_utf8_cnt = utf8_len(_cursor_letter.codePointAt(0))
55+ }
3756 }
3857
3958 function enable(){
@@ -119,45 +138,48 @@ function connect_signals(candidate_popup){
119138 // text.get_text(): Javascript string object.
120139 // Its indexes are based on UTF-16 code units.
121140 const text_string = text.get_text();
141+ let newstring = text_string;
122142 const attrs = text.get_attributes();
123- const chars = [];
124- const codes = [];
125- { // split chars
143+ const utf8i = [0];
144+ {
145+ let unicode_count = 0;
126146 let utf16_count = 0;
147+ let utf8_count = 0;
127148 while(utf16_count < text_string.length){
128- const code = text_string.charCodeAt(utf16_count);
129- if(0xd800 <= code && code <= 0xdbff){
130- const lo = text_string.charCodeAt(utf16_count+1);
131- if(0xdc00 <= lo && lo <= 0xdfff){
132- utf16_count += 2;
133- chars.push(String.fromCharCode(code, lo));
134- codes.push(((code&0x3ff) << 10 | lo&0x3ff) + 0x10000);
135- continue;
149+ if(_cursor_letter !== void 0 && cursorPosition == unicode_count){
150+ if(!_cursor_combining || unicode_count){
151+ newstring = "";
152+ newstring += text_string.substring(0, utf16_count);
153+ newstring += _cursor_letter;
154+ newstring += text_string.substring(utf16_count);
155+ utf8_count += _cursor_utf8_cnt;
136156 }
137157 }
138- utf16_count += 1;
139- chars.push(String.fromCharCode(code));
140- codes.push(code);
141- }
142- }
143- const utf8i = [0];
144- { // generate byte index list of utf-8 representation
145- let i = 0;
146- for(const c of codes){
147- if(c < 0x80){
148- i += 1;
149- }else if(c < 0x800){
150- i += 2;
151- }else if(c < 0x10000){
152- i += 3;
158+
159+ const code = text_string.codePointAt(utf16_count);
160+ if(code > 0xffff){
161+ utf16_count += 2;
153162 }else{
154- i += 4;
163+ utf16_count += 1;
164+ }
165+
166+ utf8_count += utf8_len(code);
167+ unicode_count++;
168+
169+ utf8i.push(utf8_count);
170+ }
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;
155178 }
156- utf8i.push(i);
157179 }
158180 }
159181
160- candidate_popup._preeditText.text = text_string;
182+ candidate_popup._preeditText.text = newstring;
161183 const pango_attrs = _style_pango_attributes.copy();
162184 { // Translate iBus attributes to Pango one.
163185 let attr;