Skip to content

Commit

Permalink
Fix handling compositions in Firefox on Linux
Browse files Browse the repository at this point in the history
Fixes #489
  • Loading branch information
javan committed Mar 1, 2018
1 parent e5ca869 commit 89c9544
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/trix/controllers/input_controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class Trix.InputController extends Trix.BasicObject
@responder?.insertString(string)
@setInputSummary(textAdded: string, didDelete: @selectionIsExpanded())

keyup: (event) ->
@inputSummary.didInput = true

textInput: (event) ->
# Handle autocapitalization
{data} = event
Expand Down
20 changes: 20 additions & 0 deletions test/src/system/composition_input_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@ testGroup "Composition input", template: "editor_empty", ->
assert.locationRange(index: 0, offset: 2)
expectDocument("éé\n")

# Simulates compositions in Firefox on Linux, which aren't preceded by
# keydown and don't dispatch input after compositionupdate.
test "composition with limited contextual keyboard and input events", (expectDocument) ->
element = getEditorElement()
element.editor.insertString("i")
element.editor.setSelectedRange(1)
defer ->
triggerEvent(element, "keyup", charCode: 0, keyCode: 0, which: 0)
triggerEvent(element, "compositionstart", data: "")
triggerEvent(element, "compositionupdate", data: "ó")
node = document.createTextNode("ó")
insertNode(node)
selectNode(node)
defer ->
triggerEvent(element, "compositionend", data: "ó")
triggerEvent(element, "input")
typeCharacters "n", ->
assert.locationRange(index: 0, offset: 3)
expectDocument("ión\n")

removeCharacters = (direction, callback) ->
selection = rangy.getSelection()
range = selection.getRangeAt(0)
Expand Down

0 comments on commit 89c9544

Please sign in to comment.