Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
7bcbf8d4
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,发现更多精彩内容 >>
未验证
提交
7bcbf8d4
编写于
3月 09, 2020
作者:
A
Alexandru Dima
提交者:
GitHub
3月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #92291 from microsoft/alex/validate-monospace-assumptions
Validate monospace assumptions
上级
404b5678
fadb2e6b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
93 addition
and
1 deletion
+93
-1
src/vs/editor/browser/viewParts/lines/viewLine.ts
src/vs/editor/browser/viewParts/lines/viewLine.ts
+44
-1
src/vs/editor/browser/viewParts/lines/viewLines.ts
src/vs/editor/browser/viewParts/lines/viewLines.ts
+49
-0
未找到文件。
src/vs/editor/browser/viewParts/lines/viewLine.ts
浏览文件 @
7bcbf8d4
...
...
@@ -42,6 +42,8 @@ const canUseFastRenderedViewLine = (function () {
return
true
;
})();
let
monospaceAssumptionsAreValid
=
true
;
const
alwaysRenderInlineSelection
=
(
browser
.
isEdge
);
export
class
DomReadingContext
{
...
...
@@ -248,7 +250,7 @@ export class ViewLine implements IVisibleLine {
sb
.
appendASCIIString
(
'
</div>
'
);
let
renderedViewLine
:
IRenderedViewLine
|
null
=
null
;
if
(
canUseFastRenderedViewLine
&&
lineData
.
isBasicASCII
&&
options
.
useMonospaceOptimizations
&&
output
.
containsForeignElements
===
ForeignElementType
.
None
)
{
if
(
monospaceAssumptionsAreValid
&&
canUseFastRenderedViewLine
&&
lineData
.
isBasicASCII
&&
options
.
useMonospaceOptimizations
&&
output
.
containsForeignElements
===
ForeignElementType
.
None
)
{
if
(
lineData
.
content
.
length
<
300
&&
renderLineInput
.
lineTokens
.
getCount
()
<
100
)
{
// Browser rounding errors have been observed in Chrome and IE, so using the fast
// view line only for short lines. Please test before removing the length check...
...
...
@@ -304,6 +306,29 @@ export class ViewLine implements IVisibleLine {
return
this
.
_renderedViewLine
.
getWidthIsFast
();
}
public
needsMonospaceFontCheck
():
boolean
{
if
(
!
this
.
_renderedViewLine
)
{
return
false
;
}
return
(
this
.
_renderedViewLine
instanceof
FastRenderedViewLine
);
}
public
monospaceAssumptionsAreValid
():
boolean
{
if
(
!
this
.
_renderedViewLine
)
{
return
monospaceAssumptionsAreValid
;
}
if
(
this
.
_renderedViewLine
instanceof
FastRenderedViewLine
)
{
return
this
.
_renderedViewLine
.
monospaceAssumptionsAreValid
();
}
return
monospaceAssumptionsAreValid
;
}
public
onMonospaceAssumptionsInvalidated
():
void
{
if
(
this
.
_renderedViewLine
&&
this
.
_renderedViewLine
instanceof
FastRenderedViewLine
)
{
this
.
_renderedViewLine
=
this
.
_renderedViewLine
.
toSlowRenderedLine
();
}
}
public
getVisibleRangesForRange
(
startColumn
:
number
,
endColumn
:
number
,
context
:
DomReadingContext
):
VisibleRanges
|
null
{
if
(
!
this
.
_renderedViewLine
)
{
return
null
;
...
...
@@ -382,6 +407,24 @@ class FastRenderedViewLine implements IRenderedViewLine {
return
true
;
}
public
monospaceAssumptionsAreValid
():
boolean
{
if
(
!
this
.
domNode
)
{
return
monospaceAssumptionsAreValid
;
}
const
expectedWidth
=
this
.
getWidth
();
const
actualWidth
=
(
<
HTMLSpanElement
>
this
.
domNode
.
domNode
.
firstChild
).
offsetWidth
;
if
(
Math
.
abs
(
expectedWidth
-
actualWidth
)
>=
2
)
{
// more than 2px off
console
.
warn
(
`monospace assumptions have been violated, therefore disabling monospace optimizations!`
);
monospaceAssumptionsAreValid
=
false
;
}
return
monospaceAssumptionsAreValid
;
}
public
toSlowRenderedLine
():
RenderedViewLine
{
return
createRenderedLine
(
this
.
domNode
,
this
.
input
,
this
.
_characterMapping
,
false
,
ForeignElementType
.
None
);
}
public
getVisibleRangesForRange
(
startColumn
:
number
,
endColumn
:
number
,
context
:
DomReadingContext
):
HorizontalRange
[]
|
null
{
const
startPosition
=
this
.
_getCharPosition
(
startColumn
);
const
endPosition
=
this
.
_getCharPosition
(
endColumn
);
...
...
src/vs/editor/browser/viewParts/lines/viewLines.ts
浏览文件 @
7bcbf8d4
...
...
@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
'
vs/css!./viewLines
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
{
FastDomNode
}
from
'
vs/base/browser/fastDomNode
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
Configuration
}
from
'
vs/editor/browser/config/configuration
'
;
...
...
@@ -106,6 +107,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
// --- width
private
_maxLineWidth
:
number
;
private
readonly
_asyncUpdateLineWidths
:
RunOnceScheduler
;
private
readonly
_asyncCheckMonospaceFontAssumptions
:
RunOnceScheduler
;
private
_horizontalRevealRequest
:
HorizontalRevealRequest
|
null
;
private
readonly
_lastRenderedData
:
LastRenderedData
;
...
...
@@ -140,6 +142,9 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
this
.
_asyncUpdateLineWidths
=
new
RunOnceScheduler
(()
=>
{
this
.
_updateLineWidthsSlow
();
},
200
);
this
.
_asyncCheckMonospaceFontAssumptions
=
new
RunOnceScheduler
(()
=>
{
this
.
_checkMonospaceFontAssumptions
();
},
2000
);
this
.
_lastRenderedData
=
new
LastRenderedData
();
...
...
@@ -148,6 +153,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
public
dispose
():
void
{
this
.
_asyncUpdateLineWidths
.
dispose
();
this
.
_asyncCheckMonospaceFontAssumptions
.
dispose
();
super
.
dispose
();
}
...
...
@@ -513,6 +519,37 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
return
allWidthsComputed
;
}
private
_checkMonospaceFontAssumptions
():
void
{
// Problems with monospace assumptions are more apparent for longer lines,
// as small rounding errors start to sum up, so we will select the longest
// line for a closer inspection
let
longestLineNumber
=
-
1
;
let
longestWidth
=
-
1
;
const
rendStartLineNumber
=
this
.
_visibleLines
.
getStartLineNumber
();
const
rendEndLineNumber
=
this
.
_visibleLines
.
getEndLineNumber
();
for
(
let
lineNumber
=
rendStartLineNumber
;
lineNumber
<=
rendEndLineNumber
;
lineNumber
++
)
{
const
visibleLine
=
this
.
_visibleLines
.
getVisibleLine
(
lineNumber
);
if
(
visibleLine
.
needsMonospaceFontCheck
())
{
const
lineWidth
=
visibleLine
.
getWidth
();
if
(
lineWidth
>
longestWidth
)
{
longestWidth
=
lineWidth
;
longestLineNumber
=
lineNumber
;
}
}
}
if
(
longestLineNumber
===
-
1
)
{
return
;
}
if
(
!
this
.
_visibleLines
.
getVisibleLine
(
longestLineNumber
).
monospaceAssumptionsAreValid
())
{
for
(
let
lineNumber
=
rendStartLineNumber
;
lineNumber
<=
rendEndLineNumber
;
lineNumber
++
)
{
const
visibleLine
=
this
.
_visibleLines
.
getVisibleLine
(
lineNumber
);
visibleLine
.
onMonospaceAssumptionsInvalidated
();
}
}
}
public
prepareRender
():
void
{
throw
new
Error
(
'
Not supported
'
);
}
...
...
@@ -571,6 +608,18 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
this
.
_asyncUpdateLineWidths
.
schedule
();
}
if
(
platform
.
isLinux
&&
!
this
.
_asyncCheckMonospaceFontAssumptions
.
isScheduled
())
{
const
rendStartLineNumber
=
this
.
_visibleLines
.
getStartLineNumber
();
const
rendEndLineNumber
=
this
.
_visibleLines
.
getEndLineNumber
();
for
(
let
lineNumber
=
rendStartLineNumber
;
lineNumber
<=
rendEndLineNumber
;
lineNumber
++
)
{
const
visibleLine
=
this
.
_visibleLines
.
getVisibleLine
(
lineNumber
);
if
(
visibleLine
.
needsMonospaceFontCheck
())
{
this
.
_asyncCheckMonospaceFontAssumptions
.
schedule
();
break
;
}
}
}
// (3) handle scrolling
this
.
_linesContent
.
setLayerHinting
(
this
.
_canUseLayerHinting
);
this
.
_linesContent
.
setContain
(
'
strict
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录