rime / squirrel

【鼠鬚管】Rime for macOS
https://rime.im
GNU General Public License v3.0
4.6k stars 412 forks source link

输入法切换导致鼠须管卡死 #482

Open suili opened 3 years ago

suili commented 3 years ago

自使用鼠须管以来,总会时不时出现无法输入中文的状态,如图所示

image

发现使用vscode的vim插件搭配im-select来实现vim不同状态的输入法切换时这个问题出现的尤其频繁,每切换几次后鼠须管就进入了无法输入中文的状态。

于是发现只要在terminal这样反复调用im-select几次,就能复现问题:

im-select com.apple.keylayout.ABC
im-select im.rime.inputmethod.Squirrel.Rime
im-select com.apple.keylayout.ABC
im-select im.rime.inputmethod.Squirrel.Rime

这样鼠须管就会100%进入那种挂掉的状态。(im-select搭配系统原生输入法时则没有这个问题)

系统设置开启“automatically switch to input source”的自动切换似乎也会导致类似的问题,但不方便复现。 用ctrl+space手动切换似乎不存在这样的问题。

Big sur 11.1

Yiklek commented 3 years ago

使用Hammerspoon 调用hs.keycodes.currentSourceIDcom.apple.keylayout.ABC切换到im.rime.inputmethod.Squirrel.Rime同样有此问题。 可复现,用ctrl+space手动切换一次才可恢复。 image

Rime配置: 小鹤音形官方挂载

Hammerspoon 配置: 使用ctrl+option+.切换可复现,切换窗口正常。 设置切换为搜狗输入法正常

local IME_SOGOU = "sogou"
local IME_RIME = "rime"
local IME_ABC = "abc"
local IME = {}

IME[IME_RIME] = "im.rime.inputmethod.Squirrel.Rime"
IME[IME_SOGOU] = "com.sogou.inputmethod.sogou.pinyin"
IME[IME_ABC] = "com.apple.keylayout.ABC"
local USE_IME_CHINESE = IME_RIME
local USE_IME_EN = IME_ABC

local function Chinese()
  hs.keycodes.currentSourceID(IME[USE_IME_CHINESE])
end

local function English()
  hs.keycodes.currentSourceID(IME[USE_IME_EN])
end

local function set_app_input_method(app_name, set_input_method_function, event)
  event = event or hs.window.filter.windowFocused

  hs.window.filter.new(app_name)
    :subscribe(event, function()
                 set_input_method_function()
              end)
end

set_app_input_method('Hammerspoon', English, hs.window.filter.windowCreated)
set_app_input_method('Spotlight', English, hs.window.filter.windowCreated)
set_app_input_method('Alfred', English, hs.window.filter.windowCreated)
set_app_input_method('Emacs', English)
set_app_input_method('iTerm2', English)
set_app_input_method('Alacritty', English)
set_app_input_method('kitty', English)
set_app_input_method('Clion', English)
set_app_input_method('IntelliJ IDEA', English)
set_app_input_method('Google Chrome', Chinese)
set_app_input_method('微信', Chinese)
set_app_input_method('WeChat', Chinese)
set_app_input_method('QQ', Chinese)

hs.hotkey.bind({'ctrl', 'cmd', 'option'}, ".", function()
          hs.alert.show("App path:        "
                ..hs.window.focusedWindow():application():path()
                .."\n"
                .."App name:      "
                ..hs.window.focusedWindow():application():name()
                .."\n"
                .."IM source id:  "
                ..hs.keycodes.currentSourceID())
end)
hs.hotkey.bind({'ctrl', 'option'}, ".", function()
        local ime_id = hs.keycodes.currentSourceID()
        if ime_id == IME[USE_IME_EN] then
            Chinese() 
        elseif ime_id == IME[USE_IME_CHINESE]  then
            English() 
        end
end)

Macos:11.3.1 (20E241) Squirrel:44c7c4608d078e90762a0463583b9560c9a775b9 Hammerspoon:0.9.90 (6030)

HF706 commented 11 months ago

这个并不是Squirrel的问题,其他第三方输入法同样也有,目前找到的方案如下,https://github.com/laishulu/macism ,能用,就是会有一定延迟。