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
merged 63 commits into from Feb 21, 2019

Conversation

Projects
None yet
1 participant
@javan
Copy link
Member

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

javan added some commits Nov 15, 2018

Cancel formatting events
The default behavior is rarely what we want: <b> instead of <strong>, <i> instead of <em>, etc.
Avoid canceling "beforeinput" events
We don't technically need to cancel them and support is varied between Level 1 and 2 so skip it altogether for clarity.
Only use target DOM ranges with a string length > 1 for deletions
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

javan added some commits Jan 4, 2019

Merge branch 'master' into level-2-input
# Conflicts:
#	.blade.yml
Handle dragstart, dragover, and drop events when dragging attachments
Fixes reordering images in galleries, and generally ensures that attachments remain managed.
Reset the selection after each input
Fixes handling multiple deletions within a single animation frame.
Ensure dataTransfer.types doesn't include "Files" when dragging exist…
…ing attachments

Looking at you, Safari. Setting *any* dataTransfer values fixes it.
Fix pasting files in Safari
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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@javan javan deleted the level-2-input branch Feb 21, 2019

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
You can’t perform that action at this time.