-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17481 from ckeditor/ck/17171
Fix (typing): Fix not working two-step caret movement on iOS devices. Closes #17171
- Loading branch information
Showing
5 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/ckeditor5-engine/src/view/observer/touchobserver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options | ||
*/ | ||
|
||
/** | ||
* @module engine/view/observer/touchobserver | ||
*/ | ||
|
||
import DomEventObserver from './domeventobserver.js'; | ||
import type DomEventData from './domeventdata.js'; | ||
|
||
/** | ||
* Touch events observer. | ||
* | ||
* Note that this observer is not available by default. To make it available it needs to be added to | ||
* {@link module:engine/view/view~View} by {@link module:engine/view/view~View#addObserver} method. | ||
*/ | ||
export default class TouchObserver extends DomEventObserver<'touchstart' | 'touchend' | 'touchmove'> { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public readonly domEventType = [ 'touchstart', 'touchend', 'touchmove' ] as const; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public onDomEvent( domEvent: TouchEvent ): void { | ||
this.fire( domEvent.type, domEvent ); | ||
} | ||
} | ||
|
||
/** | ||
* Fired when a touch is started on one of the editing roots of the editor. | ||
* | ||
* Introduced by {@link module:engine/view/observer/touchobserver~TouchObserver}. | ||
* | ||
* Note that this event is not available by default. To make it available, {@link module:engine/view/observer/touchobserver~TouchObserver} | ||
* needs to be added to {@link module:engine/view/view~View} by the {@link module:engine/view/view~View#addObserver} method. | ||
* | ||
* @see module:engine/view/observer/touchobserver~TouchObserver | ||
* @eventName module:engine/view/document~Document#touchstart | ||
* @param data The event data. | ||
*/ | ||
export type ViewDocumentTouchStartEvent = { | ||
name: 'touchstart'; | ||
args: [ data: DomEventData<TouchEvent> ]; | ||
}; | ||
|
||
/** | ||
* Fired when a touch ends on one of the editing roots of the editor. | ||
* | ||
* Introduced by {@link module:engine/view/observer/touchobserver~TouchObserver}. | ||
* | ||
* Note that this event is not available by default. To make it available, {@link module:engine/view/observer/touchobserver~TouchObserver} | ||
* needs to be added to {@link module:engine/view/view~View} by the {@link module:engine/view/view~View#addObserver} method. | ||
* | ||
* @see module:engine/view/observer/touchobserver~TouchObserver | ||
* @eventName module:engine/view/document~Document#touchend | ||
* @param data The event data. | ||
*/ | ||
export type ViewDocumentTouchEndEvent = { | ||
name: 'touchend'; | ||
args: [ data: DomEventData<TouchEvent> ]; | ||
}; | ||
|
||
/** | ||
* Fired when a touch is moved on one of the editing roots of the editor. | ||
* | ||
* Introduced by {@link module:engine/view/observer/touchobserver~TouchObserver}. | ||
* | ||
* Note that this event is not available by default. To make it available, {@link module:engine/view/observer/touchobserver~TouchObserver} | ||
* needs to be added to {@link module:engine/view/view~View} by the {@link module:engine/view/view~View#addObserver} method. | ||
* | ||
* @see module:engine/view/observer/touchobserver~TouchObserver | ||
* @eventName module:engine/view/document~Document#touchmove | ||
* @param data The event data. | ||
*/ | ||
export type ViewDocumentTouchMoveEvent = { | ||
name: 'touchmove'; | ||
args: [ data: DomEventData<TouchEvent> ]; | ||
}; |
69 changes: 69 additions & 0 deletions
69
packages/ckeditor5-engine/tests/view/observer/touchobserver.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options | ||
*/ | ||
|
||
/* globals document */ | ||
|
||
import TouchObserver from '../../../src/view/observer/touchobserver.js'; | ||
import View from '../../../src/view/view.js'; | ||
import { StylesProcessor } from '../../../src/view/stylesmap.js'; | ||
|
||
describe( 'TouchObserver', () => { | ||
let view, viewDocument, observer; | ||
|
||
beforeEach( () => { | ||
view = new View( new StylesProcessor() ); | ||
viewDocument = view.document; | ||
observer = view.addObserver( TouchObserver ); | ||
} ); | ||
|
||
afterEach( () => { | ||
view.destroy(); | ||
} ); | ||
|
||
it( 'should define domEventType', () => { | ||
expect( observer.domEventType ).to.deep.equal( [ 'touchstart', 'touchend', 'touchmove' ] ); | ||
} ); | ||
|
||
describe( 'onDomEvent', () => { | ||
it( 'should fire touchstart with the right event data', () => { | ||
const spy = sinon.spy(); | ||
|
||
viewDocument.on( 'touchstart', spy ); | ||
|
||
observer.onDomEvent( { type: 'touchstart', target: document.body } ); | ||
|
||
expect( spy.calledOnce ).to.be.true; | ||
|
||
const data = spy.args[ 0 ][ 1 ]; | ||
expect( data.domTarget ).to.equal( document.body ); | ||
} ); | ||
|
||
it( 'should fire touchend with the right event data', () => { | ||
const spy = sinon.spy(); | ||
|
||
viewDocument.on( 'touchend', spy ); | ||
|
||
observer.onDomEvent( { type: 'touchend', target: document.body } ); | ||
|
||
expect( spy.calledOnce ).to.be.true; | ||
|
||
const data = spy.args[ 0 ][ 1 ]; | ||
expect( data.domTarget ).to.equal( document.body ); | ||
} ); | ||
|
||
it( 'should fire touchmove with the right event data', () => { | ||
const spy = sinon.spy(); | ||
|
||
viewDocument.on( 'touchmove', spy ); | ||
|
||
observer.onDomEvent( { type: 'touchmove', target: document.body } ); | ||
|
||
expect( spy.calledOnce ).to.be.true; | ||
|
||
const data = spy.args[ 0 ][ 1 ]; | ||
expect( data.domTarget ).to.equal( document.body ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters