Set pending when compositionend event is dispatched #326

Closed
shimbaco wants to merge 2 commits from dispatch-compositionend into master
shimbaco commented 2020-10-31 06:51:45 +01:00 (Migrated from github.com)

I noticed to change autocompletion state to Result when enter key is pressed with Japanese IME (e.g. Google IME). So I can not autocomplete text.
This PR will fix it by changing autocompletion state to Pending when the compositionend event is dispatched.

master This PR
Kapture 2020-10-31 at 14 37 24 Kapture 2020-10-31 at 14 31 55
I noticed to change autocompletion state to `Result` when enter key is pressed with Japanese IME (e.g. [Google IME](https://www.google.co.jp/ime/)). So I can not autocomplete text. This PR will fix it by changing autocompletion state to `Pending` when the `compositionend` event is dispatched. | master | This PR | | --- | --- | | ![Kapture 2020-10-31 at 14 37 24](https://user-images.githubusercontent.com/56767/97772206-24183300-1b88-11eb-9673-064368405814.gif) | ![Kapture 2020-10-31 at 14 31 55](https://user-images.githubusercontent.com/56767/97772015-0f3aa000-1b86-11eb-8bcd-be8e1d089731.gif) |
marijnh commented 2020-11-04 14:15:49 +01:00 (Migrated from github.com)

The problem, as far as I can see (using Linux's IBus IME), is that when the IME menu is open, the selection is moved to the start of the composition, confusing the completion (in the case where the composition starts a word it won't complete anything, in cases where it continues a word it'll only complete up to the selection start). Then when the composition finishes, the cursor is moved to its end, but since that transaction doesn't change the document, the completion state isn't appropriately updated and no completion is started for the composed text.

Thanks for coming up with a patch. However, I don't think it's a good idea to fire a transaction for this, especially since event delivery order around compositions is a bit of a mess, and thus this new transaction might end up being ordered strangely relative to the document or selection changes caused by the composition end.

Path 0ef664d adds a little state machine to the completion plugin that checks for the problematic situation (composition made changes, but then moved the selection before ending), and manually restarts completion when that occurs. Does that work for you? (I only tested with Firefox/Linux so far.)

The problem, as far as I can see (using Linux's IBus IME), is that when the IME menu is open, the selection is moved to the start of the composition, confusing the completion (in the case where the composition starts a word it won't complete anything, in cases where it continues a word it'll only complete up to the selection start). Then when the composition finishes, the cursor is moved to its end, but since that transaction doesn't change the document, the completion state isn't appropriately updated and no completion is started for the composed text. Thanks for coming up with a patch. However, I don't think it's a good idea to fire a transaction for this, especially since event delivery order around compositions is a bit of a mess, and thus this new transaction might end up being ordered strangely relative to the document or selection changes caused by the composition end. Path 0ef664d adds a little state machine to the completion plugin that checks for the problematic situation (composition made changes, but then moved the selection before ending), and manually restarts completion when that occurs. Does that work for you? (I only tested with Firefox/Linux so far.)
shimbaco commented 2020-11-06 19:47:55 +01:00 (Migrated from github.com)

Thank you for your review and the commit! I tried on latest master and it doesn't work that I expected. (Tested with macOS/Chrome/Google IME)

  • expected: The completion menu is continued to open when I press enter key and the IME menu is closed
  • actual: The completion menu is closed

But the startCompletionEffect which you added is useful. I can create a plugin which I want like this (may be tricky...):

const myAutocompletionPlugin = ViewPlugin.fromClass(class {
  // ...
}, {
  eventHandlers: {
    compositionend(this: {view: EditorView}) {
      this.view.dispatch({effects: startCompletionEffect.of(true)})
    }
  } as any
})

I understand that my patch has problem. I'll close this PR and try to customise by creating a plugin.

Thank you!

Thank you for your review and the commit! I tried on latest master and it doesn't work that I expected. (Tested with macOS/Chrome/Google IME) - expected: The completion menu is continued to open when I press enter key and the IME menu is closed - actual: The completion menu is closed But the `startCompletionEffect` which you added is useful. I can create a plugin which I want like this (may be tricky...): ```ts const myAutocompletionPlugin = ViewPlugin.fromClass(class { // ... }, { eventHandlers: { compositionend(this: {view: EditorView}) { this.view.dispatch({effects: startCompletionEffect.of(true)}) } } as any }) ``` I understand that my patch has problem. I'll close this PR and try to customise by creating a plugin. Thank you!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/dev!326
No description provided.