Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling preedit from Lua addon #14

Open
hankei6km opened this issue Feb 2, 2022 · 2 comments
Open

Handling preedit from Lua addon #14

hankei6km opened this issue Feb 2, 2022 · 2 comments

Comments

@hankei6km
Copy link

Thank you for developing.

I updated from Fcitx to Fcitx5 a few days ago.
Currently used with mozc. It works very well.

I have some questions and requests.

Background

I have developed Addon for Fcitx(Fcitx4).

https://github.com/hankei6km/fcitx-at-esc

This addon doesn't work with Fcitx5, so I want to develop a new addon with Lua.

The main features of addon that are planned are as follows.

Execute the following when ESC is pressed.

Commit the text in the pre-editing to context
    ==> Deactivate IME
        ==> Pass through ESC (to Vim etc.)

I wrote the following code, but couldn't get the preedit status.

local fcitx = require("fcitx")

function deactivateInputMethod()
  os.execute("sh -c 'dbus-send --session --print-reply --dest=org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1.Deactivate >/dev/null &'")
end

local forceDeactivate = false

local confForceDeactivate = false
local confCommitPreedit = false

fcitx.watchEvent(fcitx.EventType.KeyEvent, "keyEventHandler")

function keyEventHandler(sym, state, release)
  if (sym == 65307 and state == 0) and not release then
    if preedit then
      if confCommitPreedit then
        -- fcitx.commitPreedit()
      end
      if confForceDeactivate then
        -- fcitx.deactivateInputMethod()
        deactivateInputMethod()
      end
    else
      -- fcitx.deactivateInputMethod()
      deactivateInputMethod()
    end
  end
  return false
end

Question

  • Is there a way to get the preedit status and text from Lua addon?
  • Is there a way to commit the pre-edit text from Lua addon?

Feature request

It would be helpful if the following features were implemented.

  • preedit flag in KeyEvent haandler
  • fcitx.commitPreedit()
  • fcitx.deactivateInputMethod()
fcitx.watchEvent(fcitx.EventType.KeyEvent, "keyEventHandler")

function keyEventHandler(sym, state, release, preedit)
  if (sym == 65307 and state == 0) and not release then
    if preedit then
      if confCommitPreedit then
        fcitx.commitPreedit()
      end
      if confForceDeactivate then
        fcitx.deactivateInputMethod()
      end

      -- snip

end

or

  • text argument in UpdatePreedit event handler
local curPreeditText = ""

fcitx.watchEvent(fcitx.EventType.UpdatePreedit, "updatePreeditHandler")

function updatePreeditHandler(text)
  -- print(text)
  curPreeditText = text
end
@wengxt
Copy link
Member

wengxt commented Feb 2, 2022

While we could extend API to expose more operation, in terms of "commit preedit", it can be tricky to initiate such operation from out side because there is no such logic in fcitx.

The best thing you could do would be like (pseudo code).

if fcitx.capabilityFlags & fcitx.CapabillityFlag.Preedit != 0 then
   preedit =  fcitx.preedit()
else
   preedit = fcitx.clientPreedit()
end
fcitx.commitString(preedit)
fcitx.reset()

Just to let you know ahead. It can cause bug because there are some input method do their own "commit preedit" upon reset, but in most case it should be OK.

@hankei6km
Copy link
Author

The best thing you could do would be like (pseudo code).

I would be happy API presented in pseudo code was implemented in fcitx5-lua.

Just to let you know ahead. It can cause bug because there are some input method do their own "commit preedit" upon reset, but in most case it should be OK.

Thank you for the information.
I plan to add a "commit preedit" flag(confCommitPreedit) to my addon in case it conflicts with "preedit commit" from the input method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants