Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
3b8f8a3b
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,发现更多精彩内容 >>
提交
3b8f8a3b
编写于
5月 08, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify editor configuration
上级
e31a5085
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
79 addition
and
92 deletion
+79
-92
src/vs/editor/browser/config/configuration.ts
src/vs/editor/browser/config/configuration.ts
+19
-31
src/vs/editor/browser/config/elementSizeObserver.ts
src/vs/editor/browser/config/elementSizeObserver.ts
+1
-2
src/vs/editor/common/config/commonEditorConfig.ts
src/vs/editor/common/config/commonEditorConfig.ts
+38
-34
src/vs/editor/test/common/config/commonEditorConfig.test.ts
src/vs/editor/test/common/config/commonEditorConfig.test.ts
+10
-2
src/vs/editor/test/common/mocks/testConfiguration.ts
src/vs/editor/test/common/mocks/testConfiguration.ts
+11
-23
未找到文件。
src/vs/editor/browser/config/configuration.ts
浏览文件 @
3b8f8a3b
...
...
@@ -8,7 +8,7 @@ import Event, { Emitter } from 'vs/base/common/event';
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
*
as
browser
from
'
vs/base/browser/browser
'
;
import
{
CommonEditorConfiguration
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
import
{
CommonEditorConfiguration
,
IEnvConfiguration
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
import
{
IDimension
}
from
'
vs/editor/common/editorCommon
'
;
import
{
FontInfo
,
BareFontInfo
}
from
'
vs/editor/common/config/fontInfo
'
;
import
{
ElementSizeObserver
}
from
'
vs/editor/browser/config/elementSizeObserver
'
;
...
...
@@ -309,8 +309,12 @@ export class Configuration extends CommonEditorConfiguration {
domNode
.
setLineHeight
(
fontInfo
.
lineHeight
);
}
private
readonly
_elementSizeObserver
:
ElementSizeObserver
;
constructor
(
options
:
IEditorOptions
,
referenceDomElement
:
HTMLElement
=
null
)
{
super
(
options
,
new
ElementSizeObserver
(
referenceDomElement
,
()
=>
this
.
_onReferenceDomElementSizeChanged
()));
super
(
options
);
this
.
_elementSizeObserver
=
this
.
_register
(
new
ElementSizeObserver
(
referenceDomElement
,
()
=>
this
.
_onReferenceDomElementSizeChanged
()));
this
.
_register
(
CSSBasedConfiguration
.
INSTANCE
.
onDidChange
(()
=>
this
.
_onCSSBasedConfigurationChanged
()));
...
...
@@ -319,6 +323,8 @@ export class Configuration extends CommonEditorConfiguration {
}
this
.
_register
(
browser
.
onDidChangeZoomLevel
(
_
=>
this
.
_recomputeOptions
()));
this
.
_recomputeOptions
();
}
private
_onReferenceDomElementSizeChanged
():
void
{
...
...
@@ -334,11 +340,10 @@ export class Configuration extends CommonEditorConfiguration {
}
public
dispose
():
void
{
this
.
_elementSizeObserver
.
dispose
();
super
.
dispose
();
}
pr
otected
_getEditorClassName
(
theme
:
string
,
fontLigatures
:
boolean
,
mouseStyle
:
'
text
'
|
'
default
'
|
'
copy
'
):
string
{
pr
ivate
_getExtraEditorClassName
(
):
string
{
let
extra
=
''
;
if
(
browser
.
isIE
)
{
extra
+=
'
ie
'
;
...
...
@@ -350,38 +355,21 @@ export class Configuration extends CommonEditorConfiguration {
if
(
platform
.
isMacintosh
)
{
extra
+=
'
mac
'
;
}
if
(
fontLigatures
)
{
extra
+=
'
enable-ligatures
'
;
}
if
(
mouseStyle
===
'
default
'
)
{
extra
+=
'
mouse-default
'
;
}
else
if
(
mouseStyle
===
'
copy
'
)
{
extra
+=
'
mouse-copy
'
;
}
return
'
monaco-editor
'
+
extra
+
theme
;
}
protected
getOuterWidth
():
number
{
return
this
.
_elementSizeObserver
.
getWidth
();
}
protected
getOuterHeight
():
number
{
return
this
.
_elementSizeObserver
.
getHeight
();
return
extra
;
}
protected
_getCanUseTranslate3d
():
boolean
{
return
browser
.
canUseTranslate3d
();
}
protected
_getPixelRatio
():
number
{
return
browser
.
getPixelRatio
();
protected
_getEnvConfiguration
():
IEnvConfiguration
{
return
{
extraEditorClassName
:
this
.
_getExtraEditorClassName
(),
outerWidth
:
this
.
_elementSizeObserver
.
getWidth
(),
outerHeight
:
this
.
_elementSizeObserver
.
getHeight
(),
canUseTranslate3d
:
browser
.
canUseTranslate3d
(),
pixelRatio
:
browser
.
getPixelRatio
(),
zoomLevel
:
browser
.
getZoomLevel
()
};
}
protected
readConfiguration
(
bareFontInfo
:
BareFontInfo
):
FontInfo
{
return
CSSBasedConfiguration
.
INSTANCE
.
readConfiguration
(
bareFontInfo
);
}
protected
getZoomLevel
():
number
{
return
browser
.
getZoomLevel
();
}
}
src/vs/editor/browser/config/elementSizeObserver.ts
浏览文件 @
3b8f8a3b
...
...
@@ -6,9 +6,8 @@
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDimension
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IElementSizeObserver
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
export
class
ElementSizeObserver
extends
Disposable
implements
IElementSizeObserver
{
export
class
ElementSizeObserver
extends
Disposable
{
private
referenceDomElement
:
HTMLElement
;
private
measureReferenceDomElementToken
:
number
;
...
...
src/vs/editor/common/config/commonEditorConfig.ts
浏览文件 @
3b8f8a3b
...
...
@@ -51,38 +51,35 @@ export const TabFocus: ITabFocus = new class {
}
};
export
interface
IElementSizeObserver
{
startObserving
():
void
;
observe
(
dimension
?:
editorCommon
.
IDimension
):
void
;
dispose
():
void
;
getWidth
():
number
;
getHeight
():
number
;
export
interface
IEnvConfiguration
{
extraEditorClassName
:
string
;
outerWidth
:
number
;
outerHeight
:
number
;
canUseTranslate3d
:
boolean
;
pixelRatio
:
number
;
zoomLevel
:
number
;
}
export
abstract
class
CommonEditorConfiguration
extends
Disposable
implements
editorCommon
.
IConfiguration
{
protected
_rawOptions
:
editorOptions
.
IEditorOptions
;
protected
_validatedOptions
:
editorOptions
.
IValidatedEditorOptions
;
public
editor
:
editorOptions
.
InternalEditorOptions
;
protected
_elementSizeObserver
:
IElementSizeObserver
;
private
_isDominatedByLongLines
:
boolean
;
private
_lineNumbersDigitCount
:
number
;
private
_onDidChange
=
this
.
_register
(
new
Emitter
<
editorOptions
.
IConfigurationChangedEvent
>
());
public
onDidChange
:
Event
<
editorOptions
.
IConfigurationChangedEvent
>
=
this
.
_onDidChange
.
event
;
constructor
(
options
:
editorOptions
.
IEditorOptions
,
elementSizeObserver
:
IElementSizeObserver
=
null
)
{
constructor
(
options
:
editorOptions
.
IEditorOptions
)
{
super
();
this
.
_rawOptions
=
options
||
{};
this
.
_validatedOptions
=
editorOptions
.
EditorOptionsValidator
.
validate
(
this
.
_rawOptions
,
EDITOR_DEFAULTS
);
this
.
_elementSizeObserver
=
elementSizeObserver
;
this
.
editor
=
null
;
this
.
_isDominatedByLongLines
=
false
;
this
.
_lineNumbersDigitCount
=
1
;
this
.
editor
=
this
.
_computeInternalOptions
();
this
.
_register
(
EditorZoom
.
onDidChangeZoomLevel
(
_
=>
this
.
_recomputeOptions
()));
this
.
_register
(
TabFocus
.
onDidChangeTabFocus
(
_
=>
this
.
_recomputeOptions
()));
}
...
...
@@ -92,17 +89,18 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
}
protected
_recomputeOptions
():
void
{
this
.
_setOptions
(
this
.
_computeInternalOptions
())
;
}
const
oldOptions
=
this
.
editor
;
const
newOptions
=
this
.
_computeInternalOptions
();
private
_setOptions
(
newOptions
:
editorOptions
.
InternalEditorOptions
):
void
{
if
(
this
.
editor
&&
this
.
editor
.
equals
(
newOptions
))
{
if
(
oldOptions
&&
oldOptions
.
equals
(
newOptions
))
{
return
;
}
let
changeEvent
=
this
.
editor
.
createChangeEvent
(
newOptions
);
this
.
editor
=
newOptions
;
this
.
_onDidChange
.
fire
(
changeEvent
);
if
(
oldOptions
)
{
this
.
_onDidChange
.
fire
(
oldOptions
.
createChangeEvent
(
newOptions
));
}
}
public
getRawOptions
():
editorOptions
.
IEditorOptions
{
...
...
@@ -111,16 +109,18 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
private
_computeInternalOptions
():
editorOptions
.
InternalEditorOptions
{
const
opts
=
this
.
_validatedOptions
;
const
bareFontInfo
=
BareFontInfo
.
createFromRawSettings
(
this
.
_rawOptions
,
this
.
getZoomLevel
());
const
partialEnv
=
this
.
_getEnvConfiguration
();
const
bareFontInfo
=
BareFontInfo
.
createFromRawSettings
(
this
.
_rawOptions
,
partialEnv
.
zoomLevel
);
const
editorClassName
=
this
.
_getEditorClassName
(
opts
.
viewInfo
.
theme
,
opts
.
viewInfo
.
fontLigatures
,
opts
.
mouseStyle
);
const
env
:
editorOptions
.
IEnvironmentalOptions
=
{
outerWidth
:
this
.
getOuterWidth
()
,
outerHeight
:
this
.
getOuterHeight
()
,
outerWidth
:
partialEnv
.
outerWidth
,
outerHeight
:
partialEnv
.
outerHeight
,
fontInfo
:
this
.
readConfiguration
(
bareFontInfo
),
editorClassName
:
this
.
_getEditorClassName
(
opts
.
viewInfo
.
theme
,
opts
.
viewInfo
.
fontLigatures
,
opts
.
mouseStyle
)
,
editorClassName
:
editorClassName
+
'
'
+
partialEnv
.
extraEditorClassName
,
isDominatedByLongLines
:
this
.
_isDominatedByLongLines
,
lineNumbersDigitCount
:
this
.
_lineNumbersDigitCount
,
canUseTranslate3d
:
this
.
_getCanUseTranslate3d
()
,
pixelRatio
:
this
.
_getPixelRatio
()
,
canUseTranslate3d
:
partialEnv
.
canUseTranslate3d
,
pixelRatio
:
partialEnv
.
pixelRatio
,
tabFocusMode
:
TabFocus
.
getTabFocusMode
()
};
return
editorOptions
.
InternalEditorOptionsFactory
.
createInternalEditorOptions
(
env
,
opts
);
...
...
@@ -155,19 +155,23 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
return
r
?
r
:
1
;
}
protected
abstract
_getEditorClassName
(
theme
:
string
,
fontLigatures
:
boolean
,
mouseDrag
:
'
text
'
|
'
default
'
|
'
copy
'
):
string
;
protected
abstract
getOuterWidth
():
number
;
protected
abstract
getOuterHeight
():
number
;
protected
abstract
_getCanUseTranslate3d
():
boolean
;
private
_getEditorClassName
(
theme
:
string
,
fontLigatures
:
boolean
,
mouseStyle
:
'
text
'
|
'
default
'
|
'
copy
'
):
string
{
let
extra
=
''
;
if
(
fontLigatures
)
{
extra
+=
'
enable-ligatures
'
;
}
if
(
mouseStyle
===
'
default
'
)
{
extra
+=
'
mouse-default
'
;
}
else
if
(
mouseStyle
===
'
copy
'
)
{
extra
+=
'
mouse-copy
'
;
}
return
'
monaco-editor
'
+
extra
+
theme
;
}
protected
abstract
_get
PixelRatio
():
number
;
protected
abstract
_get
EnvConfiguration
():
IEnvConfiguration
;
protected
abstract
readConfiguration
(
styling
:
BareFontInfo
):
FontInfo
;
protected
abstract
getZoomLevel
():
number
;
}
const
configurationRegistry
=
<
IConfigurationRegistry
>
Registry
.
as
(
Extensions
.
Configuration
);
...
...
src/vs/editor/test/common/config/commonEditorConfig.test.ts
浏览文件 @
3b8f8a3b
...
...
@@ -7,6 +7,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
EditorZoom
}
from
'
vs/editor/common/config/editorZoom
'
;
import
{
TestConfiguration
}
from
'
vs/editor/test/common/mocks/testConfiguration
'
;
import
{
IEnvConfiguration
}
from
"
vs/editor/common/config/commonEditorConfig
"
;
suite
(
'
Common Editor Config
'
,
()
=>
{
test
(
'
Zoom Level
'
,
()
=>
{
...
...
@@ -52,8 +53,15 @@ suite('Common Editor Config', () => {
});
class
TestWrappingConfiguration
extends
TestConfiguration
{
protected
getOuterWidth
():
number
{
return
1000
;
protected
_getEnvConfiguration
():
IEnvConfiguration
{
return
{
extraEditorClassName
:
''
,
outerWidth
:
1000
,
outerHeight
:
100
,
canUseTranslate3d
:
true
,
pixelRatio
:
1
,
zoomLevel
:
0
};
}
}
...
...
src/vs/editor/test/common/mocks/testConfiguration.ts
浏览文件 @
3b8f8a3b
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
CommonEditorConfiguration
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
import
{
CommonEditorConfiguration
,
IEnvConfiguration
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
import
{
IEditorOptions
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
FontInfo
,
BareFontInfo
}
from
'
vs/editor/common/config/fontInfo
'
;
...
...
@@ -12,26 +12,18 @@ export class TestConfiguration extends CommonEditorConfiguration {
constructor
(
opts
:
IEditorOptions
)
{
super
(
opts
);
this
.
_recomputeOptions
();
}
protected
_getEditorClassName
(
theme
:
string
,
fontLigatures
:
boolean
):
string
{
return
''
;
}
protected
getOuterWidth
():
number
{
return
100
;
}
protected
getOuterHeight
():
number
{
return
100
;
}
protected
_getCanUseTranslate3d
():
boolean
{
return
true
;
}
protected
_getPixelRatio
():
number
{
return
1
;
protected
_getEnvConfiguration
():
IEnvConfiguration
{
return
{
extraEditorClassName
:
''
,
outerWidth
:
100
,
outerHeight
:
100
,
canUseTranslate3d
:
true
,
pixelRatio
:
1
,
zoomLevel
:
0
};
}
protected
readConfiguration
(
styling
:
BareFontInfo
):
FontInfo
{
...
...
@@ -48,8 +40,4 @@ export class TestConfiguration extends CommonEditorConfiguration {
maxDigitWidth
:
10
,
},
true
);
}
protected
getZoomLevel
():
number
{
return
0
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录