From ec95de99083b0c220567e98d36defea7ae7bb7e8 Mon Sep 17 00:00:00 2001 From: Igor Kurganov Date: Mon, 29 Feb 2016 15:29:08 -0800 Subject: [PATCH 1/2] Cache the childrens of editable elements --- mithril.js | 1 + test/mithril.render.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/mithril.js b/mithril.js index 20a59720..f4790019 100644 --- a/mithril.js +++ b/mithril.js @@ -533,6 +533,7 @@ } else if (editable) { // contenteditable nodes use `innerHTML` instead of `nodeValue`. editable.innerHTML = data + nodes = [].slice.call(editable.childNodes) } else { // was a trusted string if (nodes[0].nodeType === 1 || nodes.length > 1 || diff --git a/test/mithril.render.js b/test/mithril.render.js index c2c56b5a..f851de58 100644 --- a/test/mithril.render.js +++ b/test/mithril.render.js @@ -1577,5 +1577,18 @@ describe("m.render()", function () { // This works only if select value is set after its options exist. expect(root.childNodes[0].value).to.equal("b") }) + + it("caches children of editable on update", function () { + var root = document.createElement("span") + var t1 = m.trust("

fo

o") + var t2 = "foo" + + m.render(root, m("span", {contenteditable: false}, t1)) + m.render(root, m("span", {contenteditable: true}, t2)) + m.render(root, m("span", {contenteditable: false}, t1)) + + expect(root.childNodes[0].innerHTML).to.equal(t1.valueOf()) + + }) }) }) From 97186f88a5353ad7955d53bad6fef7a44870a84d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Sat, 10 Sep 2016 01:18:59 +0200 Subject: [PATCH 2/2] Reactivate previously disabled test --- CONTRIBUTING.md | 1 - test/mithril.trust.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index de8d0b50..eb0febc9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,7 +22,6 @@ We welcome any and all contributions. This is a community-driven project. Althou 1. Please try to adhere to the style guide. Most of it is checked by ESLint. ESLint is also set up to check for other common errors, such as undeclared variables and invalid `typeof` values. 2. Please make sure there are no regressions with your patch. Please don't disable existing tests, and please don't send a PR with new, disabled tests. - - There is [one known failing test](https://github.com/lhorie/mithril.js/blob/015f1275631d79681a22fcd4ddfec4b5c0f5f6a6/test/mithril.trust.js#L44-55) currently (PR welcome). 3. For any new features introduced, be sure to write new unit tests for it. Maximum coverage is what we want. 4. Try to not leave any extra `TODO`s, `FIXME`s, etc. in your code. ESLint will nag at you until you fix whatever problem it is. - Note that it's only a warning, not an error. It won't fail the CI tests, and there's a few outstanding ones inside Mithril right now. diff --git a/test/mithril.trust.js b/test/mithril.trust.js index 16fd92ab..6b9d745e 100644 --- a/test/mithril.trust.js +++ b/test/mithril.trust.js @@ -41,8 +41,7 @@ describe("m.trust()", function () { expect(root.childNodes[3].tagName).to.equal("I") }) - // TODO: m.trust's contents are having their tags stripped. - xit("works with mixed trusted content in td", function () { + it("works with mixed trusted content in td", function () { var root = document.createElement("table") root.appendChild(root = document.createElement("tr"))