Closed pi314 closed 7 years ago
Standalone plugin 需要再提供 trigger = [keys]
資訊,handler()
和 s:SendKey()
也要傳入按下的 key。
切換模式的時候,core 要先把前一個模式的 key 都 unmap
,再把新模式的 trigger
都 inoremap
突然想到一個可能很嚴重的問題,如果讓 standalone plugin 決定送字的 key,所有的 embedded plugin 都會受到影響。
想到一個方法,讓 embedded plugin 也提供 trigger
。
s:SendKey()
在檢查 embedded plugin 的時候,先檢查該 plugin 是否接受那個按鍵。
另一個還沒測試過的東西是 <space>
,不知道這個鍵傳進 function 裡會是 "<space>"
還是 " "
。
另一個還沒測試過的東西是
,不知道這個鍵傳進 function 裡會是 " " 還是 " "。
昨天腦洞,今天想通了,就是 "<space>"
" execute 'inoremap <space> <C-R>=<SID>SendKey()<CR>'
for l:trigger_key in s:boshiamy_mode['trigger']
execute 'inoremap '. l:trigger_key .' <C-R>=<SID>SendKey("'. l:trigger_key .'")<CR>'
endfor
當然這樣會有引號 escape 的風險,現在是先假設不會指定雙引號 "
今天測了一下發現還有 <
escape 的問題,雖然已經在 abstract
branch 上解決了,還是貼在這裡
execute 'inoremap '. l:trigger .' <C-R>=<SID>SendKey("'. substitute(l:trigger, '<', '<lt>', 'g') .'")<CR>'
a70ac5c c15255e 37af30b
目前是 hard code 成
<space>
,但如果要讓 core 繼續抽象化,需要考慮其他輸入法的習慣。例如注音輸入法的送字可能會在
3
(ˇ
)、4
(ˋ
)、6
(ˊ
)、<space>
觸發,如果要做得更友善,可能會在每個 key 都觸發。這個想法還在考慮中,如果要納入注音輸入法,就得考慮選字選詞的問題,