Don’t tokenize spaces preceding combining chars as leading whitespace

Fixes #5349
This commit is contained in:
Nathan Sobo 2015-02-24 12:10:25 -07:00
parent 5fdb3cde08
commit 0bf0c0527f
2 changed files with 15 additions and 0 deletions

View File

@ -318,6 +318,18 @@ describe "TokenizedBuffer", ->
expect(tokenizedBuffer.tokenizedLineForRow(5).tokens[1].isAtomic).toBeFalsy()
expect(tokenizedBuffer.tokenizedLineForRow(5).tokens[1].value).toBe " current "
it "does not tokenize whitespaces followed by combining characters as leading whitespace", ->
buffer.setText(" \u030b")
fullyTokenize(tokenizedBuffer)
{tokens} = tokenizedBuffer.tokenizedLineForRow(0)
expect(tokens[0].value).toBe " "
expect(tokens[0].hasLeadingWhitespace()).toBe true
expect(tokens[1].value).toBe " "
expect(tokens[1].hasLeadingWhitespace()).toBe true
expect(tokens[2].value).toBe " \u030b"
expect(tokens[2].hasLeadingWhitespace()).toBe false
describe "when the buffer contains hard-tabs", ->
beforeEach ->
waitsForPromise ->

View File

@ -1,4 +1,5 @@
_ = require 'underscore-plus'
{isPairedCharacter} = require './text-utils'
NonWhitespaceRegex = /\S/
LeadingWhitespaceRegex = /^\s*/
@ -147,6 +148,8 @@ class TokenizedLine
markLeadingAndTrailingWhitespaceTokens: ->
firstNonWhitespaceIndex = @text.search(NonWhitespaceRegex)
if firstNonWhitespaceIndex > 0 and isPairedCharacter(@text, firstNonWhitespaceIndex - 1)
firstNonWhitespaceIndex--
firstTrailingWhitespaceIndex = @text.search(TrailingWhitespaceRegex)
@lineIsWhitespaceOnly = firstTrailingWhitespaceIndex is 0
index = 0