Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep combining character sequences together #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/LineBreak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ const _lineBreakAtIndex = (
return BREAK_NOT_ALLOWED;
}

// see LB9 in codePointsToCharacterClasses
if (indicies[index] === indicies[index -1]) {
return BREAK_NOT_ALLOWED;
}

let currentIndex = index - 1;
if (Array.isArray(forbiddenBreaks) && forbiddenBreaks[currentIndex] === true) {
return BREAK_NOT_ALLOWED;
Expand Down Expand Up @@ -311,11 +316,6 @@ const _lineBreakAtIndex = (
return BREAK_NOT_ALLOWED;
}

// zwj emojis
if ((current === EB || current === EM) && UnicodeTrie.get(codePoints[afterIndex]) === ZWJ) {
return BREAK_NOT_ALLOWED;
}

// LB11 Do not break before or after Word joiner and related characters.
if (current === WJ || next === WJ) {
return BREAK_NOT_ALLOWED;
Expand Down
4 changes: 2 additions & 2 deletions tests/LineBreaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('LineBreaker', () => {
});

it('should handle zwj emojis', () => {
const breaker = LineBreaker('Text with zwj emojis 👨‍👩‍👧‍👦 and modifiers 🤷🏾‍♂️.');
const breaker = LineBreaker('Text with zwj emojis 👨‍👩‍👧‍👦 and 🏳️‍🌈 and modifiers 🤷🏾‍♂️.');

const words = [];
let bk;
Expand All @@ -29,7 +29,7 @@ describe('LineBreaker', () => {
}
}

deepEqual(words, ['Text ', 'with ', 'zwj ', 'emojis ', '👨‍👩‍👧‍👦 ', 'and ', 'modifiers ', '🤷🏾‍♂️.']);
deepEqual(words, ['Text ', 'with ', 'zwj ', 'emojis ', '👨‍👩‍👧‍👦 ', 'and ', '🏳️‍🌈 ', 'and ', 'modifiers ', '🤷🏾‍♂️.']);
});

it('Works with options', () => {
Expand Down