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
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
fix: keep combining character sequences together
pasieronen committed Mar 13, 2022
commit 41fd84f01fc9a836406c77949cefe09954290881
10 changes: 5 additions & 5 deletions src/LineBreak.ts
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
4 changes: 2 additions & 2 deletions tests/LineBreaker.ts
Original file line number Diff line number Diff line change
@@ -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;
@@ -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', () => {