add a fix, TODO: refactor

Summary: fix(service): Remove redundant tail newline when hiding previous in compose view. Fixes T2467.

Test Plan: Added a test to verify that all tail newlines are removed except one. Added another to verify that non-tail newlines aren't removed. Tweaked an existing test to make it pass.

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T2467

Differential Revision: https://phab.nylas.com/D1864
This commit is contained in:
dillon 2015-08-11 11:35:33 -07:00
parent 1ce7b62be1
commit 262eb71c0b
3 changed files with 23 additions and 1 deletions

View file

@ -11,7 +11,7 @@ ContenteditableComponent = require "../lib/contenteditable-component",
describe "ContenteditableComponent", ->
beforeEach ->
@onChange = jasmine.createSpy('onChange')
@html = 'Test <strong>HTML</strong><br><br>'
@html = 'Test <strong>HTML</strong><br>'
@component = ReactTestUtils.renderIntoDocument(
<ContenteditableComponent html={@html} onChange={@onChange}/>
)

View file

@ -242,6 +242,16 @@ describe "QuotedHTMLParser", ->
test = clean(QuotedHTMLParser.removeQuotedHTML(before))
expect(test).toEqual clean(after)
it 'removes all trailing <br> tags except one', ->
input0 = "hello world<br><br><blockquote>foolololol</blockquote>"
expect0 = "<head></head><body>hello world<br></body>"
expect(QuotedHTMLParser.removeQuotedHTML(input0)).toEqual expect0
it 'preserves <br> tags in the middle and only chops off tail', ->
input0 = "hello<br><br>world<br><br><blockquote>foolololol</blockquote>"
expect0 = "<head></head><body>hello<br><br>world<br></body>"
expect(QuotedHTMLParser.removeQuotedHTML(input0)).toEqual expect0
# We have a little utility method that you can manually uncomment to

View file

@ -36,6 +36,18 @@ class QuotedHTMLParser
doc = @_parseHTML(html)
quoteElements = @_findQuoteLikeElements(doc, options)
DOMUtils.removeElements(quoteElements, options)
childNodes = doc.body.childNodes
extraTailBrTags = []
for i in [(childNodes.length - 1)..0] by -1
curr = childNodes[i]
next = childNodes[i - 1]
if curr and curr.nodeName == 'BR' and next and next.nodeName == 'BR'
extraTailBrTags.push(curr)
else
break
DOMUtils.removeElements(extraTailBrTags)
return doc.children[0].innerHTML
appendQuotedHTML: (htmlWithoutQuotes, originalHTML) ->