Skip to content

Commit 31afbe3

Browse files
authored
Using different backgrounds on composition instead of underline (microsoft#229806)
using backgrounds instead of underline
1 parent 9a91d33 commit 31afbe3

File tree

2 files changed

+26
-44
lines changed

2 files changed

+26
-44
lines changed

src/vs/editor/browser/controller/editContext/native/nativeEditContext.css

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,14 @@
1313
text-wrap: nowrap;
1414
}
1515

16-
.monaco-editor .edit-context-format-decoration {
17-
text-decoration-line: underline;
18-
/* TODO @aiday chose a theme color */
19-
text-decoration-color: blue;
20-
color: var(--vscode-editor-foreground, inherit);
21-
opacity: 0.8;
22-
23-
&.underline-style-none {
24-
text-decoration-line: none;
25-
text-decoration-style: none;
26-
}
27-
28-
&.underline-style-solid {
29-
text-decoration-style: solid;
30-
}
31-
32-
&.underline-style-dotted {
33-
text-decoration-style: dotted;
34-
}
35-
36-
&.underline-style-dashed {
37-
text-decoration-style: dashed;
38-
}
39-
40-
&.underline-style-wavy {
41-
text-decoration-style: wavy;
42-
}
43-
44-
&.underline-thickness-none {
45-
text-decoration-line: none;
46-
text-decoration-thickness: none;
47-
}
16+
.monaco-editor .edit-context-composition-none {
17+
background-color: transparent;
18+
}
4819

49-
&.underline-thickness-thin {
50-
text-decoration-thickness: 1px;
51-
}
20+
.monaco-editor .edit-context-composition-secondary {
21+
background-color: var(--vscode-editor-selectionBackground);
22+
}
5223

53-
&.underline-thickness-thick {
54-
text-decoration-thickness: 2px;
55-
}
24+
.monaco-editor .edit-context-composition-primary {
25+
background-color: var(--vscode-editor-selectionHighlightBackground);
5626
}

src/vs/editor/browser/controller/editContext/native/nativeEditContext.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import { Position } from '../../../../common/core/position.js';
2727
import { IVisibleRangeProvider } from '../textArea/textAreaEditContext.js';
2828
import { PositionOffsetTransformer } from '../../../../common/core/positionToOffset.js';
2929

30+
// Corresponds to classes in nativeEditContext.css
31+
enum CompositionClassName {
32+
NONE = 'edit-context-composition-none',
33+
SECONDARY = 'edit-context-composition-secondary',
34+
PRIMARY = 'edit-context-composition-primary',
35+
}
36+
3037
export class NativeEditContext extends AbstractEditContext {
3138

3239
public readonly domNode: FastDomNode<HTMLDivElement>;
@@ -257,16 +264,21 @@ export class NativeEditContext extends AbstractEditContext {
257264
const startPositionOfDecoration = textModel.getPositionAt(offsetOfEditContextText + f.rangeStart);
258265
const endPositionOfDecoration = textModel.getPositionAt(offsetOfEditContextText + f.rangeEnd);
259266
const decorationRange = Range.fromPositions(startPositionOfDecoration, endPositionOfDecoration);
260-
const classNames = [
261-
'edit-context-format-decoration',
262-
`underline-style-${f.underlineStyle.toLowerCase()}`,
263-
`underline-thickness-${f.underlineThickness.toLowerCase()}`,
264-
];
267+
const thickness = f.underlineThickness.toLowerCase();
268+
let decorationClassName: string = CompositionClassName.NONE;
269+
switch (thickness) {
270+
case 'thin':
271+
decorationClassName = CompositionClassName.SECONDARY;
272+
break;
273+
case 'thick':
274+
decorationClassName = CompositionClassName.PRIMARY;
275+
break;
276+
}
265277
decorations.push({
266278
range: decorationRange,
267279
options: {
268280
description: 'textFormatDecoration',
269-
inlineClassName: classNames.join(' '),
281+
inlineClassName: decorationClassName,
270282
}
271283
});
272284
});

0 commit comments

Comments
 (0)