From f855771beba3f5b043c7bf1c2ec39ad83a7bb53d Mon Sep 17 00:00:00 2001 From: Blake Thomson Date: Thu, 19 Mar 2015 12:11:32 -0400 Subject: [PATCH] Ensure targetNode matches leaf.length in formatText Without this call to split(), the targetNode may outgrow leaf.length, causing the call to format.add(targetNode, value) to operate on more than was intended. Fixes #310 --- src/core/line.coffee | 1 + test/unit/core/line.coffee | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/core/line.coffee b/src/core/line.coffee index 04296fe4e4..9764409d84 100644 --- a/src/core/line.coffee +++ b/src/core/line.coffee @@ -101,6 +101,7 @@ class Line extends LinkedList.Node dom(targetNode).splitBefore(@node) while !format.match(targetNode) targetNode = targetNode.parentNode + dom(targetNode).split(leaf.length) # Isolate target node if leafOffset > 0 [leftNode, targetNode] = dom(targetNode).split(leafOffset) diff --git a/test/unit/core/line.coffee b/test/unit/core/line.coffee index fe40b06687..e5bf30a224 100644 --- a/test/unit/core/line.coffee +++ b/test/unit/core/line.coffee @@ -275,6 +275,10 @@ describe('Line', -> initial: '01234567' expected: '01234567' args: [3, 4, 'bold', false] + 'split boundaries with parents remove at beginning': + initial: '0123' + expected: '0123' + args: [0, 4, 'bold', false] 'remove image': initial: '0134' expected: "01#{dom.EMBED_TEXT}34"