Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Normalize Unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Wliu authored and Wliu committed Feb 19, 2018
1 parent 161ab6b commit e925dbc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/fuzzy-finder-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ class FuzzyFinderView {
if (colon !== -1) {
query = query.slice(0, colon)
}
// Normalize to backslashes on Windows
if (process.platform === 'win32') {

// Compose Unicode by default
query = query.normalize('NFC')
if (process.platform === 'darwin') {
// But decompose on macOS
query = query.normalize('NFD')
} else if (process.platform === 'win32') {
// Normalize to backslashes on Windows
query = query.replace(/\//g, '\\')
}

Expand Down
36 changes: 36 additions & 0 deletions spec/fuzzy-finder-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,42 @@ describe('FuzzyFinder', () => {
})
})

describe('unicode characters', () => {
const originalPlatform = process.platform

afterEach(() => {
Object.defineProperty(process, 'platform', {value: originalPlatform})
})

it('decomposes unicode characters on macOS', async () => {
Object.defineProperty(process, 'platform', {value: 'darwin'})

await bufferView.toggle()

bufferView.selectListView.refs.queryEditor.setText('erstiebegrüßung')

const query = bufferView.selectListView.getFilterQuery()
expect(query.length).toBe(16)
expect(query.includes('ü')).toBe(false)
expect(query.includes('u\u0308')).toBe(true)
})

it('composes unicode characters on Windows and Linux', async () => {
for (let platform of ['win32, linux']) {
Object.defineProperty(process, 'platform', {value: platform})

await bufferView.toggle()

bufferView.selectListView.refs.queryEditor.setText('erstiebegru\u0308ßung')

const query = bufferView.selectListView.getFilterQuery()
expect(query.length).toBe(15)
expect(query.includes('ü')).toBe(true)
expect(query.includes('u\u0308')).toBe(false)
}
})
})

describe('match highlighting', () => {
beforeEach(async () => {
jasmine.attachToDOM(workspaceElement)
Expand Down

0 comments on commit e925dbc

Please sign in to comment.