Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
af7765c0
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
af7765c0
编写于
8月 08, 2020
作者:
S
Stepan Repin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add 'trailing' option to render whitespace
上级
6d913c4c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
116 addition
and
12 deletion
+116
-12
src/vs/editor/browser/viewParts/lines/viewLine.ts
src/vs/editor/browser/viewParts/lines/viewLine.ts
+1
-1
src/vs/editor/common/config/editorOptions.ts
src/vs/editor/common/config/editorOptions.ts
+4
-3
src/vs/editor/common/viewLayout/viewLineRenderer.ts
src/vs/editor/common/viewLayout/viewLineRenderer.ts
+19
-5
src/vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
...vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
+90
-1
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+2
-2
未找到文件。
src/vs/editor/browser/viewParts/lines/viewLine.ts
浏览文件 @
af7765c0
...
...
@@ -72,7 +72,7 @@ export class DomReadingContext {
export
class
ViewLineOptions
{
public
readonly
themeType
:
ThemeType
;
public
readonly
renderWhitespace
:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
all
'
;
public
readonly
renderWhitespace
:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
trailing
'
|
'
all
'
;
public
readonly
renderControlCharacters
:
boolean
;
public
readonly
spaceWidth
:
number
;
public
readonly
middotWidth
:
number
;
...
...
src/vs/editor/common/config/editorOptions.ts
浏览文件 @
af7765c0
...
...
@@ -529,7 +529,7 @@ export interface IEditorOptions {
* Enable rendering of whitespace.
* Defaults to none.
*/
renderWhitespace
?:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
all
'
;
renderWhitespace
?:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
trailing
'
|
'
all
'
;
/**
* Enable rendering of control characters.
* Defaults to false.
...
...
@@ -4037,13 +4037,14 @@ export const EditorOptions = {
)),
renderWhitespace
:
register
(
new
EditorStringEnumOption
(
EditorOption
.
renderWhitespace
,
'
renderWhitespace
'
,
'
selection
'
as
'
selection
'
|
'
none
'
|
'
boundary
'
|
'
all
'
,
[
'
none
'
,
'
boundary
'
,
'
selection
'
,
'
all
'
]
as
const
,
'
selection
'
as
'
selection
'
|
'
none
'
|
'
boundary
'
|
'
trailing
'
|
'
all
'
,
[
'
none
'
,
'
boundary
'
,
'
selection
'
,
'
trailing
'
,
'
all
'
]
as
const
,
{
enumDescriptions
:
[
''
,
nls
.
localize
(
'
renderWhitespace.boundary
'
,
"
Render whitespace characters except for single spaces between words.
"
),
nls
.
localize
(
'
renderWhitespace.selection
'
,
"
Render whitespace characters only on selected text.
"
),
nls
.
localize
(
'
renderWhitespace.trailing
'
,
"
Render only trailing whitespace characters
"
),
''
],
description
:
nls
.
localize
(
'
renderWhitespace
'
,
"
Controls how the editor should render whitespace characters.
"
)
...
...
src/vs/editor/common/viewLayout/viewLineRenderer.ts
浏览文件 @
af7765c0
...
...
@@ -14,7 +14,8 @@ export const enum RenderWhitespace {
None
=
0
,
Boundary
=
1
,
Selection
=
2
,
All
=
3
Trailing
=
3
,
All
=
4
}
export
const
enum
LinePartMetadata
{
...
...
@@ -113,7 +114,7 @@ export class RenderLineInput {
middotWidth
:
number
,
wsmiddotWidth
:
number
,
stopRenderingLineAfter
:
number
,
renderWhitespace
:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
all
'
,
renderWhitespace
:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
trailing
'
|
'
all
'
,
renderControlCharacters
:
boolean
,
fontLigatures
:
boolean
,
selectionsOnLine
:
LineRange
[]
|
null
...
...
@@ -138,6 +139,8 @@ export class RenderLineInput {
?
RenderWhitespace
.
Boundary
:
renderWhitespace
===
'
selection
'
?
RenderWhitespace
.
Selection
:
renderWhitespace
===
'
trailing
'
?
RenderWhitespace
.
Trailing
:
RenderWhitespace
.
None
);
this
.
renderControlCharacters
=
renderControlCharacters
;
...
...
@@ -435,7 +438,11 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
}
let
tokens
=
transformAndRemoveOverflowing
(
input
.
lineTokens
,
input
.
fauxIndentLength
,
len
);
if
(
input
.
renderWhitespace
===
RenderWhitespace
.
All
||
input
.
renderWhitespace
===
RenderWhitespace
.
Boundary
||
(
input
.
renderWhitespace
===
RenderWhitespace
.
Selection
&&
!!
input
.
selectionsOnLine
))
{
if
(
input
.
renderWhitespace
===
RenderWhitespace
.
All
||
input
.
renderWhitespace
===
RenderWhitespace
.
Boundary
||
(
input
.
renderWhitespace
===
RenderWhitespace
.
Selection
&&
!!
input
.
selectionsOnLine
)
||
input
.
renderWhitespace
===
RenderWhitespace
.
Trailing
)
{
tokens
=
_applyRenderWhitespace
(
input
,
lineContent
,
len
,
tokens
);
}
let
containsForeignElements
=
ForeignElementType
.
None
;
...
...
@@ -592,6 +599,7 @@ function _applyRenderWhitespace(input: RenderLineInput, lineContent: string, len
const
useMonospaceOptimizations
=
input
.
useMonospaceOptimizations
;
const
selections
=
input
.
selectionsOnLine
;
const
onlyBoundary
=
(
input
.
renderWhitespace
===
RenderWhitespace
.
Boundary
);
const
onlyTrailing
=
(
input
.
renderWhitespace
===
RenderWhitespace
.
Trailing
);
const
generateLinePartForEachWhitespace
=
(
input
.
renderSpaceWidth
!==
input
.
spaceWidth
);
let
result
:
LinePart
[]
=
[],
resultLen
=
0
;
...
...
@@ -600,10 +608,11 @@ function _applyRenderWhitespace(input: RenderLineInput, lineContent: string, len
let
tokenEndIndex
=
tokens
[
tokenIndex
].
endIndex
;
const
tokensLength
=
tokens
.
length
;
let
lineIsEmptyOrWhitespace
=
false
;
let
firstNonWhitespaceIndex
=
strings
.
firstNonWhitespaceIndex
(
lineContent
);
let
lastNonWhitespaceIndex
:
number
;
if
(
firstNonWhitespaceIndex
===
-
1
)
{
// The entire line is whitespace
lineIsEmptyOrWhitespace
=
true
;
firstNonWhitespaceIndex
=
len
;
lastNonWhitespaceIndex
=
len
;
}
else
{
...
...
@@ -651,6 +660,11 @@ function _applyRenderWhitespace(input: RenderLineInput, lineContent: string, len
isInWhitespace
=
!!
currentSelection
&&
currentSelection
.
startOffset
<=
charIndex
&&
currentSelection
.
endOffset
>
charIndex
;
}
// If rendering only trailing whitespace, check that the charIndex points to trailing whitespace.
if
(
isInWhitespace
&&
onlyTrailing
)
{
isInWhitespace
=
lineIsEmptyOrWhitespace
||
charIndex
>
lastNonWhitespaceIndex
;
}
if
(
wasInWhitespace
)
{
// was in whitespace token
if
(
!
isInWhitespace
||
(
!
useMonospaceOptimizations
&&
tmpIndent
>=
tabSize
))
{
...
...
src/vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
浏览文件 @
af7765c0
...
...
@@ -869,7 +869,7 @@ suite('viewLineRenderer.renderLine', () => {
suite
(
'
viewLineRenderer.renderLine 2
'
,
()
=>
{
function
testCreateLineParts
(
fontIsMonospace
:
boolean
,
lineContent
:
string
,
tokens
:
ViewLineToken
[],
fauxIndentLength
:
number
,
renderWhitespace
:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
all
'
,
selections
:
LineRange
[]
|
null
,
expected
:
string
):
void
{
function
testCreateLineParts
(
fontIsMonospace
:
boolean
,
lineContent
:
string
,
tokens
:
ViewLineToken
[],
fauxIndentLength
:
number
,
renderWhitespace
:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
trailing
'
|
'
all
'
,
selections
:
LineRange
[]
|
null
,
expected
:
string
):
void
{
let
actual
=
renderViewLine
(
new
RenderLineInput
(
fontIsMonospace
,
true
,
...
...
@@ -1355,6 +1355,95 @@ suite('viewLineRenderer.renderLine 2', () => {
);
});
test
(
'
createLineParts render whitespace for trailing with leading, inner, and without trailing whitespace
'
,
()
=>
{
testCreateLineParts
(
false
,
'
Hello world!
'
,
[
createPart
(
4
,
0
),
createPart
(
6
,
1
),
createPart
(
14
,
2
)
],
0
,
'
trailing
'
,
null
,
[
'
<span>
'
,
'
<span class="mtk0">
\
u00a0Hel</span>
'
,
'
<span class="mtk1">lo</span>
'
,
'
<span class="mtk2">
\
u00a0world!</span>
'
,
'
</span>
'
,
].
join
(
''
)
);
});
test
(
'
createLineParts render whitespace for trailing with leading, inner, and trailing whitespace
'
,
()
=>
{
testCreateLineParts
(
false
,
'
Hello world!
\t
'
,
[
createPart
(
4
,
0
),
createPart
(
6
,
1
),
createPart
(
15
,
2
)
],
0
,
'
trailing
'
,
null
,
[
'
<span>
'
,
'
<span class="mtk0">
\
u00a0Hel</span>
'
,
'
<span class="mtk1">lo</span>
'
,
'
<span class="mtk2">
\
u00a0world!</span>
'
,
'
<span class="mtkz" style="width:30px">
\
u00b7
\
u2192
\
u00a0</span>
'
,
'
</span>
'
,
].
join
(
''
)
);
});
test
(
'
createLineParts render whitespace for trailing with 8 leading and 8 trailing whitespaces
'
,
()
=>
{
testCreateLineParts
(
false
,
'
Hello world!
'
,
[
createPart
(
8
,
1
),
createPart
(
10
,
2
),
createPart
(
28
,
3
)
],
0
,
'
trailing
'
,
null
,
[
'
<span>
'
,
'
<span class="mtk1">
\
u00a0
\
u00a0
\
u00a0
\
u00a0
\
u00a0
\
u00a0
\
u00a0
\
u00a0</span>
'
,
'
<span class="mtk2">He</span>
'
,
'
<span class="mtk3">llo
\
u00a0world!</span>
'
,
'
<span class="mtkz" style="width:40px">
\
u00b7
\
u00b7
\
u00b7
\
u00b7</span>
'
,
'
<span class="mtkz" style="width:40px">
\
u00b7
\
u00b7
\
u00b7
\
u00b7</span>
'
,
'
</span>
'
,
].
join
(
''
)
);
});
test
(
'
createLineParts render whitespace for trailing with line containing only whitespaces
'
,
()
=>
{
testCreateLineParts
(
false
,
'
\t
'
,
[
createPart
(
2
,
0
),
createPart
(
3
,
1
),
],
0
,
'
trailing
'
,
null
,
[
'
<span>
'
,
'
<span class="mtkz" style="width:40px">
\
u00b7
\
u2192
\
u00a0
\
u00a0</span>
'
,
'
<span class="mtkz" style="width:10px">
\
u00b7</span>
'
,
'
</span>
'
,
].
join
(
''
)
);
});
test
(
'
createLineParts can handle unsorted inline decorations
'
,
()
=>
{
let
actual
=
renderViewLine
(
new
RenderLineInput
(
false
,
...
...
src/vs/monaco.d.ts
浏览文件 @
af7765c0
...
...
@@ -3068,7 +3068,7 @@ declare namespace monaco.editor {
* Enable rendering of whitespace.
* Defaults to none.
*/
renderWhitespace
?:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
all
'
;
renderWhitespace
?:
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
trailing
'
|
'
all
'
;
/**
* Enable rendering of control characters.
* Defaults to false.
...
...
@@ -4048,7 +4048,7 @@ declare namespace monaco.editor {
renderLineHighlight
:
IEditorOption
<
EditorOption
.
renderLineHighlight
,
'
all
'
|
'
line
'
|
'
none
'
|
'
gutter
'
>
;
renderLineHighlightOnlyWhenFocus
:
IEditorOption
<
EditorOption
.
renderLineHighlightOnlyWhenFocus
,
boolean
>
;
renderValidationDecorations
:
IEditorOption
<
EditorOption
.
renderValidationDecorations
,
'
on
'
|
'
off
'
|
'
editable
'
>
;
renderWhitespace
:
IEditorOption
<
EditorOption
.
renderWhitespace
,
'
all
'
|
'
none
'
|
'
boundary
'
|
'
selection
'
>
;
renderWhitespace
:
IEditorOption
<
EditorOption
.
renderWhitespace
,
'
all
'
|
'
none
'
|
'
boundary
'
|
'
selection
'
|
'
trailing
'
>
;
revealHorizontalRightPadding
:
IEditorOption
<
EditorOption
.
revealHorizontalRightPadding
,
number
>
;
roundedSelection
:
IEditorOption
<
EditorOption
.
roundedSelection
,
boolean
>
;
rulers
:
IEditorOption
<
EditorOption
.
rulers
,
{}
>
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录