pi314 / ime.vim

A Vim input method engine
BSD 2-Clause "Simplified" License
84 stars 3 forks source link

讓 standalone plugin 決定送字的 key #26

Closed pi314 closed 7 years ago

pi314 commented 7 years ago

目前是 hard code 成 <space>,但如果要讓 core 繼續抽象化,需要考慮其他輸入法的習慣。

例如注音輸入法的送字可能會在 3(ˇ)、4(ˋ)、6(ˊ)、<space> 觸發,如果要做得更友善,可能會在每個 key 都觸發。

這個想法還在考慮中,如果要納入注音輸入法,就得考慮選字選詞的問題,

pi314 commented 7 years ago

Standalone plugin 需要再提供 trigger = [keys] 資訊,handler()s:SendKey() 也要傳入按下的 key。

切換模式的時候,core 要先把前一個模式的 key 都 unmap,再把新模式的 triggerinoremap

pi314 commented 7 years ago

突然想到一個可能很嚴重的問題,如果讓 standalone plugin 決定送字的 key,所有的 embedded plugin 都會受到影響。

pi314 commented 7 years ago

想到一個方法,讓 embedded plugin 也提供 triggers:SendKey() 在檢查 embedded plugin 的時候,先檢查該 plugin 是否接受那個按鍵。


另一個還沒測試過的東西是 <space>,不知道這個鍵傳進 function 裡會是 "<space>" 還是 " "

pi314 commented 7 years ago

另一個還沒測試過的東西是 ,不知道這個鍵傳進 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 的風險,現在是先假設不會指定雙引號 "

pi314 commented 7 years ago

今天測了一下發現還有 < escape 的問題,雖然已經在 abstract branch 上解決了,還是貼在這裡

execute 'inoremap '. l:trigger .' <C-R>=<SID>SendKey("'. substitute(l:trigger, '<', '<lt>', 'g') .'")<CR>'
pi314 commented 7 years ago

a70ac5c c15255e 37af30b