Skip to content

Commit 9f218d1

Browse files
committed
Fixes microsoft#87359: Use U+2E31 - WORD SEPARATOR MIDDLE DOT instead of U+00B7 - MIDDLE DOT when the latter is wider than space
1 parent b5e9cb5 commit 9f218d1

11 files changed

Lines changed: 63 additions & 2 deletions

File tree

src/vs/editor/browser/config/configuration.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface ISerializedFontInfo {
8787
readonly typicalFullwidthCharacterWidth: number;
8888
readonly canUseHalfwidthRightwardsArrow: boolean;
8989
readonly spaceWidth: number;
90+
middotWidth: number;
9091
readonly maxDigitWidth: number;
9192
}
9293

@@ -159,6 +160,7 @@ class CSSBasedConfiguration extends Disposable {
159160
const savedFontInfo = savedFontInfos[i];
160161
// compatibility with older versions of VS Code which did not store this...
161162
savedFontInfo.fontFeatureSettings = savedFontInfo.fontFeatureSettings || EditorFontLigatures.OFF;
163+
savedFontInfo.middotWidth = savedFontInfo.middotWidth || savedFontInfo.spaceWidth;
162164
const fontInfo = new FontInfo(savedFontInfo, false);
163165
this._writeToCache(fontInfo, fontInfo);
164166
}
@@ -183,6 +185,7 @@ class CSSBasedConfiguration extends Disposable {
183185
typicalFullwidthCharacterWidth: Math.max(readConfig.typicalFullwidthCharacterWidth, 5),
184186
canUseHalfwidthRightwardsArrow: readConfig.canUseHalfwidthRightwardsArrow,
185187
spaceWidth: Math.max(readConfig.spaceWidth, 5),
188+
middotWidth: Math.max(readConfig.middotWidth, 5),
186189
maxDigitWidth: Math.max(readConfig.maxDigitWidth, 5),
187190
}, false);
188191
}
@@ -223,7 +226,8 @@ class CSSBasedConfiguration extends Disposable {
223226
const rightwardsArrow = this.createRequest('→', CharWidthRequestType.Regular, all, monospace);
224227
const halfwidthRightwardsArrow = this.createRequest('→', CharWidthRequestType.Regular, all, null);
225228

226-
this.createRequest('·', CharWidthRequestType.Regular, all, monospace);
229+
// middle dot character
230+
const middot = this.createRequest('·', CharWidthRequestType.Regular, all, monospace);
227231

228232
// monospace test: some characters
229233
this.createRequest('|', CharWidthRequestType.Regular, all, monospace);
@@ -289,6 +293,7 @@ class CSSBasedConfiguration extends Disposable {
289293
typicalFullwidthCharacterWidth: typicalFullwidthCharacter.width,
290294
canUseHalfwidthRightwardsArrow: canUseHalfwidthRightwardsArrow,
291295
spaceWidth: space.width,
296+
middotWidth: middot.width,
292297
maxDigitWidth: maxDigitWidth
293298
}, canTrustBrowserZoomLevel);
294299
}

