-
-
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 #9023 from ckeditor/i/8640
Feature (engine): Introduced bubbling of `view.Document` events, similar to how bubbling works in the DOM. Bubbling allows listening on a view event on a specific kind of an element, hence simplifying code that needs to handle a specific event for only that element (e.g. `enter` in `blockquote`s only). Read more in the documentation: **\[TODO\]**. Closes #8640. Feature (engine): Introduced `ArrowKeysObserver`. See #8640. Fix (utils): The `EmitterMixin#listenTo()` method is split into listener and emitter parts. The `ObservableMixin` decorated methods reverted to the original method while destroying an observable. Other (typing): The `TwoStepCaretMovement` feature is now using bubbling events. Closes #7437. BREAKING CHANGE: We introduced bubbling of `view.Document` events, similar to how bubbling works in the DOM. That allowed us to reprioritize many listeners that previously had to rely on `priority`. However, it means that existing listeners that use priorities may now be executed in a wrong moment. The listeners to such events should be reviewed in terms of when they should be executed (in what context/element/phase). You can find more information regarding bubbling in the documentation: **\[TODO\]**. See #8640. Internal (widget): The enter, delete and arrow key events handling moved to the usage of the bubbling observer. Internal (block-quote): The enter and delete events handling moved to the usage of the bubbling observer. Internal (code-block): The enter event handling moved to the usage of the bubbling observer. Internal (list): The enter and delete events handling moved to the usage of the bubbling observer. Internal (table): The arrow keys handling moved to the usage of the bubbling observer.
- Loading branch information
Showing
40 changed files
with
2,193 additions
and
189 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
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
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
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
58 changes: 58 additions & 0 deletions
58
packages/ckeditor5-engine/src/view/observer/arrowkeysobserver.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,58 @@ | ||
/** | ||
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module engine/view/observer/arrowkeysobserver | ||
*/ | ||
|
||
import Observer from './observer'; | ||
import BubblingEventInfo from './bubblingeventinfo'; | ||
|
||
import { isArrowKeyCode } from '@ckeditor/ckeditor5-utils'; | ||
|
||
/** | ||
* Arrow keys observer introduces the {@link module:engine/view/document~Document#event:arrowKey `Document#arrowKey`} event. | ||
* | ||
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default. | ||
* | ||
* @extends module:engine/view/observer/observer~Observer | ||
*/ | ||
export default class ArrowKeysObserver extends Observer { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
constructor( view ) { | ||
super( view ); | ||
|
||
this.document.on( 'keydown', ( event, data ) => { | ||
if ( this.isEnabled && isArrowKeyCode( data.keyCode ) ) { | ||
const eventInfo = new BubblingEventInfo( this.document, 'arrowKey', this.document.selection.getFirstRange() ); | ||
|
||
this.document.fire( eventInfo, data ); | ||
|
||
if ( eventInfo.stop.called ) { | ||
event.stop(); | ||
} | ||
} | ||
} ); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
observe() {} | ||
} | ||
|
||
/** | ||
* Event fired when the user presses an arrow keys. | ||
* | ||
* Introduced by {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver}. | ||
* | ||
* Note that because {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver} is attached by the | ||
* {@link module:engine/view/view~View} this event is available by default. | ||
* | ||
* @event module:engine/view/document~Document#event:arrowKey | ||
* @param {module:engine/view/observer/domeventdata~DomEventData} data | ||
*/ |
Oops, something went wrong.