From cf83c4921665f57956bb3cf4bd2bad9cb5b19803 Mon Sep 17 00:00:00 2001 From: Jason Chen Date: Sun, 28 Aug 2016 20:40:30 -0700 Subject: [PATCH] add code tests and fixes --- blots/scroll.js | 9 +++++++-- test/unit/formats/code.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/blots/scroll.js b/blots/scroll.js index 5df09f627f..870e1a9572 100644 --- a/blots/scroll.js +++ b/blots/scroll.js @@ -2,6 +2,7 @@ import Parchment from 'parchment'; import Emitter from '../core/emitter'; import Block, { BlockEmbed } from './block'; import Container from './container'; +import CodeBlock from '../formats/code'; function isLine(blot) { @@ -28,15 +29,19 @@ class Scroll extends Parchment.Scroll { super.deleteAt(index, length); if (last != null && first !== last && offset > 0 && !(first instanceof BlockEmbed) && !(last instanceof BlockEmbed)) { + if (last instanceof CodeBlock) { + last.deleteAt(last.length() - 1, 1); + } last.moveChildren(first); last.remove(); - this.optimize(); } + this.optimize(); } formatAt(index, length, format, value) { if (this.whitelist != null && !this.whitelist[format]) return; super.formatAt(index, length, format, value); + this.optimize(); } insertAt(index, value, def) { @@ -53,10 +58,10 @@ class Scroll extends Parchment.Scroll { let embed = Parchment.create(value, def); this.appendChild(embed); } - this.optimize(); } else { super.insertAt(index, value, def); } + this.optimize(); } insertBefore(blot, ref) { diff --git a/test/unit/formats/code.js b/test/unit/formats/code.js index 4705d47811..794ad50f71 100644 --- a/test/unit/formats/code.js +++ b/test/unit/formats/code.js @@ -117,6 +117,20 @@ describe('Code', function() { expect(editor.scroll.domNode).toEqualHTML('

0123

'); }); + 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

'); + }); + + 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
'); + }); + it('replace', function() { let editor = this.initialize(Editor, { html: '
0123\n
' }); editor.formatText(4, 1, { 'header': 1 });