From bab390c690a8a5cf4ef4b00450d92ebbb21020ab Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Tue, 1 Aug 2017 15:29:38 +0200 Subject: [PATCH 1/4] Scroll the view document to the selection on enter if the BlockQuote feature handles the keystroke. --- src/blockquote.js | 1 + tests/integration.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/blockquote.js b/src/blockquote.js index da8e8d1..e0b85d5 100644 --- a/src/blockquote.js +++ b/src/blockquote.js @@ -84,6 +84,7 @@ export default class BlockQuote extends Plugin { if ( doc.selection.isCollapsed && positionParent.isEmpty && command.value ) { this.editor.execute( 'blockQuote' ); + this.editor.editing.view.scrollToTheSelection(); data.preventDefault(); evt.stop(); diff --git a/tests/integration.js b/tests/integration.js index 1b9069a..f668e4e 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -190,6 +190,23 @@ describe( 'BlockQuote', () => { 'x' ); } ); + + it( 'scrolls the view document to the selection after the command is executed', () => { + const data = fakeEventData(); + const execSpy = sinon.spy( editor, 'execute' ); + const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} ); + + setModelData( doc, + 'x' + + '
a[]
' + + 'x' + ); + + editor.editing.view.fire( 'enter', data ); + + sinon.assert.calledOnce( scrollSpy ); + sinon.assert.callOrder( execSpy, scrollSpy ); + } ); } ); describe( 'backspace key support', () => { From 8c9ec706ae0106e71e73a645889cc4081d8fca51 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Wed, 9 Aug 2017 15:53:21 +0200 Subject: [PATCH 2/4] SAlways scroll the viewport to the selection when the BlockQuoteCommand gets executed. --- src/blockquote.js | 1 - src/blockquotecommand.js | 5 ++++- tests/blockquotecommand.js | 42 ++++++++++++++++++++++++++++++++++++++ tests/integration.js | 17 --------------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/blockquote.js b/src/blockquote.js index e0b85d5..da8e8d1 100644 --- a/src/blockquote.js +++ b/src/blockquote.js @@ -84,7 +84,6 @@ export default class BlockQuote extends Plugin { if ( doc.selection.isCollapsed && positionParent.isEmpty && command.value ) { this.editor.execute( 'blockQuote' ); - this.editor.editing.view.scrollToTheSelection(); data.preventDefault(); evt.stop(); diff --git a/src/blockquotecommand.js b/src/blockquotecommand.js index af6f3c4..b1e66a3 100644 --- a/src/blockquotecommand.js +++ b/src/blockquotecommand.js @@ -47,7 +47,8 @@ export default class BlockQuoteCommand extends Command { * A new batch will be created if this option is not set. */ execute( options = {} ) { - const doc = this.editor.document; + const editor = this.editor; + const doc = editor.document; const schema = doc.schema; const batch = options.batch || doc.batch(); const blocks = Array.from( doc.selection.getSelectedBlocks() ); @@ -64,6 +65,8 @@ export default class BlockQuoteCommand extends Command { this._applyQuote( batch, blocksToQuote ); } + + editor.editing.view.scrollToTheSelection(); } ); } diff --git a/tests/blockquotecommand.js b/tests/blockquotecommand.js index dee015f..4c5c6e1 100644 --- a/tests/blockquotecommand.js +++ b/tests/blockquotecommand.js @@ -141,6 +141,14 @@ describe( 'BlockQuoteCommand', () => { } ); describe( 'execute()', () => { + let scrollToTheSelectionStub; + + beforeEach( () => { + // VirtualTestEditor has no DOM, so this method must be stubbed for all tests. + // Otherwise it will throw as it accesses the DOM to do its job. + scrollToTheSelectionStub = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} ); + } ); + describe( 'applying quote', () => { it( 'should wrap a single block', () => { setModelData( @@ -431,6 +439,23 @@ describe( 'BlockQuoteCommand', () => { '' ); } ); + + it( 'should scroll the viewport to the selection', () => { + setModelData( doc, '[xx]' ); + + editor.execute( 'blockQuote' ); + sinon.assert.notCalled( scrollToTheSelectionStub ); + + setModelData( + doc, + 'abc' + + 'x[]x' + + 'def' + ); + + editor.execute( 'blockQuote' ); + sinon.assert.calledOnce( scrollToTheSelectionStub ); + } ); } ); describe( 'removing quote', () => { @@ -591,6 +616,23 @@ describe( 'BlockQuoteCommand', () => { '

ghi

' ); } ); + + it( 'should scroll the viewport to the selections', () => { + setModelData( doc, '[xx]' ); + + editor.execute( 'blockQuote' ); + sinon.assert.notCalled( scrollToTheSelectionStub ); + + setModelData( + doc, + 'abc' + + '
x[]x
' + + 'def' + ); + + editor.execute( 'blockQuote' ); + sinon.assert.calledOnce( scrollToTheSelectionStub ); + } ); } ); } ); } ); diff --git a/tests/integration.js b/tests/integration.js index 4a69900..0e959c7 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -191,23 +191,6 @@ describe( 'BlockQuote', () => { 'x' ); } ); - - it( 'scrolls the view document to the selection after the command is executed', () => { - const data = fakeEventData(); - const execSpy = sinon.spy( editor, 'execute' ); - const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} ); - - setModelData( doc, - 'x' + - '
a[]
' + - 'x' - ); - - editor.editing.view.fire( 'enter', data ); - - sinon.assert.calledOnce( scrollSpy ); - sinon.assert.callOrder( execSpy, scrollSpy ); - } ); } ); describe( 'backspace key support', () => { From 9a3cf992e8c479ae9eb3e58f5cc4a20df2cae9d7 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Wed, 9 Aug 2017 16:10:08 +0200 Subject: [PATCH 3/4] Revert "SAlways scroll the viewport to the selection when the BlockQuoteCommand gets executed." This reverts commit 8c9ec706ae0106e71e73a645889cc4081d8fca51. --- src/blockquote.js | 1 + src/blockquotecommand.js | 5 +---- tests/blockquotecommand.js | 42 -------------------------------------- tests/integration.js | 17 +++++++++++++++ 4 files changed, 19 insertions(+), 46 deletions(-) diff --git a/src/blockquote.js b/src/blockquote.js index da8e8d1..e0b85d5 100644 --- a/src/blockquote.js +++ b/src/blockquote.js @@ -84,6 +84,7 @@ export default class BlockQuote extends Plugin { if ( doc.selection.isCollapsed && positionParent.isEmpty && command.value ) { this.editor.execute( 'blockQuote' ); + this.editor.editing.view.scrollToTheSelection(); data.preventDefault(); evt.stop(); diff --git a/src/blockquotecommand.js b/src/blockquotecommand.js index b1e66a3..af6f3c4 100644 --- a/src/blockquotecommand.js +++ b/src/blockquotecommand.js @@ -47,8 +47,7 @@ export default class BlockQuoteCommand extends Command { * A new batch will be created if this option is not set. */ execute( options = {} ) { - const editor = this.editor; - const doc = editor.document; + const doc = this.editor.document; const schema = doc.schema; const batch = options.batch || doc.batch(); const blocks = Array.from( doc.selection.getSelectedBlocks() ); @@ -65,8 +64,6 @@ export default class BlockQuoteCommand extends Command { this._applyQuote( batch, blocksToQuote ); } - - editor.editing.view.scrollToTheSelection(); } ); } diff --git a/tests/blockquotecommand.js b/tests/blockquotecommand.js index 4c5c6e1..dee015f 100644 --- a/tests/blockquotecommand.js +++ b/tests/blockquotecommand.js @@ -141,14 +141,6 @@ describe( 'BlockQuoteCommand', () => { } ); describe( 'execute()', () => { - let scrollToTheSelectionStub; - - beforeEach( () => { - // VirtualTestEditor has no DOM, so this method must be stubbed for all tests. - // Otherwise it will throw as it accesses the DOM to do its job. - scrollToTheSelectionStub = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} ); - } ); - describe( 'applying quote', () => { it( 'should wrap a single block', () => { setModelData( @@ -439,23 +431,6 @@ describe( 'BlockQuoteCommand', () => { '' ); } ); - - it( 'should scroll the viewport to the selection', () => { - setModelData( doc, '[xx]' ); - - editor.execute( 'blockQuote' ); - sinon.assert.notCalled( scrollToTheSelectionStub ); - - setModelData( - doc, - 'abc' + - 'x[]x' + - 'def' - ); - - editor.execute( 'blockQuote' ); - sinon.assert.calledOnce( scrollToTheSelectionStub ); - } ); } ); describe( 'removing quote', () => { @@ -616,23 +591,6 @@ describe( 'BlockQuoteCommand', () => { '

ghi

' ); } ); - - it( 'should scroll the viewport to the selections', () => { - setModelData( doc, '[xx]' ); - - editor.execute( 'blockQuote' ); - sinon.assert.notCalled( scrollToTheSelectionStub ); - - setModelData( - doc, - 'abc' + - '
x[]x
' + - 'def' - ); - - editor.execute( 'blockQuote' ); - sinon.assert.calledOnce( scrollToTheSelectionStub ); - } ); } ); } ); } ); diff --git a/tests/integration.js b/tests/integration.js index 0e959c7..4a69900 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -191,6 +191,23 @@ describe( 'BlockQuote', () => { 'x' ); } ); + + it( 'scrolls the view document to the selection after the command is executed', () => { + const data = fakeEventData(); + const execSpy = sinon.spy( editor, 'execute' ); + const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} ); + + setModelData( doc, + 'x' + + '
a[]
' + + 'x' + ); + + editor.editing.view.fire( 'enter', data ); + + sinon.assert.calledOnce( scrollSpy ); + sinon.assert.callOrder( execSpy, scrollSpy ); + } ); } ); describe( 'backspace key support', () => { From 4e1f5f6c11dfc89f27afc3331c54a34a42eaae80 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Thu, 10 Aug 2017 10:58:23 +0200 Subject: [PATCH 4/4] Tests: Updated stubs to the latest Sinon API. --- tests/integration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.js b/tests/integration.js index 4a69900..83f89d7 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -195,7 +195,7 @@ describe( 'BlockQuote', () => { it( 'scrolls the view document to the selection after the command is executed', () => { const data = fakeEventData(); const execSpy = sinon.spy( editor, 'execute' ); - const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection', () => {} ); + const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection' ); setModelData( doc, 'x' +