From be24c62a6234818548658fcb5e1935a0c07b4eb7 Mon Sep 17 00:00:00 2001 From: Jason Chen Date: Sun, 28 Aug 2016 21:51:50 -0700 Subject: [PATCH] fix line merge behavior If we have

0

2

and delete to newline between the two headers, should the resulting line be h1 or h2? What if they were bullets vs lists, or other line formats? Testing on word processors seem to depend on the format itself, rather than always keeping the first line's format or the 2nd line's. This does not work well for a customizable and consistent editor because we do not know the formats ahead of time, so cannot order based on format. We must either always take the first line's format or the second line's. Prior to this commit the editor favored the first and the Delta format favored the second. We standardize to always favor the second. Fixes #889 --- blots/scroll.js | 4 ++-- test/unit/blots/block.js | 2 +- test/unit/core/editor.js | 6 ++++++ test/unit/formats/code.js | 8 ++++---- test/unit/formats/list.js | 4 ++-- test/unit/modules/clipboard.js | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/blots/scroll.js b/blots/scroll.js index 870e1a9572..acb8f78db5 100644 --- a/blots/scroll.js +++ b/blots/scroll.js @@ -32,8 +32,8 @@ class Scroll extends Parchment.Scroll { if (last instanceof CodeBlock) { last.deleteAt(last.length() - 1, 1); } - last.moveChildren(first); - last.remove(); + first.moveChildren(last, last.children.head); + first.remove(); } this.optimize(); } diff --git a/test/unit/blots/block.js b/test/unit/blots/block.js index 29827cdb37..4a10e0394a 100644 --- a/test/unit/blots/block.js +++ b/test/unit/blots/block.js @@ -49,7 +49,7 @@ describe('Block', function() { it('join lines', function() { let scroll = this.initialize(Scroll, '

Hello

World!

'); scroll.deleteAt(5, 1); - expect(scroll.domNode).toEqualHTML('

HelloWorld!

'); + expect(scroll.domNode).toEqualHTML('

HelloWorld!

'); }); it('join empty lines', function() { diff --git a/test/unit/core/editor.js b/test/unit/core/editor.js index 4a54603d31..ca506a587f 100644 --- a/test/unit/core/editor.js +++ b/test/unit/core/editor.js @@ -391,6 +391,12 @@ describe('Editor', function() { ); expect(this.container).toEqualHTML('

0123

56

89

'); }); + + it('code', function() { + let editor = this.initialize(Editor, { html: '

0

1\n23\n


' }); + editor.applyDelta(new Delta().delete(4).retain(1).delete(2)); + expect(editor.scroll.domNode.innerHTML).toEqual('

2

'); + }); }); describe('getFormat()', function() { diff --git a/test/unit/formats/code.js b/test/unit/formats/code.js index 794ad50f71..e17532a159 100644 --- a/test/unit/formats/code.js +++ b/test/unit/formats/code.js @@ -120,15 +120,15 @@ describe('Code', function() { it('delete merge before', function() { let editor = this.initialize(Editor, { html: '

0123

4567\n
' }); editor.deleteText(4, 1); - expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { header: 1 })); - expect(editor.scroll.domNode).toEqualHTML('

01234567\n

'); + expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { 'code-block': true })); + expect(editor.scroll.domNode).toEqualHTML('
01234567\n
'); }); it('delete merge after', function() { let editor = this.initialize(Editor, { html: '
0123\n

4567

' }); editor.deleteText(4, 1); - expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { 'code-block': true })); - expect(editor.scroll.domNode).toEqualHTML('
01234567\n
'); + expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { header: 1 })); + expect(editor.scroll.domNode).toEqualHTML('

01234567

'); }); it('replace', function() { diff --git a/test/unit/formats/list.js b/test/unit/formats/list.js index 964246304e..d304309d5a 100644 --- a/test/unit/formats/list.js +++ b/test/unit/formats/list.js @@ -189,13 +189,13 @@ describe('List', function() {

5678

` ); editor.deleteText(2, 5); - expect(this.container).toEqualHTML('
  1. 0178
'); + expect(this.container).toEqualHTML('

0178

'); }); it('delete partial', function() { let editor = this.initialize(Editor, '

0123

'); editor.deleteText(2, 5); - expect(this.container).toEqualHTML('

0178

'); + expect(this.container).toEqualHTML(''); }); it('nested list replacement', function() { diff --git a/test/unit/modules/clipboard.js b/test/unit/modules/clipboard.js index 24181f9843..1eaf0ad76a 100644 --- a/test/unit/modules/clipboard.js +++ b/test/unit/modules/clipboard.js @@ -23,7 +23,7 @@ describe('Clipboard', function() { this.quill.clipboard.container.innerHTML = '|'; this.quill.clipboard.onPaste(this.event); setTimeout(() => { - expect(this.quill.root).toEqualHTML('

01|78

'); + expect(this.quill.root).toEqualHTML('

01|78

'); expect(this.quill.getSelection()).toEqual(new Range(3)); done(); }, 2);