Skip to content

Commit

Permalink
add code tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Aug 29, 2016
1 parent 2f25680 commit cf83c49
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions blots/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/formats/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ describe('Code', function() {
expect(editor.scroll.domNode).toEqualHTML('<p>0123</p>');
});

it('delete merge before', function() {
let editor = this.initialize(Editor, { html: '<h1>0123</h1><pre>4567\n</pre>' });
editor.deleteText(4, 1);
expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { header: 1 }));
expect(editor.scroll.domNode).toEqualHTML('<h1>01234567\n</h1>');
});

it('delete merge after', function() {
let editor = this.initialize(Editor, { html: '<pre>0123\n</pre><h1>4567</h1>' });
editor.deleteText(4, 1);
expect(editor.getDelta()).toEqual(new Delta().insert('01234567').insert('\n', { 'code-block': true }));
expect(editor.scroll.domNode).toEqualHTML('<pre>01234567\n</pre>');
});

it('replace', function() {
let editor = this.initialize(Editor, { html: '<pre>0123\n</pre>' });
editor.formatText(4, 1, { 'header': 1 });
Expand Down

0 comments on commit cf83c49

Please sign in to comment.