Skip to content

Commit d9f2dff

Browse files
chengloumayrang
andcommitted
fix: keep CJK opening brackets with annotations
Skip backward punctuation merges when the previous segment contains CJK so opening brackets can flow through to the forward-sticky pass and attach to the following annotation text. Closes #145 Refs #148. Co-authored-by: mayrang <pkss0626@naver.com>
1 parent a2726c9 commit d9f2dff

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/analysis.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ function buildMergedSegmentation(
10081008
!piece.isWordLike &&
10091009
mergedLen > 0 &&
10101010
mergedKinds[prevIndex] === 'text' &&
1011+
!mergedContainsCJK[prevIndex] &&
10111012
(
10121013
isLeftStickyPunctuationSegment(piece.text) ||
10131014
(piece.text === '-' && mergedWordLike[prevIndex]!)
@@ -1056,7 +1057,8 @@ function buildMergedSegmentation(
10561057
mergedKinds[i] === 'text' &&
10571058
!mergedWordLike[i]! &&
10581059
isEscapedQuoteClusterSegment(mergedTexts[i]!) &&
1059-
mergedKinds[i - 1] === 'text'
1060+
mergedKinds[i - 1] === 'text' &&
1061+
!mergedContainsCJK[i - 1]
10601062
) {
10611063
mergedTexts[i - 1] += mergedTexts[i]!
10621064
mergedWordLike[i - 1] = mergedWordLike[i - 1]! || mergedWordLike[i]!

src/layout.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,14 @@ describe('prepare invariants', () => {
622622
expect(isCJK('hello')).toBe(false)
623623
})
624624

625+
test('keeps opening brackets after CJK attached to following annotation text', () => {
626+
expect(prepareWithSegments('서울(Seoul)과', FONT).segments).toEqual(['서', '울', '(Seoul)', '과'])
627+
expect(prepareWithSegments('東京(Tokyo)と', FONT).segments).toEqual(['東', '京', '(Tokyo)', 'と'])
628+
expect(prepareWithSegments('北京(Beijing)和', FONT).segments).toEqual(['北', '京', '(Beijing)', '和'])
629+
expect(prepareWithSegments('참조[1]와', FONT).segments).toEqual(['참', '조', '[1]', '와'])
630+
expect(prepareWithSegments('AB(CD)', FONT).segments).toEqual(['AB(', 'CD)'])
631+
})
632+
625633
test('prepare and prepareWithSegments agree on layout behavior', () => {
626634
const plain = prepare('Alpha beta gamma', FONT)
627635
const rich = prepareWithSegments('Alpha beta gamma', FONT)

0 commit comments

Comments
 (0)