Skip to content

Commit

Permalink
Fix rendering identical blocks after re-parsing HTML
Browse files Browse the repository at this point in the history
Fixes #662. Regression introduced very subtly (by me) in #355.
  • Loading branch information
javan committed Aug 13, 2019
1 parent 6e08079 commit 692e2fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/trix/views/object_view.coffee
Expand Up @@ -12,6 +12,7 @@ class Trix.ObjectView extends Trix.BasicObject

invalidate: ->
@nodes = null
@childViews = []
@parentView?.invalidate()

invalidateViewForObject: (object) ->
Expand All @@ -36,8 +37,7 @@ class Trix.ObjectView extends Trix.BasicObject
recordChildView: (view) ->
view.parentView = this
view.rootView = @rootView
unless view in @childViews
@childViews.push(view)
@childViews.push(view)
view

getAllChildViews: ->
Expand Down
24 changes: 24 additions & 0 deletions test/src/system/html_reparsing_test.coffee
@@ -0,0 +1,24 @@
{assert, test, testGroup} = Trix.TestHelpers

testGroup "HTML Reparsing", template: "editor_empty", ->
test "mutation resulting in identical blocks", (expectDocument) ->
element = getEditorElement()
element.editor.loadHTML("<ul><li>a</li><li>b</li></ul>")
requestAnimationFrame ->
element.querySelector("li").textContent = "b"
requestAnimationFrame ->
assert.blockAttributes([0, 1], ["bulletList", "bullet"])
assert.blockAttributes([2, 3], ["bulletList", "bullet"])
assert.equal(element.value, "<ul><li>b</li><li>b</li></ul>")
expectDocument("b\nb\n")

test "mutation resulting in identical pieces", (expectDocument) ->
element = getEditorElement()
element.editor.loadHTML("<div><strong>a</strong> <strong>b</strong></div>")
requestAnimationFrame ->
element.querySelector("strong").textContent = "b"
requestAnimationFrame ->
assert.textAttributes([0, 1], bold: true)
assert.textAttributes([2, 3], bold: true)
assert.equal(element.value, "<div><strong>b</strong> <strong>b</strong></div>")
expectDocument("b b\n")

0 comments on commit 692e2fd

Please sign in to comment.