Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into t/92
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Feb 20, 2018
2 parents 28e70a2 + 9aabd1b commit 20b1d84
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 96 deletions.
9 changes: 5 additions & 4 deletions src/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ export default class Delete extends Plugin {

init() {
const editor = this.editor;
const editingView = editor.editing.view;
const view = editor.editing.view;
const viewDocument = view.document;

editingView.addObserver( DeleteObserver );
view.addObserver( DeleteObserver );

editor.commands.add( 'forwardDelete', new DeleteCommand( editor, 'forward' ) );
editor.commands.add( 'delete', new DeleteCommand( editor, 'backward' ) );

this.listenTo( editingView, 'delete', ( evt, data ) => {
this.listenTo( viewDocument, 'delete', ( evt, data ) => {
editor.execute( data.direction == 'forward' ? 'forwardDelete' : 'delete', { unit: data.unit, sequence: data.sequence } );
data.preventDefault();
editingView.scrollToTheSelection();
view.scrollToTheSelection();
} );
}
}
5 changes: 3 additions & 2 deletions src/deleteobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import env from '@ckeditor/ckeditor5-utils/src/env';
* @extends module:engine/view/observer/observer~Observer
*/
export default class DeleteObserver extends Observer {
constructor( document ) {
super( document );
constructor( view ) {
super( view );

const document = view.document;
let sequence = 0;

document.on( 'keyup', ( evt, data ) => {
Expand Down
4 changes: 2 additions & 2 deletions src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export default class Input extends Plugin {

editor.commands.add( 'input', inputCommand );

this.listenTo( editingView, 'keydown', ( evt, data ) => {
this.listenTo( editingView.document, 'keydown', ( evt, data ) => {
this._handleKeydown( data, inputCommand );
}, { priority: 'lowest' } );

this.listenTo( editingView, 'mutations', ( evt, mutations, viewSelection ) => {
this.listenTo( editingView.document, 'mutations', ( evt, mutations, viewSelection ) => {
this._handleMutations( mutations, viewSelection );
} );
}
Expand Down
16 changes: 8 additions & 8 deletions tests/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import Delete from '../src/delete';
import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';

describe( 'Delete feature', () => {
let editor, editingView;
let editor, viewDocument;

beforeEach( () => {
return VirtualTestEditor
.create( { plugins: [ Delete ] } )
.then( newEditor => {
editor = newEditor;
editingView = editor.editing.view;
viewDocument = editor.editing.view.document;
} );
} );

Expand All @@ -28,12 +28,12 @@ describe( 'Delete feature', () => {
expect( editor.commands.get( 'forwardDelete' ) ).to.have.property( 'direction', 'forward' );
} );

it( 'listens to the editing view delete event', () => {
it( 'listens to the editing view document delete event', () => {
const spy = editor.execute = sinon.spy();
const view = editor.editing.view;
const viewDocument = editor.editing.view.document;
const domEvt = getDomEvent();

view.fire( 'delete', new DomEventData( editingView, domEvt, {
viewDocument.fire( 'delete', new DomEventData( viewDocument, domEvt, {
direction: 'forward',
unit: 'character',
sequence: 1
Expand All @@ -44,7 +44,7 @@ describe( 'Delete feature', () => {

expect( domEvt.preventDefault.calledOnce ).to.be.true;

view.fire( 'delete', new DomEventData( editingView, getDomEvent(), {
viewDocument.fire( 'delete', new DomEventData( viewDocument, getDomEvent(), {
direction: 'backward',
unit: 'character',
sequence: 5
Expand All @@ -55,10 +55,10 @@ describe( 'Delete feature', () => {
} );

it( 'scrolls the editing document to the selection after executing the command', () => {
const scrollSpy = sinon.stub( editingView, 'scrollToTheSelection' );
const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection' );
const executeSpy = editor.execute = sinon.spy();

editingView.fire( 'delete', new DomEventData( editingView, getDomEvent(), {
viewDocument.fire( 'delete', new DomEventData( viewDocument, getDomEvent(), {
direction: 'backward',
unit: 'character'
} ) );
Expand Down
15 changes: 10 additions & 5 deletions tests/deleteobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* globals document */

import DeleteObserver from '../src/deleteobserver';
import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document';
import View from '@ckeditor/ckeditor5-engine/src/view/view';
import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
import createViewRoot from '@ckeditor/ckeditor5-engine/tests/view/_utils/createroot';
import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
Expand All @@ -17,18 +17,23 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
testUtils.createSinonSandbox();

describe( 'DeleteObserver', () => {
let viewDocument;
let view, viewDocument;

beforeEach( () => {
viewDocument = new ViewDocument();
viewDocument.addObserver( DeleteObserver );
view = new View();
viewDocument = view.document;
view.addObserver( DeleteObserver );
} );

afterEach( () => {
view.destroy();
} );

// See ckeditor/ckeditor5-enter#10.
it( 'can be initialized', () => {
expect( () => {
createViewRoot( viewDocument );
viewDocument.attachDomRoot( document.createElement( 'div' ) );
view.attachDomRoot( document.createElement( 'div' ) );
} ).to.not.throw();
} );

Expand Down
Loading

0 comments on commit 20b1d84

Please sign in to comment.