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

Break at the start of multiple BREAK_BEFORE chars and at the end of multiple BREAK_AFTER chars #153121

Merged
merged 1 commit into from Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts
Expand Up @@ -411,7 +411,7 @@ function createLineBreaks(classifier: WrappingCharacterClassifier, _lineText: st
for (let i = startOffset; i < len; i++) {
const charStartOffset = i;
const charCode = lineText.charCodeAt(i);
let charCodeClass: number;
let charCodeClass: CharacterClass;
let charWidth: number;

if (strings.isHighSurrogate(charCode)) {
Expand Down Expand Up @@ -489,9 +489,9 @@ function canBreak(prevCharCode: number, prevCharCodeClass: CharacterClass, charC
return (
charCode !== CharCode.Space
&& (
(prevCharCodeClass === CharacterClass.BREAK_AFTER)
(prevCharCodeClass === CharacterClass.BREAK_AFTER && charCodeClass !== CharacterClass.BREAK_AFTER) // break at the end of multiple BREAK_AFTER
|| (prevCharCodeClass !== CharacterClass.BREAK_BEFORE && charCodeClass === CharacterClass.BREAK_BEFORE) // break at the start of multiple BREAK_BEFORE
|| (prevCharCodeClass === CharacterClass.BREAK_IDEOGRAPHIC && charCodeClass !== CharacterClass.BREAK_AFTER)
|| (charCodeClass === CharacterClass.BREAK_BEFORE)
|| (charCodeClass === CharacterClass.BREAK_IDEOGRAPHIC && prevCharCodeClass !== CharacterClass.BREAK_BEFORE)
)
);
Expand Down
Expand Up @@ -116,9 +116,9 @@ suite('Editor ViewModel - MonospaceLineBreaksComputer', () => {
assertLineBreaks(factory, 4, 5, 'aaa))|).aaa');
assertLineBreaks(factory, 4, 5, 'aaa))|).|aaaa');
assertLineBreaks(factory, 4, 5, 'aaa)|().|aaa');
assertLineBreaks(factory, 4, 5, 'aaa(|().|aaa');
assertLineBreaks(factory, 4, 5, 'aa.(|().|aaa');
assertLineBreaks(factory, 4, 5, 'aa.(.|).aaa');
assertLineBreaks(factory, 4, 5, 'aaa|(().|aaa');
assertLineBreaks(factory, 4, 5, 'aa.|(().|aaa');
assertLineBreaks(factory, 4, 5, 'aa.|(.).|aaa');
});

function assertLineBreakDataEqual(a: ModelLineProjectionData | null, b: ModelLineProjectionData | null): void {
Expand Down Expand Up @@ -293,6 +293,11 @@ suite('Editor ViewModel - MonospaceLineBreaksComputer', () => {
assertLineBreaks(factory, 4, 23, 'this is a line of |text, text that sits |on a line', WrappingIndent.Same);
});

test('issue #152773: Word wrap algorithm behaves differently with bracket followed by comma', () => {
const factory = new MonospaceLineBreaksComputerFactory(EditorOptions.wordWrapBreakBeforeCharacters.defaultValue, EditorOptions.wordWrapBreakAfterCharacters.defaultValue);
assertLineBreaks(factory, 4, 24, 'this is a line of |(text), text that sits |on a line', WrappingIndent.Same);
});

test('issue #112382: Word wrap doesn\'t work well with control characters', () => {
const factory = new MonospaceLineBreaksComputerFactory(EditorOptions.wordWrapBreakBeforeCharacters.defaultValue, EditorOptions.wordWrapBreakAfterCharacters.defaultValue);
assertLineBreaks(factory, 4, 6, '\x06\x06\x06|\x06\x06\x06', WrappingIndent.Same);
Expand Down