src/vs/editor/browser/viewParts/lines/viewLine.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class ViewLineOptions {
7373
public readonly renderWhitespace: 'none' | 'boundary' | 'selection' | 'all';
7474
public readonly renderControlCharacters: boolean;
7575
public readonly spaceWidth: number;
76+
public readonly middotWidth: number;
7677
public readonly useMonospaceOptimizations: boolean;
7778
public readonly canUseHalfwidthRightwardsArrow: boolean;
7879
public readonly lineHeight: number;
@@ -86,6 +87,7 @@ export class ViewLineOptions {
8687
this.renderWhitespace = options.get(EditorOption.renderWhitespace);
8788
this.renderControlCharacters = options.get(EditorOption.renderControlCharacters);
8889
this.spaceWidth = fontInfo.spaceWidth;
90+
this.middotWidth = fontInfo.middotWidth;
8991
this.useMonospaceOptimizations = (
9092
fontInfo.isMonospace
9193
&& !options.get(EditorOption.disableMonospaceOptimizations)
@@ -102,6 +104,7 @@ export class ViewLineOptions {
102104
&& this.renderWhitespace === other.renderWhitespace
103105
&& this.renderControlCharacters === other.renderControlCharacters
104106
&& this.spaceWidth === other.spaceWidth
107+
&& this.middotWidth === other.middotWidth
105108
&& this.useMonospaceOptimizations === other.useMonospaceOptimizations
106109
&& this.canUseHalfwidthRightwardsArrow === other.canUseHalfwidthRightwardsArrow
107110
&& this.lineHeight === other.lineHeight
@@ -215,6 +218,7 @@ export class ViewLine implements IVisibleLine {
215218
lineData.tabSize,
216219
lineData.startVisibleColumn,
217220
options.spaceWidth,
221+
options.middotWidth,
218222
options.stopRenderingLineAfter,
219223
options.renderWhitespace,
220224
options.renderControlCharacters,

src/vs/editor/browser/widget/diffEditorWidget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {
21462146
tabSize,
21472147
0,
21482148
fontInfo.spaceWidth,
2149+
fontInfo.middotWidth,
21492150
options.get(EditorOption.stopRenderingLineAfter),
21502151
options.get(EditorOption.renderWhitespace),
21512152
options.get(EditorOption.renderControlCharacters),

src/vs/editor/browser/widget/diffReview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ export class DiffReview extends Disposable {
782782
tabSize,
783783
0,
784784
fontInfo.spaceWidth,
785+
fontInfo.middotWidth,
785786
options.get(EditorOption.stopRenderingLineAfter),
786787
options.get(EditorOption.renderWhitespace),
787788
options.get(EditorOption.renderControlCharacters),

src/vs/editor/common/config/fontInfo.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export class FontInfo extends BareFontInfo {
134134
readonly typicalFullwidthCharacterWidth: number;
135135
readonly canUseHalfwidthRightwardsArrow: boolean;
136136
readonly spaceWidth: number;
137+
readonly middotWidth: number;
137138
readonly maxDigitWidth: number;
138139

139140
/**
@@ -152,6 +153,7 @@ export class FontInfo extends BareFontInfo {
152153
typicalFullwidthCharacterWidth: number;
153154
canUseHalfwidthRightwardsArrow: boolean;
154155
spaceWidth: number;
156+
middotWidth: number;
155157
maxDigitWidth: number;
156158
}, isTrusted: boolean) {
157159
super(opts);
@@ -161,6 +163,7 @@ export class FontInfo extends BareFontInfo {
161163
this.typicalFullwidthCharacterWidth = opts.typicalFullwidthCharacterWidth;
162164
this.canUseHalfwidthRightwardsArrow = opts.canUseHalfwidthRightwardsArrow;
163165
this.spaceWidth = opts.spaceWidth;
166+
this.middotWidth = opts.middotWidth;
164167
this.maxDigitWidth = opts.maxDigitWidth;
165168
}
166169

@@ -179,6 +182,7 @@ export class FontInfo extends BareFontInfo {
179182
&& this.typicalFullwidthCharacterWidth === other.typicalFullwidthCharacterWidth
180183
&& this.canUseHalfwidthRightwardsArrow === other.canUseHalfwidthRightwardsArrow
181184
&& this.spaceWidth === other.spaceWidth
185+
&& this.middotWidth === other.middotWidth
182186
&& this.maxDigitWidth === other.maxDigitWidth
183187
);
184188
}

src/vs/editor/common/viewLayout/viewLineRenderer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class RenderLineInput {
6868
public readonly tabSize: number;
6969
public readonly startVisibleColumn: number;
7070
public readonly spaceWidth: number;
71+
public readonly middotWidth: number;
7172
public readonly stopRenderingLineAfter: number;
7273
public readonly renderWhitespace: RenderWhitespace;
7374
public readonly renderControlCharacters: boolean;
@@ -92,6 +93,7 @@ export class RenderLineInput {
9293
tabSize: number,
9394
startVisibleColumn: number,
9495
spaceWidth: number,
96+
middotWidth: number,
9597
stopRenderingLineAfter: number,
9698
renderWhitespace: 'none' | 'boundary' | 'selection' | 'all',
9799
renderControlCharacters: boolean,
@@ -110,6 +112,7 @@ export class RenderLineInput {
110112
this.tabSize = tabSize;
111113
this.startVisibleColumn = startVisibleColumn;
112114
this.spaceWidth = spaceWidth;
115+
this.middotWidth = middotWidth;
113116
this.stopRenderingLineAfter = stopRenderingLineAfter;
114117
this.renderWhitespace = (
115118
renderWhitespace === 'all'
@@ -380,6 +383,7 @@ class ResolvedRenderLineInput {
380383
public readonly startVisibleColumn: number,
381384
public readonly containsRTL: boolean,
382385
public readonly spaceWidth: number,
386+
public readonly middotWidth: number,
383387
public readonly renderWhitespace: RenderWhitespace,
384388
public readonly renderControlCharacters: boolean,
385389
) {
@@ -439,6 +443,7 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
439443
input.startVisibleColumn,
440444
input.containsRTL,
441445
input.spaceWidth,
446+
input.middotWidth,
442447
input.renderWhitespace,
443448
input.renderControlCharacters
444449
);
@@ -734,9 +739,13 @@ function _renderLine(input: ResolvedRenderLineInput, sb: IStringBuilder): Render
734739
const startVisibleColumn = input.startVisibleColumn;
735740
const containsRTL = input.containsRTL;
736741
const spaceWidth = input.spaceWidth;
742+
const middotWidth = input.middotWidth;
737743
const renderWhitespace = input.renderWhitespace;
738744
const renderControlCharacters = input.renderControlCharacters;
739745

746+
// use U+2E31 - WORD SEPARATOR MIDDLE DOT or U+00B7 - MIDDLE DOT
747+
const spaceRenderWhitespaceCharacter = (middotWidth > spaceWidth ? 0x2E31 : 0xB7);
748+
740749
const characterMapping = new CharacterMapping(len + 1, parts.length);
741750

742751
let charIndex = 0;
@@ -808,7 +817,7 @@ function _renderLine(input: ResolvedRenderLineInput, sb: IStringBuilder): Render
808817
} else { // must be CharCode.Space
809818
charWidth = 1;
810819

811-
sb.write1(0xB7); // ·
820+
sb.write1(spaceRenderWhitespaceCharacter); // · or word separator middle dot
812821
}
813822

814823
charOffsetInPart += charWidth;

src/vs/editor/standalone/browser/colorizer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class Colorizer {
126126
tabSize,
127127
0,
128128
0,
129+
0,
129130
-1,
130131
'none',
131132
false,
@@ -195,6 +196,7 @@ function _fakeColorize(lines: string[], tabSize: number): string {
195196
tabSize,
196197
0,
197198
0,
199+
0,
198200
-1,
199201
'none',
200202
false,
@@ -233,6 +235,7 @@ function _actualColorize(lines: string[], tabSize: number, tokenizationSupport:
233235
tabSize,
234236
0,
235237
0,
238+
0,
236239
-1,
237240
'none',
238241
false,

src/vs/editor/test/common/mocks/testConfiguration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class TestConfiguration extends CommonEditorConfiguration {
4141
typicalFullwidthCharacterWidth: 20,
4242
canUseHalfwidthRightwardsArrow: true,
4343
spaceWidth: 10,
44+
middotWidth: 10,
4445
maxDigitWidth: 10,
4546
}, true);
4647
}

0 commit comments

Comments
 (0)