Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
c6dec6ef
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,发现更多精彩内容 >>
未验证
提交
c6dec6ef
编写于
1月 13, 2020
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for WrappingIndent.Same in DOMLineBreaksComputer
上级
02d39920
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
95 addition
and
21 deletion
+95
-21
src/vs/editor/browser/view/domLineBreaksComputer.ts
src/vs/editor/browser/view/domLineBreaksComputer.ts
+95
-21
未找到文件。
src/vs/editor/browser/view/domLineBreaksComputer.ts
浏览文件 @
c6dec6ef
...
@@ -36,26 +36,82 @@ export class DOMLineBreaksComputerFactory implements ILineBreaksComputerFactory
...
@@ -36,26 +36,82 @@ export class DOMLineBreaksComputerFactory implements ILineBreaksComputerFactory
requests
.
push
(
lineText
);
requests
.
push
(
lineText
);
},
},
finalize
:
()
=>
{
finalize
:
()
=>
{
return
createLineBreaks
(
this
.
_fontInfo
,
tabSize
,
wrappingColumn
,
wrappingIndent
,
requests
);
return
createLineBreaks
(
requests
,
this
.
_fontInfo
,
tabSize
,
wrappingColumn
,
wrappingIndent
);
}
}
};
};
}
}
}
}
function
createLineBreaks
(
fontInfo
:
FontInfo
,
tabSize
:
number
,
firstLineBreakColumn
:
number
,
wrappingIndent
:
WrappingIndent
,
requests
:
string
[]):
(
LineBreakData
|
null
)[]
{
function
createLineBreaks
(
requests
:
string
[],
fontInfo
:
FontInfo
,
tabSize
:
number
,
firstLineBreakColumn
:
number
,
wrappingIndent
:
WrappingIndent
):
(
LineBreakData
|
null
)[]
{
const
width
=
Math
.
round
(
firstLineBreakColumn
*
fontInfo
.
typicalHalfwidthCharacterWidth
);
if
(
firstLineBreakColumn
===
-
1
)
{
const
result
:
null
[]
=
[];
for
(
let
i
=
0
,
len
=
requests
.
length
;
i
<
len
;
i
++
)
{
result
[
i
]
=
null
;
}
return
result
;
}
const
overallWidth
=
Math
.
round
(
firstLineBreakColumn
*
fontInfo
.
typicalHalfwidthCharacterWidth
);
// Cannot respect WrappingIndent.Indent and WrappingIndent.DeepIndent because that would require
// two dom layouts, in order to first set the width of the first line, and then set the width of the wrapped lines
if
(
wrappingIndent
===
WrappingIndent
.
Indent
||
wrappingIndent
===
WrappingIndent
.
DeepIndent
)
{
wrappingIndent
=
WrappingIndent
.
Same
;
}
const
containerDomNode
=
document
.
createElement
(
'
div
'
);
const
containerDomNode
=
document
.
createElement
(
'
div
'
);
Configuration
.
applyFontInfoSlow
(
containerDomNode
,
fontInfo
);
Configuration
.
applyFontInfoSlow
(
containerDomNode
,
fontInfo
);
containerDomNode
.
style
.
width
=
`
${
width
}
px`
;
const
sb
=
createStringBuilder
(
10000
);
const
sb
=
createStringBuilder
(
10000
);
const
charOffsets
:
number
[][]
=
[];
const
firstNonWhitespaceIndices
:
number
[]
=
[];
const
visibleColumns
:
number
[][]
=
[];
const
wrappedTextIndentLengths
:
number
[]
=
[];
const
renderLineContents
:
string
[]
=
[];
const
allCharOffsets
:
number
[][]
=
[];
const
allVisibleColumns
:
number
[][]
=
[];
for
(
let
i
=
0
;
i
<
requests
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
requests
.
length
;
i
++
)
{
const
r
=
renderLine
(
i
,
requests
[
i
],
tabSize
,
sb
);
const
lineContent
=
requests
[
i
];
charOffsets
[
i
]
=
r
[
0
];
visibleColumns
[
i
]
=
r
[
1
];
let
firstNonWhitespaceIndex
=
0
;
let
wrappedTextIndentLength
=
0
;
let
width
=
overallWidth
;
if
(
wrappingIndent
!==
WrappingIndent
.
None
)
{
firstNonWhitespaceIndex
=
strings
.
firstNonWhitespaceIndex
(
lineContent
);
if
(
firstNonWhitespaceIndex
===
-
1
)
{
// all whitespace line
firstNonWhitespaceIndex
=
0
;
}
else
{
// Track existing indent
for
(
let
i
=
0
;
i
<
firstNonWhitespaceIndex
;
i
++
)
{
const
charWidth
=
(
lineContent
.
charCodeAt
(
i
)
===
CharCode
.
Tab
?
(
tabSize
-
(
wrappedTextIndentLength
%
tabSize
))
:
1
);
wrappedTextIndentLength
+=
charWidth
;
}
const
indentWidth
=
Math
.
ceil
(
fontInfo
.
spaceWidth
*
wrappedTextIndentLength
);
// Force sticking to beginning of line if no character would fit except for the indentation
if
(
indentWidth
+
fontInfo
.
typicalFullwidthCharacterWidth
>
overallWidth
)
{
firstNonWhitespaceIndex
=
0
;
wrappedTextIndentLength
=
0
;
}
else
{
width
=
overallWidth
-
indentWidth
;
}
}
}
const
renderLineContent
=
lineContent
.
substr
(
firstNonWhitespaceIndex
);
const
tmp
=
renderLine
(
renderLineContent
,
wrappedTextIndentLength
,
tabSize
,
width
,
sb
);
firstNonWhitespaceIndices
[
i
]
=
firstNonWhitespaceIndex
;
wrappedTextIndentLengths
[
i
]
=
wrappedTextIndentLength
;
renderLineContents
[
i
]
=
renderLineContent
;
allCharOffsets
[
i
]
=
tmp
[
0
];
allVisibleColumns
[
i
]
=
tmp
[
1
];
}
}
containerDomNode
.
innerHTML
=
sb
.
build
();
containerDomNode
.
innerHTML
=
sb
.
build
();
...
@@ -71,21 +127,45 @@ function createLineBreaks(fontInfo: FontInfo, tabSize: number, firstLineBreakCol
...
@@ -71,21 +127,45 @@ function createLineBreaks(fontInfo: FontInfo, tabSize: number, firstLineBreakCol
let
result
:
(
LineBreakData
|
null
)[]
=
[];
let
result
:
(
LineBreakData
|
null
)[]
=
[];
for
(
let
i
=
0
;
i
<
requests
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
requests
.
length
;
i
++
)
{
const
lineDomNode
=
lineDomNodes
[
i
];
const
lineDomNode
=
lineDomNodes
[
i
];
result
[
i
]
=
readLineBreaks
(
range
,
lineDomNode
,
requests
[
i
],
charOffsets
[
i
],
visibleColumns
[
i
]);
const
breakOffsets
:
number
[]
|
null
=
readLineBreaks
(
range
,
lineDomNode
,
renderLineContents
[
i
],
allCharOffsets
[
i
]);
if
(
breakOffsets
===
null
)
{
result
[
i
]
=
null
;
continue
;
}
const
firstNonWhitespaceIndex
=
firstNonWhitespaceIndices
[
i
];
const
wrappedTextIndentLength
=
wrappedTextIndentLengths
[
i
];
const
visibleColumns
=
allVisibleColumns
[
i
];
const
breakOffsetsVisibleColumn
:
number
[]
=
[];
for
(
let
j
=
0
,
len
=
breakOffsets
.
length
;
j
<
len
;
j
++
)
{
breakOffsetsVisibleColumn
[
j
]
=
visibleColumns
[
breakOffsets
[
j
]];
}
if
(
firstNonWhitespaceIndex
!==
0
)
{
// All break offsets are relative to the renderLineContent, make them absolute again
for
(
let
j
=
0
,
len
=
breakOffsets
.
length
;
j
<
len
;
j
++
)
{
breakOffsets
[
j
]
+=
firstNonWhitespaceIndex
;
}
}
result
[
i
]
=
new
LineBreakData
(
breakOffsets
,
breakOffsetsVisibleColumn
,
wrappedTextIndentLength
);
}
}
document
.
body
.
removeChild
(
containerDomNode
);
document
.
body
.
removeChild
(
containerDomNode
);
return
result
;
return
result
;
}
}
function
renderLine
(
lineIndex
:
number
,
lineContent
:
string
,
tabSize
:
number
,
sb
:
IStringBuilder
):
[
number
[],
number
[]]
{
function
renderLine
(
lineContent
:
string
,
initialVisibleColumn
:
number
,
tabSize
:
number
,
width
:
number
,
sb
:
IStringBuilder
):
[
number
[],
number
[]]
{
sb
.
appendASCIIString
(
'
<div>
'
);
sb
.
appendASCIIString
(
'
<div style="width:
'
);
sb
.
appendASCIIString
(
String
(
width
));
sb
.
appendASCIIString
(
'
px;">
'
);
// if (containsRTL) {
// if (containsRTL) {
// sb.appendASCIIString('" dir="ltr');
// sb.appendASCIIString('" dir="ltr');
// }
// }
const
len
=
lineContent
.
length
;
const
len
=
lineContent
.
length
;
let
visibleColumn
=
0
;
let
visibleColumn
=
initialVisibleColumn
;
let
charOffset
=
0
;
let
charOffset
=
0
;
let
charOffsets
:
number
[]
=
[];
let
charOffsets
:
number
[]
=
[];
let
visibleColumns
:
number
[]
=
[];
let
visibleColumns
:
number
[]
=
[];
...
@@ -163,7 +243,7 @@ function renderLine(lineIndex: number, lineContent: string, tabSize: number, sb:
...
@@ -163,7 +243,7 @@ function renderLine(lineIndex: number, lineContent: string, tabSize: number, sb:
return
[
charOffsets
,
visibleColumns
];
return
[
charOffsets
,
visibleColumns
];
}
}
function
readLineBreaks
(
range
:
Range
,
lineDomNode
:
HTMLDivElement
,
lineContent
:
string
,
charOffsets
:
number
[]
,
visibleColumns
:
number
[]):
LineBreakData
|
null
{
function
readLineBreaks
(
range
:
Range
,
lineDomNode
:
HTMLDivElement
,
lineContent
:
string
,
charOffsets
:
number
[]
):
number
[]
|
null
{
if
(
lineContent
.
length
<=
1
)
{
if
(
lineContent
.
length
<=
1
)
{
return
null
;
return
null
;
}
}
...
@@ -177,13 +257,7 @@ function readLineBreaks(range: Range, lineDomNode: HTMLDivElement, lineContent:
...
@@ -177,13 +257,7 @@ function readLineBreaks(range: Range, lineDomNode: HTMLDivElement, lineContent:
}
}
breakOffsets
.
push
(
lineContent
.
length
);
breakOffsets
.
push
(
lineContent
.
length
);
return
breakOffsets
;
const
breakOffsetsVisibleColumn
=
[];
for
(
let
i
=
0
,
len
=
breakOffsets
.
length
;
i
<
len
;
i
++
)
{
breakOffsetsVisibleColumn
[
i
]
=
visibleColumns
[
breakOffsets
[
i
]];
}
return
new
LineBreakData
(
breakOffsets
,
breakOffsetsVisibleColumn
,
0
);
}
}
type
MaybeRects
=
ClientRectList
|
DOMRectList
|
null
;
type
MaybeRects
=
ClientRectList
|
DOMRectList
|
null
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录