Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d59c4d02
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d59c4d02
编写于
4月 26, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #95686: Ensure the break offset is always increasing
上级
78b071d8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
13 deletion
+38
-13
src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts
...vs/editor/common/viewModel/monospaceLineBreaksComputer.ts
+26
-12
src/vs/editor/test/common/viewModel/monospaceLineBreaksComputer.test.ts
...test/common/viewModel/monospaceLineBreaksComputer.test.ts
+12
-1
未找到文件。
src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts
浏览文件 @
d59c4d02
...
...
@@ -119,6 +119,8 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
let
breakingOffsets
:
number
[]
=
arrPool1
;
let
breakingOffsetsVisibleColumn
:
number
[]
=
arrPool2
;
let
breakingOffsetsCount
:
number
=
0
;
let
lastBreakingOffset
=
0
;
let
lastBreakingOffsetVisibleColumn
=
0
;
let
breakingColumn
=
firstLineBreakColumn
;
const
prevLen
=
prevBreakingOffsets
.
length
;
...
...
@@ -138,8 +140,12 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
while
(
prevIndex
<
prevLen
)
{
// Allow for prevIndex to be -1 (for the case where we hit a tab when walking backwards from the first break)
const
prevBreakOffset
=
prevIndex
<
0
?
0
:
prevBreakingOffsets
[
prevIndex
];
const
prevBreakoffsetVisibleColumn
=
prevIndex
<
0
?
0
:
prevBreakingOffsetsVisibleColumn
[
prevIndex
];
let
prevBreakOffset
=
prevIndex
<
0
?
0
:
prevBreakingOffsets
[
prevIndex
];
let
prevBreakOffsetVisibleColumn
=
prevIndex
<
0
?
0
:
prevBreakingOffsetsVisibleColumn
[
prevIndex
];
if
(
lastBreakingOffset
>
prevBreakOffset
)
{
prevBreakOffset
=
lastBreakingOffset
;
prevBreakOffsetVisibleColumn
=
lastBreakingOffsetVisibleColumn
;
}
let
breakOffset
=
0
;
let
breakOffsetVisibleColumn
=
0
;
...
...
@@ -148,10 +154,10 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
let
forcedBreakOffsetVisibleColumn
=
0
;
// initially, we search as much as possible to the right (if it fits)
if
(
prevBreak
o
ffsetVisibleColumn
<=
breakingColumn
)
{
let
visibleColumn
=
prevBreak
o
ffsetVisibleColumn
;
let
prevCharCode
=
lineText
.
charCodeAt
(
prevBreakOffset
-
1
);
let
prevCharCodeClass
=
classifier
.
get
(
prevCharCode
);
if
(
prevBreak
O
ffsetVisibleColumn
<=
breakingColumn
)
{
let
visibleColumn
=
prevBreak
O
ffsetVisibleColumn
;
let
prevCharCode
=
prevBreakOffset
===
0
?
CharCode
.
Null
:
lineText
.
charCodeAt
(
prevBreakOffset
-
1
);
let
prevCharCodeClass
=
prevBreakOffset
===
0
?
CharacterClass
.
NONE
:
classifier
.
get
(
prevCharCode
);
let
entireLineFits
=
true
;
for
(
let
i
=
prevBreakOffset
;
i
<
len
;
i
++
)
{
const
charStartOffset
=
i
;
...
...
@@ -169,7 +175,7 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
charWidth
=
computeCharWidth
(
charCode
,
visibleColumn
,
tabSize
,
columnsForFullWidthChar
);
}
if
(
canBreak
(
prevCharCode
,
prevCharCodeClass
,
charCode
,
charCodeClass
))
{
if
(
c
harStartOffset
>
lastBreakingOffset
&&
c
anBreak
(
prevCharCode
,
prevCharCodeClass
,
charCode
,
charCodeClass
))
{
breakOffset
=
charStartOffset
;
breakOffsetVisibleColumn
=
visibleColumn
;
}
...
...
@@ -179,8 +185,14 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
// check if adding character at `i` will go over the breaking column
if
(
visibleColumn
>
breakingColumn
)
{
// We need to break at least before character at `i`:
forcedBreakOffset
=
charStartOffset
;
forcedBreakOffsetVisibleColumn
=
visibleColumn
-
charWidth
;
if
(
charStartOffset
>
lastBreakingOffset
)
{
forcedBreakOffset
=
charStartOffset
;
forcedBreakOffsetVisibleColumn
=
visibleColumn
-
charWidth
;
}
else
{
// we need to advance at least by one character
forcedBreakOffset
=
i
+
1
;
forcedBreakOffsetVisibleColumn
=
visibleColumn
;
}
if
(
visibleColumn
-
breakOffsetVisibleColumn
>
wrappedLineBreakColumn
)
{
// Cannot break at `breakOffset` => reset it if it was set
...
...
@@ -198,7 +210,7 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
if
(
entireLineFits
)
{
// there is no more need to break => stop the outer loop!
if
(
breakingOffsetsCount
>
0
)
{
// Add last segment
// Add last segment
, no need to assign to `lastBreakingOffset` and `lastBreakingOffsetVisibleColumn`
breakingOffsets
[
breakingOffsetsCount
]
=
prevBreakingOffsets
[
prevBreakingOffsets
.
length
-
1
];
breakingOffsetsVisibleColumn
[
breakingOffsetsCount
]
=
prevBreakingOffsetsVisibleColumn
[
prevBreakingOffsets
.
length
-
1
];
breakingOffsetsCount
++
;
...
...
@@ -209,11 +221,11 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
if
(
breakOffset
===
0
)
{
// must search left
let
visibleColumn
=
prevBreak
o
ffsetVisibleColumn
;
let
visibleColumn
=
prevBreak
O
ffsetVisibleColumn
;
let
charCode
=
lineText
.
charCodeAt
(
prevBreakOffset
);
let
charCodeClass
=
classifier
.
get
(
charCode
);
let
hitATabCharacter
=
false
;
for
(
let
i
=
prevBreakOffset
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
prevBreakOffset
-
1
;
i
>=
lastBreakingOffset
;
i
--
)
{
const
charStartOffset
=
i
+
1
;
const
prevCharCode
=
lineText
.
charCodeAt
(
i
);
...
...
@@ -290,7 +302,9 @@ function createLineBreaksFromPreviousLineBreaks(classifier: WrappingCharacterCla
breakOffsetVisibleColumn
=
forcedBreakOffsetVisibleColumn
;
}
lastBreakingOffset
=
breakOffset
;
breakingOffsets
[
breakingOffsetsCount
]
=
breakOffset
;
lastBreakingOffsetVisibleColumn
=
breakOffsetVisibleColumn
;
breakingOffsetsVisibleColumn
[
breakingOffsetsCount
]
=
breakOffsetVisibleColumn
;
breakingOffsetsCount
++
;
breakingColumn
=
breakOffsetVisibleColumn
+
wrappedLineBreakColumn
;
...
...
src/vs/editor/test/common/viewModel/monospaceLineBreaksComputer.test.ts
浏览文件 @
d59c4d02
...
...
@@ -147,7 +147,7 @@ suite('Editor ViewModel - MonospaceLineBreaksComputer', () => {
test
(
'
MonospaceLineBreaksComputer incremental 1
'
,
()
=>
{
le
t
factory
=
new
MonospaceLineBreaksComputerFactory
(
EditorOptions
.
wordWrapBreakBeforeCharacters
.
defaultValue
,
EditorOptions
.
wordWrapBreakAfterCharacters
.
defaultValue
);
cons
t
factory
=
new
MonospaceLineBreaksComputerFactory
(
EditorOptions
.
wordWrapBreakBeforeCharacters
.
defaultValue
,
EditorOptions
.
wordWrapBreakAfterCharacters
.
defaultValue
);
assertIncrementalLineBreaks
(
factory
,
'
just some text and more
'
,
4
,
...
...
@@ -203,6 +203,17 @@ suite('Editor ViewModel - MonospaceLineBreaksComputer', () => {
);
});
test
(
'
issue #95686: CRITICAL: loop forever on the monospaceLineBreaksComputer
'
,
()
=>
{
const
factory
=
new
MonospaceLineBreaksComputerFactory
(
EditorOptions
.
wordWrapBreakBeforeCharacters
.
defaultValue
,
EditorOptions
.
wordWrapBreakAfterCharacters
.
defaultValue
);
assertIncrementalLineBreaks
(
factory
,
'
<tr dmx-class:table-danger="(alt <= 50)" dmx-class:table-warning="(alt <= 200)" dmx-class:table-primary="(alt <= 400)" dmx-class:table-info="(alt <= 800)" dmx-class:table-success="(alt >= 400)">
'
,
4
,
179
,
'
<tr dmx-class:table-danger="(alt <= 50)" dmx-class:table-warning="(alt <= 200)" dmx-class:table-primary="(alt <= 400)" dmx-class:table-info="(alt <= 800)" |dmx-class:table-success="(alt >= 400)">
'
,
1
,
'
| | | | | |<|t|r| |d|m|x|-|c|l|a|s|s|:|t|a|b|l|e|-|d|a|n|g|e|r|=|"|(|a|l|t| |<|=| |5|0|)|"| |d|m|x|-|c|l|a|s|s|:|t|a|b|l|e|-|w|a|r|n|i|n|g|=|"|(|a|l|t| |<|=| |2|0|0|)|"| |d|m|x|-|c|l|a|s|s|:|t|a|b|l|e|-|p|r|i|m|a|r|y|=|"|(|a|l|t| |<|=| |4|0|0|)|"| |d|m|x|-|c|l|a|s|s|:|t|a|b|l|e|-|i|n|f|o|=|"|(|a|l|t| |<|=| |8|0|0|)|"| |d|m|x|-|c|l|a|s|s|:|t|a|b|l|e|-|s|u|c|c|e|s|s|=|"|(|a|l|t| |>|=| |4|0|0|)|"|>
'
,
WrappingIndent
.
Same
);
});
test
(
'
MonospaceLineBreaksComputer - CJK and Kinsoku Shori
'
,
()
=>
{
let
factory
=
new
MonospaceLineBreaksComputerFactory
(
'
(
'
,
'
\t
)
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录