rime / rime/squirrel

Question: Is commit(string: String(cString: input)) necessary in commitComposition(_:)?

Open
#1,074 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
6.4k
Forks
554
PR merge metrics
No merged PRs in 30d

Description

Hi, I’m reviewing the implementation of commitComposition(_:), and I’d like to confirm whether the explicit commit(string:) call here is still necessary.

/*!
   @method
   @abstract   Called when a user action was taken that ends an input session.
   Typically triggered by the user selecting a new input method
   or keyboard layout.
   @discussion When this method is called your controller should send the
   current input buffer to the client via a call to
   insertText:replacementRange:.  Additionally, this is the time
   to clean up if that is necessary.
   */
  override func commitComposition(_ sender: Any!) {
    self.client ?= sender as? IMKTextInput
    // print("[DEBUG] commitComposition: \(sender ?? "nil")")
    //  commit raw input
    if session != 0 {
      if let input = rimeAPI.get_input(session) {
        commit(string: String(cString: input))
        rimeAPI.clear_composition(session)
      }
    }
  }

In commitComposition,
it seems that calling commit(string:) may cause the raw input (such as unfinished Pinyin) to be sent to the client when the candidate window disappears — for example, after taking a screenshot of the candidate list or when the input session ends unexpectedly.

From my observation, this leads to the input buffer being committed even when the user hasn’t confirmed any candidate yet.

Would it be possible to simply remove this commit(string:) call (instead of adding a configuration switch), so that unfinished composition is just cleared when the session ends, without sending the raw input to the text field?

I’m wondering whether there is a specific reason this commit is required (e.g., IMK protocol expectations or compatibility with other clients).

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in sources/SquirrelInputController.swift at commitComposition(_:), especially the get_input, commit(string:), and clear_composition calls. Check the IMKTextInput expectations and the behavior when the candidate window or input session ends. Done means unfinished composition is cleared without being inserted, while confirmed input continues to commit correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.