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

Input Events Level {1,2} #580

merged 63 commits into from
Feb 21, 2019

Input Events Level {1,2} #580

merged 63 commits into from
Feb 21, 2019


Copy link

@javan javan commented Jan 4, 2019

This PR improves the way Trix records input—particularly on mobile—by adding support for Level 2 InputEvents, which are currently implemented in Safari and Chrome, and in their companion webview implementations on iOS and Android. In all other browsers, Trix will continue to work exactly as it does today. Here's how:

First, Trix tests for InputEvent support:

supportsInputEvents: do ->
typeof InputEvent isnt "undefined" and
"inputType" of InputEvent.prototype and
"data" of InputEvent.prototype

Then, when a <trix-editor> initializes, its editor controller installs one of two input controllers:

@inputController = new Trix["Level#{Trix.config.input.getLevel()}InputController"](@editorElement)
@inputController.delegate = this
@inputController.responder = @composition

  1. Trix.Level2InputController if input events are supported
  2. Trix.Level0InputController, which is equivalent to the current Trix.InputController, if input events are not supported

Fixes #575
Fixes #574
Fixes #520
Fixes #494
Fixes #396
Fixes #315
Fixes #178
Closes #564

The default behavior is rarely what we want: <b> instead of <strong>, <i> instead of <em>, etc.
We don't technically need to cancel them and support is varied between Level 1 and 2 so skip it altogether for clarity.
To support Composition's special cases for removing formatting, selecting attachments, etc. when the selection is collapsed.
@javan javan added the WIP label Jan 4, 2019
# Conflicts:
#	.blade.yml
Fixes reordering images in galleries, and generally ensures that attachments remain managed.
Fixes handling multiple deletions within a single animation frame.
…ing attachments

Looking at you, Safari. Setting *any* dataTransfer values fixes it.
Safari's beforeinput.insertFromPaste event doesn't include files in its dataTransfer, and, annoyingly, does include text/html with an unusable <img src="blob:http://…">. So, handle and cancel the paste event just for file pastes.
@javan javan removed the WIP label Feb 21, 2019
@javan javan merged commit 7ce4f4a into master Feb 21, 2019
@javan javan deleted the level-2-input branch February 21, 2019 17:39
thanks2music added a commit to thanks2music/trix that referenced this pull request Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

1 participant