From caaa8c9cbe86e028f72084999e9a45deefe71526 Mon Sep 17 00:00:00 2001 From: Igor Kurganov Date: Fri, 9 Dec 2016 17:37:14 -0800 Subject: [PATCH] editable node w/ focus is updated when data is changed. --- mithril.js | 2 +- test/mithril.render.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 7881b338..42c5963b 100644 --- a/mithril.js +++ b/mithril.js @@ -524,7 +524,7 @@ parentTag ) { var nodes = cached.nodes - if (!editable || editable !== $document.activeElement) { + if (!editable || editable !== $document.activeElement || data !== cached) { if (data.$trusted) { clear(nodes, cached) nodes = injectHTML(parentElement, index, data) diff --git a/test/mithril.render.js b/test/mithril.render.js index b7db5343..8aad560b 100644 --- a/test/mithril.render.js +++ b/test/mithril.render.js @@ -1589,5 +1589,25 @@ describe("m.render()", function () { expect(root.childNodes[0].innerHTML).to.equal(t1.valueOf()) }) + + it("caches children of editable on update", function () { + var root = document.createElement('div') + + // need this in order for focus & activeElement to work properly + document.body.appendChild(root) + + m.render(root, m('span', { + config: function(el) { el.focus() }, + contenteditable: true + }, 'a')) + + m.render(root, m('span', { + config: function(el) { el.focus() }, + contenteditable: true + }, 'b')) + + expect(root.childNodes[0].innerHTML).to.equal('b') + }) + }) })