Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
69b546a3
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,发现更多精彩内容 >>
未验证
提交
69b546a3
编写于
11月 28, 2019
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify onEnter calls
上级
2c208a99
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
58 deletion
+23
-58
src/vs/editor/common/modes/languageConfigurationRegistry.ts
src/vs/editor/common/modes/languageConfigurationRegistry.ts
+19
-54
src/vs/editor/common/modes/supports/onEnter.ts
src/vs/editor/common/modes/supports/onEnter.ts
+3
-3
src/vs/editor/test/common/modes/supports/onEnter.test.ts
src/vs/editor/test/common/modes/supports/onEnter.test.ts
+1
-1
未找到文件。
src/vs/editor/common/modes/languageConfigurationRegistry.ts
浏览文件 @
69b546a3
...
...
@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
IDisposable
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
...
...
@@ -17,7 +16,7 @@ import { createScopedLineTokens, ScopedLineTokens } from 'vs/editor/common/modes
import
{
CharacterPairSupport
}
from
'
vs/editor/common/modes/supports/characterPair
'
;
import
{
BracketElectricCharacterSupport
,
IElectricAction
}
from
'
vs/editor/common/modes/supports/electricCharacter
'
;
import
{
IndentConsts
,
IndentRulesSupport
}
from
'
vs/editor/common/modes/supports/indentRules
'
;
import
{
IOnEnterSupportOptions
,
OnEnterSupport
}
from
'
vs/editor/common/modes/supports/onEnter
'
;
import
{
OnEnterSupport
}
from
'
vs/editor/common/modes/supports/onEnter
'
;
import
{
RichEditBrackets
}
from
'
vs/editor/common/modes/supports/richEditBrackets
'
;
import
{
EditorAutoIndentStrategy
}
from
'
vs/editor/common/config/editorOptions
'
;
...
...
@@ -49,11 +48,11 @@ export class RichEditSupport {
private
readonly
_languageIdentifier
:
LanguageIdentifier
;
private
_brackets
:
RichEditBrackets
|
null
;
private
_electricCharacter
:
BracketElectricCharacterSupport
|
null
;
private
readonly
_onEnterSupport
:
OnEnterSupport
|
null
;
public
readonly
comments
:
ICommentsConfiguration
|
null
;
public
readonly
characterPair
:
CharacterPairSupport
;
public
readonly
wordDefinition
:
RegExp
;
public
readonly
onEnter
:
OnEnterSupport
|
null
;
public
readonly
indentRulesSupport
:
IndentRulesSupport
|
null
;
public
readonly
indentationRules
:
IndentationRule
|
undefined
;
public
readonly
foldingRules
:
FoldingRules
;
...
...
@@ -71,8 +70,7 @@ export class RichEditSupport {
this
.
_conf
=
RichEditSupport
.
_mergeConf
(
prev
,
rawConf
);
this
.
onEnter
=
RichEditSupport
.
_handleOnEnter
(
this
.
_conf
);
this
.
_onEnterSupport
=
(
this
.
_conf
.
brackets
||
this
.
_conf
.
indentationRules
||
this
.
_conf
.
onEnterRules
?
new
OnEnterSupport
(
this
.
_conf
)
:
null
);
this
.
comments
=
RichEditSupport
.
_handleComments
(
this
.
_conf
);
this
.
characterPair
=
new
CharacterPairSupport
(
this
.
_conf
);
...
...
@@ -103,6 +101,13 @@ export class RichEditSupport {
return
this
.
_electricCharacter
;
}
public
onEnter
(
autoIndent
:
EditorAutoIndentStrategy
,
oneLineAboveText
:
string
,
beforeEnterText
:
string
,
afterEnterText
:
string
):
EnterAction
|
null
{
if
(
!
this
.
_onEnterSupport
)
{
return
null
;
}
return
this
.
_onEnterSupport
.
onEnter
(
autoIndent
,
oneLineAboveText
,
beforeEnterText
,
afterEnterText
);
}
private
static
_mergeConf
(
prev
:
LanguageConfiguration
|
null
,
current
:
LanguageConfiguration
):
LanguageConfiguration
{
return
{
comments
:
(
prev
?
current
.
comments
||
prev
.
comments
:
current
.
comments
),
...
...
@@ -118,29 +123,6 @@ export class RichEditSupport {
};
}
private
static
_handleOnEnter
(
conf
:
LanguageConfiguration
):
OnEnterSupport
|
null
{
// on enter
let
onEnter
:
IOnEnterSupportOptions
=
{};
let
empty
=
true
;
if
(
conf
.
brackets
)
{
empty
=
false
;
onEnter
.
brackets
=
conf
.
brackets
;
}
if
(
conf
.
indentationRules
)
{
empty
=
false
;
}
if
(
conf
.
onEnterRules
)
{
empty
=
false
;
onEnter
.
regExpRules
=
conf
.
onEnterRules
;
}
if
(
!
empty
)
{
return
new
OnEnterSupport
(
onEnter
);
}
return
null
;
}
private
static
_handleComments
(
conf
:
LanguageConfiguration
):
ICommentsConfiguration
|
null
{
let
commentRule
=
conf
.
comments
;
if
(
!
commentRule
)
{
...
...
@@ -481,6 +463,11 @@ export class LanguageConfigurationRegistryImpl {
return
null
;
}
const
richEditSupport
=
this
.
_getRichEditSupport
(
languageId
);
if
(
!
richEditSupport
)
{
return
null
;
}
const
indentRulesSupport
=
this
.
getIndentRulesSupport
(
languageId
);
if
(
!
indentRulesSupport
)
{
return
null
;
...
...
@@ -492,15 +479,7 @@ export class LanguageConfigurationRegistryImpl {
if
(
indent
)
{
const
inheritLine
=
indent
.
line
;
if
(
inheritLine
!==
undefined
)
{
const
onEnterSupport
=
this
.
_getOnEnterSupport
(
languageId
);
let
enterResult
:
EnterAction
|
null
=
null
;
try
{
if
(
onEnterSupport
)
{
enterResult
=
onEnterSupport
.
onEnter
(
autoIndent
,
''
,
virtualModel
.
getLineContent
(
inheritLine
),
''
);
}
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
const
enterResult
=
richEditSupport
.
onEnter
(
autoIndent
,
''
,
virtualModel
.
getLineContent
(
inheritLine
),
''
);
if
(
enterResult
)
{
let
indentation
=
strings
.
getLeadingWhitespace
(
virtualModel
.
getLineContent
(
inheritLine
));
...
...
@@ -689,18 +668,10 @@ export class LanguageConfigurationRegistryImpl {
// begin onEnter
private
_getOnEnterSupport
(
languageId
:
LanguageId
):
OnEnterSupport
|
null
{
const
value
=
this
.
_getRichEditSupport
(
languageId
);
if
(
!
value
)
{
return
null
;
}
return
value
.
onEnter
||
null
;
}
public
getEnterAction
(
autoIndent
:
EditorAutoIndentStrategy
,
model
:
ITextModel
,
range
:
Range
):
CompleteEnterAction
|
null
{
const
scopedLineTokens
=
this
.
getScopedLineTokens
(
model
,
range
.
startLineNumber
,
range
.
startColumn
);
const
onEnterSupport
=
this
.
_getOnEnter
Support
(
scopedLineTokens
.
languageId
);
if
(
!
onEnter
Support
)
{
const
richEditSupport
=
this
.
_getRichEdit
Support
(
scopedLineTokens
.
languageId
);
if
(
!
richEdit
Support
)
{
return
null
;
}
...
...
@@ -726,13 +697,7 @@ export class LanguageConfigurationRegistryImpl {
}
}
let
enterResult
:
EnterAction
|
null
=
null
;
try
{
enterResult
=
onEnterSupport
.
onEnter
(
autoIndent
,
oneLineAboveText
,
beforeEnterText
,
afterEnterText
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
const
enterResult
=
richEditSupport
.
onEnter
(
autoIndent
,
oneLineAboveText
,
beforeEnterText
,
afterEnterText
);
if
(
!
enterResult
)
{
return
null
;
}
...
...
src/vs/editor/common/modes/supports/onEnter.ts
浏览文件 @
69b546a3
...
...
@@ -10,7 +10,7 @@ import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions'
export
interface
IOnEnterSupportOptions
{
brackets
?:
CharacterPair
[];
regExp
Rules
?:
OnEnterRule
[];
onEnter
Rules
?:
OnEnterRule
[];
}
interface
IProcessedBracketPair
{
...
...
@@ -25,7 +25,7 @@ export class OnEnterSupport {
private
readonly
_brackets
:
IProcessedBracketPair
[];
private
readonly
_regExpRules
:
OnEnterRule
[];
constructor
(
opts
?
:
IOnEnterSupportOptions
)
{
constructor
(
opts
:
IOnEnterSupportOptions
)
{
opts
=
opts
||
{};
opts
.
brackets
=
opts
.
brackets
||
[
[
'
(
'
,
'
)
'
],
...
...
@@ -46,7 +46,7 @@ export class OnEnterSupport {
});
}
});
this
.
_regExpRules
=
opts
.
regExp
Rules
||
[];
this
.
_regExpRules
=
opts
.
onEnter
Rules
||
[];
}
public
onEnter
(
autoIndent
:
EditorAutoIndentStrategy
,
oneLineAboveText
:
string
,
beforeEnterText
:
string
,
afterEnterText
:
string
):
EnterAction
|
null
{
...
...
src/vs/editor/test/common/modes/supports/onEnter.test.ts
浏览文件 @
69b546a3
...
...
@@ -49,7 +49,7 @@ suite('OnEnter', () => {
test
(
'
uses regExpRules
'
,
()
=>
{
let
support
=
new
OnEnterSupport
({
regExp
Rules
:
javascriptOnEnterRules
onEnter
Rules
:
javascriptOnEnterRules
});
let
testIndentAction
=
(
oneLineAboveText
:
string
,
beforeText
:
string
,
afterText
:
string
,
expectedIndentAction
:
IndentAction
|
null
,
expectedAppendText
:
string
|
null
,
removeText
:
number
=
0
)
=>
{
let
actual
=
support
.
onEnter
(
EditorAutoIndentStrategy
.
Advanced
,
oneLineAboveText
,
beforeText
,
afterText
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录