Skip to content

Commit

Permalink
fix: bread-break keep-all (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan authored Mar 3, 2023
1 parent 83d6585 commit 239d57c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ export default async function* buildTextNodes(
}

const isBreakWord = wordBreak === 'break-word'
const isBreakAll = wordBreak === 'break-all'
const { words, requiredBreaks } = splitByBreakOpportunities(
content,
isBreakAll
wordBreak as string
)

// Create a container node for this text fragment.
Expand Down
8 changes: 6 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,19 @@ export function isString(x: unknown): x is string {

export function splitByBreakOpportunities(
content: string,
isBreakAll
wordBreak: string
): {
words: string[]
requiredBreaks: boolean[]
} {
if (isBreakAll) {
if (wordBreak === 'break-all') {
return { words: segment(content, 'grapheme'), requiredBreaks: [] }
}

if (wordBreak === 'keep-all') {
return { words: segment(content, 'word'), requiredBreaks: [] }
}

const breaker = new LineBreaker(content)
let last = 0
let bk = breaker.nextBreak()
Expand Down

1 comment on commit 239d57c

@vercel
Copy link

@vercel vercel bot commented on 239d57c Mar 3, 2023

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.