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

when editor element is blurred but has selection, still possible to insert text #285

Closed
bantic opened this issue Jan 7, 2016 · 0 comments · Fixed by #291
Closed

when editor element is blurred but has selection, still possible to insert text #285

bantic opened this issue Jan 7, 2016 · 0 comments · Fixed by #291
Assignees
Milestone

Comments

@bantic
Copy link
Collaborator

bantic commented Jan 7, 2016

When the document.activeElement is an element outside the editor's element but window.getSelection() is within the editor's element, subsequent keystrokes will refocus onto the editor element and insert text, but they will not fire event handlers that were registered on the element. This causes issues related to inserting text in places it shouldn't go, such as around a card.

To reproduce in the demo:

  • insert an image card
  • position cursor at end of the card
  • click one of the section-changing buttons (e.g. "headline")
  • type text
  • the element's keydown handler will not get triggered (because the document's activeElement is the button that was clicked), but since the selection is still in the (contenteditable) editor element, the text will be inserted:

bug

@bantic bantic self-assigned this Jan 7, 2016
@bantic bantic added this to the 0.8 milestone Jan 11, 2016
@bantic bantic assigned bantic and unassigned bantic Jan 11, 2016
bantic added a commit that referenced this issue Jan 11, 2016
This helps prevent a situation where the editor element has a selection
but it is not the active element. Typing while another element (like a
button) is focused (active) but the editor element has the selection is
problematic: The browser refocuses on the editor element and starts
inserting text, but it handles the input before it has focused, which
means the key* handlers do not fire.

Also renamed Position#emptyPosition and Range#emptyRange ->
blankPosition, blankRange. Adds `isBlank` property to Position and
Range.

Defensively avoid attempting to render a cursor when the range is blank.

Fixes #285
bantic added a commit that referenced this issue Jan 11, 2016
This helps prevent a situation where the editor element has a selection
but it is not the active element. Typing while another element (like a
button) is focused (active) but the editor element has the selection is
problematic: The browser refocuses on the editor element and starts
inserting text, but it handles the input before it has focused, which
means the key* handlers do not fire.

Also renamed Position#emptyPosition and Range#emptyRange ->
blankPosition, blankRange. Adds `isBlank` property to Position and
Range.

Defensively avoid attempting to render a cursor when the range is blank.

Fixes #285
bantic added a commit that referenced this issue Jan 11, 2016
This helps prevent a situation where the editor element has a selection
but it is not the active element. Typing while another element (like a
button) is focused (active) but the editor element has the selection is
problematic: The browser refocuses on the editor element and starts
inserting text, but it handles the input before it has focused, which
means the key* handlers do not fire.

Also renamed Position#emptyPosition and Range#emptyRange ->
blankPosition, blankRange. Adds `isBlank` property to Position and
Range.

Defensively avoid attempting to render a cursor when the range is blank.

When cursor contains non-markerable, toggleMarkup is no-op

Fixes #285
Fixes #287
mixonic pushed a commit to mixonic/content-kit-editor that referenced this issue Jan 22, 2016
This helps prevent a situation where the editor element has a selection
but it is not the active element. Typing while another element (like a
button) is focused (active) but the editor element has the selection is
problematic: The browser refocuses on the editor element and starts
inserting text, but it handles the input before it has focused, which
means the key* handlers do not fire.

Also renamed Position#emptyPosition and Range#emptyRange ->
blankPosition, blankRange. Adds `isBlank` property to Position and
Range.

Defensively avoid attempting to render a cursor when the range is blank.

When cursor contains non-markerable, toggleMarkup is no-op

Fixes bustle#285
Fixes bustle#287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant