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

Fix sticky cursor resulting in reverse typing if the editable is not the activeElement in the document. #16066

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ckeditor5-engine/src/view/observer/inputobserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export default class InputObserver extends DomEventObserver<'beforeinput'> {
// @if CK_DEBUG_TYPING // );
// @if CK_DEBUG_TYPING // }

// Handles reverse typing cases where the current document is not seen as the
// DOM `activeElement`, but the editable is somehow still in focus.
// In other words, the editable visually appears to be in focus, but it is not.
if ( !this.view.document.isFocused ) {
// The current target is assumed to be the editable
domEvent.currentTarget?.dispatchEvent( new FocusEvent( 'focus' ) );
}
const domTargetRanges = domEvent.getTargetRanges();
const view = this.view;
const viewDocument = view.document;
Expand Down
28 changes: 28 additions & 0 deletions packages/ckeditor5-engine/tests/view/observer/inputobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ describe( 'InputObserver', () => {
sinon.assert.calledOnce( beforeInputSpy );
} );

it( 'should not dispatch focus event if the document has focus', () => {
viewDocument.isFocused = true;

const mockDispatchEvent = sinon.spy();
fireMockNativeBeforeInput( {
inputType: 'foo',
currentTarget: {
dispatchEvent: mockDispatchEvent
}
} );

expect( mockDispatchEvent.callCount ).to.equal( 0 );
} );

it( 'should dispatch focus event if the document does not have focus', () => {
viewDocument.isFocused = false;

const mockDispatchEvent = sinon.spy();
fireMockNativeBeforeInput( {
inputType: 'foo',
currentTarget: {
dispatchEvent: mockDispatchEvent
}
} );

expect( mockDispatchEvent.callCount ).to.equal( 1 );
} );

describe( 'event data', () => {
it( 'should contain #eventType', () => {
fireMockNativeBeforeInput( {
Expand Down