Skip to content

Commit 78ddcdc

Browse files
committed
Fixes microsoft#75494: do not break between surrogate pairs
1 parent cb67fba commit 78ddcdc

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/vs/editor/common/viewModel/characterHardWrappingLineMapper.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
136136
let charCodeIsTab = (charCode === CharCode.Tab);
137137
let charCodeClass = classifier.get(charCode);
138138

139+
if (strings.isLowSurrogate(charCode)/* && i + 1 < len */) {
140+
// A surrogate pair must always be considered as a single unit, so it is never to be broken
141+
// => advance visibleColumn by 1 and advance to next char code...
142+
visibleColumn = visibleColumn + 1;
143+
continue;
144+
}
145+
139146
if (charCodeClass === CharacterClass.BREAK_BEFORE) {
140147
// This is a character that indicates that a break should happen before it
141148
// Since we are certain the character before `i` fits, there's no extra checking needed,

src/vs/editor/test/common/viewModel/characterHardWrappingLineMapper.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ suite('Editor ViewModel - CharacterHardWrappingLineMapper', () => {
114114
assert.equal(mapper!.getWrappedLinesIndent(), ' \t');
115115
});
116116

117+
test('issue #75494: surrogate pairs', () => {
118+
let factory = new CharacterHardWrappingLineMapperFactory('', ' ', '');
119+
assertLineMapping(factory, 4, 49, '🐇👬🌖🌞🏇🍼🐇👬🌖🌞🏇🍼🐇👬🌖🌞🏇🍼🐇👬🌖🌞🏇🍼🐇|👬🌖🌞🏇🍼🐇👬🌖🌞🏇🍼🐇👬🌖🌞🏇🍼🐇👬🌖🌞🏇🍼🐇👬', WrappingIndent.Same);
120+
});
121+
117122
test('CharacterHardWrappingLineMapper - WrappingIndent.DeepIndent', () => {
118123
let factory = new CharacterHardWrappingLineMapperFactory('', ' ', '');
119124
let mapper = assertLineMapping(factory, 4, 26, ' W e A r e T e s t |i n g D e |e p I n d |e n t a t |i o n', WrappingIndent.DeepIndent);

0 commit comments

Comments
 (0)