pyim icon indicating copy to clipboard operation
pyim copied to clipboard

rime中空码时自动上屏之前首选

Open DogLooksGood opened this issue 6 years ago • 21 comments

我使用的输入法在空码的时候会直接上屏之前的首选。 大致规则是,除了aoeui的编码只能出现在一个字的前两码。 如果输入 siurjft,就会按照 siu, rj, ft在输入过程中自动上屏前两个字。

但是在pyim中,配合rime使用,在空码的时候编码会直接刷新。猜测:

  1. 没有捕获到rime的上屏行为
  2. pyim只通过rime提供候选,不同步rime的上屏行为

有没有办法比较简单的办法实现我所要的效果?例如当编码串的头部发生变化时上屏之前的首选。

P.S. 有没有办法隐藏候选框。

DogLooksGood avatar Aug 29 '19 21:08 DogLooksGood

没太看懂什么意思

tumashu avatar Aug 30 '19 04:08 tumashu

可能是我表达不清。 有一类输入法并不是固定码长上屏,而是空码上屏。

比如当前的编码 hn 候选为

  1. 好 2. 郝

此时输入d 编码为 hnd 但是hnd是没有对应的字的,这个时候自动上屏, 剩余编码为d

我的问题是,我在rime中使用的是这样的方式,但是原本在rime中应该自动上屏的时候,在pyim里面只是把编码清空了。

DogLooksGood avatar Aug 30 '19 07:08 DogLooksGood

这种上屏模式倒是没有研究过

tumashu avatar Aug 30 '19 11:08 tumashu

这样的模式在pyim中本身有办法支持吗

DogLooksGood avatar Aug 30 '19 13:08 DogLooksGood

难道你没遇到 好 不是你想要的吗,那要删除多麻烦

QiangF avatar Sep 03 '19 00:09 QiangF

@QiangF Hi 这类输入法的编码特点就是这样的,不存在候选,只有编码敲错了会有这个情况。好处就是除了一简也不需要打空格了。

DogLooksGood avatar Sep 03 '19 01:09 DogLooksGood

这样的模式在pyim中本身有办法支持吗

还没有仔细研究。。。

tumashu avatar Sep 03 '19 05:09 tumashu

大多数输入法会有一个空码行为的设置。 比如清空,顶屏,什么都不做之类的。

DogLooksGood avatar Sep 03 '19 06:09 DogLooksGood

我添加了 pyim-autoselector 的概念, 也许可以实现你需要的功能 下面的 myautoselector 估计可以用于型码类的词库,无法用于拼音

简单来说,就是用已经输入的字符串,配合词库前缀,来生成一个 词库 code, 然后在词库中搜索这个 code,如果找不到,就自动上屏,

输入的字符串构建 code,对于型码来说就比较简单

(push 'pyim-autoselector-xxx pyim-autoselector)

(defun pyim-autoselector-xxx (&rest args)
  (let* ((scheme-name (pyim-scheme-name))
         (class (pyim-scheme-get-option scheme-name :class))
         (prefix (pyim-scheme-get-option scheme-name :code-split-length))
         (words (pyim-dcache-get
                 (concat prefix
                         (pyim-entered-get)
                         (string last-command-event))
                 '(code2word shortcode2word icode2word))))
    (and (pyim-input-chinese-p)
         (not words))))


tumashu avatar Sep 06 '19 06:09 tumashu

@DogLooksGood

tumashu avatar Sep 06 '19 06:09 tumashu

这段代码是我可以直接拿来使用吗,我可以把他用于pyim + rime使用,还是只能用于pyim

DogLooksGood avatar Sep 06 '19 08:09 DogLooksGood

如果是用 rime, 那么 words 的获取方式就要改变一下,这个无法通用

tumashu avatar Sep 06 '19 08:09 tumashu

类似这样子:

(defun my-rime-get (s)
  (when (functionp 'liberime-clear-composition)
    (liberime-clear-composition)
    (dolist (key (string-to-list s))
      (liberime-process-key key))
    (let* ((context (liberime-get-context))
           (menu (alist-get 'menu context))
           (candidates (alist-get 'candidates menu)))
      candidates)))

(push 'pyim-autoselector-xxx pyim-autoselector)

(defun pyim-autoselector-xxx (&rest args)
  (let* ((scheme-name (pyim-scheme-name))
         (class (pyim-scheme-get-option scheme-name :class))
         (prefix (pyim-scheme-get-option scheme-name :code-split-length))
         (words (my-rime-get
                 (concat (pyim-entered-get)
                         (string last-command-event))))
    (and (pyim-input-chinese-p)
         (not words))))

tumashu avatar Sep 06 '19 08:09 tumashu

好的,我试一下

DogLooksGood avatar Sep 06 '19 09:09 DogLooksGood

你那边 rime 用的可以?

tumashu avatar Sep 06 '19 09:09 tumashu

@tumashu ,Hi 测试了一下,似乎并不能成功上屏,表现的行为和之前是一致的。 还有一个问题是,如果第一码没有有效编码时会有一错误。

DogLooksGood avatar Sep 08 '19 13:09 DogLooksGood

pyim-autoselector-xxx 返回为t的时候,就自动上屏, 我给你的那段代码没有测试过,因为我这边 rime 环境无法编译 @DogLooksGood

tumashu avatar Sep 12 '19 05:09 tumashu

@tumashu 返回t的时候上屏,这段代码是指上屏的上一个编码的首选吗?

DogLooksGood avatar Sep 13 '19 08:09 DogLooksGood

如果输入hnd,这段代码就判断hnd是否有对应候选词,如果没有,就返回t,hn自动上屏幕

tumashu avatar Sep 13 '19 08:09 tumashu

last-command-event 代表你最后输入的字符

tumashu avatar Sep 13 '19 08:09 tumashu

会不会是这段代码中要求码长达到了某个条件才可以?这我这里并没有上屏。但是一个有效的编码按空格手工上屏是可以的,所以rime本身使用没有问题。

DogLooksGood avatar Sep 21 '19 12:09 DogLooksGood