Skip to content

Commit

Permalink
Upgrade to rich-text 2.0
Browse files Browse the repository at this point in the history
rich-text delta compose and transform no longer self-modifying.
Fixes #296
  • Loading branch information
jhchen committed Jun 15, 2015
1 parent fe3cc39 commit 34d9a9b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"lodash": "~3.9.1",
"lodash-cli": "~3.9.3",
"protractor": "~1.8.0",
"rich-text": "~1.1.0",
"rich-text": "~2.0.0",
"stylify": "~1.0.0",
"stylus": "~0.51.1",
"through": "~2.3.7",
Expand Down
2 changes: 1 addition & 1 deletion src/core/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Editor
return clearInterval(@timer) unless @root.parentNode?
delta = this._update()
if delta
@delta.compose(delta)
@delta = @delta.compose(delta)
@length = @delta.length()
@quill.emit(@quill.constructor.events.TEXT_CHANGE, delta, source)
source = Editor.sources.SILENT if delta
Expand Down
2 changes: 1 addition & 1 deletion src/modules/paste-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PasteManager
lengthAdded = Math.max(0, delta.length() - 1)
if lengthAdded > 0
# Need to remove trailing newline so paste is inline, losing format is expected and observed in Word
delta.compose(new Delta().retain(lengthAdded).delete(1))
delta = delta.compose(new Delta().retain(lengthAdded).delete(1))
delta.ops.unshift({ retain: range.start }) if range.start > 0
delta.delete(range.end - range.start)
@quill.updateContents(delta, 'user')
Expand Down
13 changes: 13 additions & 0 deletions test/unit/core/quill.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ describe('Quill', ->
bold.insertBefore(document.createTextNode('a'), bold.lastChild)
@quill.editor.checkUpdate()
)

it('immutability', (done) ->
@quill.setHTML('<div>123</div>')
expected = new Quill.Delta().insert('0')
@quill.once('text-change', (delta) =>
expect(delta).toEqualDelta(expected)
delta.compose(new Quill.Delta().insert('^'))
).once('text-change', (delta) =>
expect(delta).toEqualDelta(expected)
done()
)
@quill.insertText(0, '0')
)
)

describe('_buildParams()', ->
Expand Down

0 comments on commit 34d9a9b

Please sign in to comment.