Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
🐛 Guard against empty trailing whitespace
Browse files Browse the repository at this point in the history
An empty trailing whitespace was being generated and this caused empty
trailing tokens to be appended to the HTML, thereby screwing up the
binary search.

/cc: @nathansobo
  • Loading branch information
as-cii committed Jul 23, 2015
1 parent 63ca3d5 commit 377771c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/line-html-builder.coffee
Expand Up @@ -134,16 +134,19 @@ class LineHtmlBuilder
if firstTrailingWhitespaceIndex?
tokenIsOnlyWhitespace = firstTrailingWhitespaceIndex is 0
trailingWhitespace = tokenText.substring(firstTrailingWhitespaceIndex)
trailingWhitespaceEndIndex = tokenStart + firstTrailingWhitespaceIndex + trailingWhitespace.length

classes = 'trailing-whitespace'
classes += ' indent-guide' if hasIndentGuide and not firstNonWhitespaceIndex? and tokenIsOnlyWhitespace
classes += ' invisible-character' if hasInvisibleCharacters
unless trailingWhitespace is ""
trailingWhitespaceStartIndex = tokenStart + firstTrailingWhitespaceIndex
trailingWhitespaceEndIndex = trailingWhitespaceStartIndex + trailingWhitespace.length

classes = 'trailing-whitespace'
classes += ' indent-guide' if hasIndentGuide and not firstNonWhitespaceIndex? and tokenIsOnlyWhitespace
classes += ' invisible-character' if hasInvisibleCharacters


trailingHtml = "<span data-start='#{tokenStart + firstTrailingWhitespaceIndex}' data-end='#{trailingWhitespaceEndIndex}' class='token #{classes}'>#{trailingWhitespace}</span>"
trailingHtml = "<span data-start='#{trailingWhitespaceStartIndex}' data-end='#{trailingWhitespaceEndIndex}' class='token #{classes}'>#{trailingWhitespace}</span>"

endIndex = firstTrailingWhitespaceIndex
endIndex = firstTrailingWhitespaceIndex

html = leadingHtml
if tokenText.length > MaxTokenLength
Expand Down

1 comment on commit 377771c

@nathansobo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.