Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
6ec574f6
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,发现更多精彩内容 >>
提交
6ec574f6
编写于
2月 09, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migrate final users of electricCharacter.onEnter to onEnterRules
上级
9033b848
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
79 addition
and
125 deletion
+79
-125
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+0
-1
src/vs/editor/common/modes/supports/electricCharacter.ts
src/vs/editor/common/modes/supports/electricCharacter.ts
+0
-52
src/vs/editor/common/modes/supports/onEnter.ts
src/vs/editor/common/modes/supports/onEnter.ts
+3
-17
src/vs/editor/test/common/controller/cursor.test.ts
src/vs/editor/test/common/controller/cursor.test.ts
+2
-4
src/vs/editor/test/common/modes/autoIndentation.test.ts
src/vs/editor/test/common/modes/autoIndentation.test.ts
+0
-17
src/vs/editor/test/common/modesUtil.ts
src/vs/editor/test/common/modesUtil.ts
+0
-13
src/vs/languages/handlebars/common/handlebars.ts
src/vs/languages/handlebars/common/handlebars.ts
+13
-1
src/vs/languages/html/common/html.ts
src/vs/languages/html/common/html.ts
+13
-1
src/vs/languages/html/test/common/html.test.ts
src/vs/languages/html/test/common/html.test.ts
+35
-18
src/vs/languages/razor/common/razor.ts
src/vs/languages/razor/common/razor.ts
+13
-1
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
6ec574f6
...
...
@@ -752,7 +752,6 @@ export interface IRichEditElectricCharacter {
getElectricCharacters
():
string
[];
// Should return opening bracket type to match indentation with
onElectricCharacter
(
context
:
ILineContext
,
offset
:
number
):
IElectricAction
;
onEnter
(
context
:
ILineContext
,
offset
:
number
):
IEnterAction
;
}
export
interface
IRichEditOnEnter
{
...
...
src/vs/editor/common/modes/supports/electricCharacter.ts
浏览文件 @
6ec574f6
...
...
@@ -57,18 +57,6 @@ export class BracketElectricCharacterSupport implements Modes.IRichEditElectricC
}
});
}
public
onEnter
(
context
:
Modes
.
ILineContext
,
offset
:
number
):
Modes
.
IEnterAction
{
return
handleEvent
(
context
,
offset
,
(
nestedMode
:
Modes
.
IMode
,
context
:
Modes
.
ILineContext
,
offset
:
number
)
=>
{
if
(
this
.
_modeId
===
nestedMode
.
getId
())
{
return
this
.
brackets
.
onEnter
(
context
,
offset
);
}
else
if
(
nestedMode
.
richEditSupport
&&
nestedMode
.
richEditSupport
.
electricCharacter
)
{
return
nestedMode
.
richEditSupport
.
electricCharacter
.
onEnter
(
context
,
offset
);
}
else
{
return
null
;
}
});
}
}
enum
Lettercase
{
Unknown
,
Lowercase
,
Uppercase
,
Camelcase
}
...
...
@@ -146,14 +134,6 @@ export class Brackets {
return
result
;
}
public
onEnter
(
context
:
Modes
.
ILineContext
,
offset
:
number
):
Modes
.
IEnterAction
{
if
(
context
.
getTokenCount
()
===
0
)
{
return
null
;
}
return
this
.
_onEnterRegexBrackets
(
context
,
offset
);
}
public
onElectricCharacter
(
context
:
Modes
.
ILineContext
,
offset
:
number
):
Modes
.
IElectricAction
{
if
(
context
.
getTokenCount
()
===
0
)
{
return
null
;
...
...
@@ -190,38 +170,6 @@ export class Brackets {
return
true
;
}
private
_onEnterRegexBrackets
(
context
:
Modes
.
ILineContext
,
offset
:
number
):
Modes
.
IEnterAction
{
// Handle regular expression brackets
for
(
var
i
=
0
;
i
<
this
.
regexBrackets
.
length
;
++
i
)
{
var
regexBracket
=
this
.
regexBrackets
[
i
];
var
line
=
context
.
getLineContent
();
if
(
this
.
caseInsensitive
)
{
line
=
line
.
toLowerCase
();
// Even with the /../i regexes we need this for the indexof below
}
// Check if an open bracket matches the line up to offset.
var
matchLine
=
line
.
substr
(
0
,
offset
);
var
matches
=
matchLine
.
match
(
regexBracket
.
open
);
if
(
matches
)
{
// The opening bracket matches. Check the closing one.
if
(
regexBracket
.
closeComplete
)
{
matchLine
=
line
.
substring
(
offset
);
var
matchAfter
=
matches
[
0
].
replace
(
regexBracket
.
open
,
regexBracket
.
closeComplete
);
if
(
matchLine
.
indexOf
(
matchAfter
)
===
0
)
{
return
{
indentAction
:
Modes
.
IndentAction
.
IndentOutdent
};
}
}
return
{
indentAction
:
Modes
.
IndentAction
.
Indent
};
}
}
return
null
;
}
private
_onElectricCharacterStandardBrackets
(
context
:
Modes
.
ILineContext
,
offset
:
number
):
Modes
.
IElectricAction
{
var
tokenIndex
=
context
.
findIndexOfOffset
(
offset
);
var
tokenText
=
context
.
getTokenText
(
tokenIndex
);
...
...
src/vs/editor/common/modes/supports/onEnter.ts
浏览文件 @
6ec574f6
...
...
@@ -182,32 +182,18 @@ export class OnEnterSupport implements IRichEditOnEnter {
}
export
function
getRawEnterActionAtPosition
(
model
:
ITokenizedModel
,
lineNumber
:
number
,
column
:
number
):
IEnterAction
{
let
enterAction
:
IEnterAction
;
let
result
:
IEnterAction
;
let
richEditSupport
=
model
.
getMode
().
richEditSupport
;
if
(
richEditSupport
&&
richEditSupport
.
onEnter
)
{
try
{
enterAction
=
richEditSupport
.
onEnter
.
onEnter
(
model
,
new
Position
(
lineNumber
,
column
));
result
=
richEditSupport
.
onEnter
.
onEnter
(
model
,
new
Position
(
lineNumber
,
column
));
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
}
if
(
!
enterAction
)
{
if
(
richEditSupport
&&
richEditSupport
.
electricCharacter
)
{
let
lineContext
=
model
.
getLineContext
(
lineNumber
);
try
{
enterAction
=
richEditSupport
.
electricCharacter
.
onEnter
(
lineContext
,
column
-
1
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
}
}
else
{
// console.log('USING NEW INDENTATION LOGIC!');
}
return
enterAction
;
return
result
;
}
export
function
getEnterActionAtPosition
(
model
:
ITokenizedModel
,
lineNumber
:
number
,
column
:
number
):
{
enterAction
:
IEnterAction
;
indentation
:
string
;
}
{
...
...
src/vs/editor/test/common/controller/cursor.test.ts
浏览文件 @
6ec574f6
...
...
@@ -786,10 +786,8 @@ class OnEnterMode extends TestMode {
constructor
(
indentAction
:
Modes
.
IndentAction
)
{
super
();
this
.
richEditSupport
=
{
electricCharacter
:
{
getElectricCharacters
:
():
string
[]
=>
null
,
onElectricCharacter
:
(
context
:
Modes
.
ILineContext
,
offset
:
number
):
Modes
.
IElectricAction
=>
null
,
onEnter
:
(
context
:
Modes
.
ILineContext
,
offset
:
number
):
Modes
.
IEnterAction
=>
{
onEnter
:
{
onEnter
:
(
model
,
position
)
=>
{
return
{
indentAction
:
indentAction
};
...
...
src/vs/editor/test/common/modes/autoIndentation.test.ts
浏览文件 @
6ec574f6
...
...
@@ -39,23 +39,6 @@ suite('Editor Modes - Auto Indentation', () => {
close
:
/<
\/(\w[\w\d]
*
)\s
*>$/i
}
],
null
,
true
);
assert
.
equal
(
brackets
.
onEnter
(
modesUtil
.
createLineContextFromTokenText
([
{
text
:
''
,
type
:
''
}
]),
0
),
null
);
assert
.
equal
(
brackets
.
onEnter
(
modesUtil
.
createLineContextFromTokenText
([
{
text
:
'
<
'
,
type
:
'
delim
'
},
{
text
:
'
tag
'
,
type
:
'
tag
'
,
bracket
:
modes
.
Bracket
.
Open
},
{
text
:
'
>
'
,
type
:
'
delim
'
},
]),
5
).
indentAction
,
modes
.
IndentAction
.
Indent
);
assert
.
equal
(
brackets
.
onEnter
(
modesUtil
.
createLineContextFromTokenText
([
{
text
:
'
<
'
,
type
:
'
delim
'
},
{
text
:
'
tag
'
,
type
:
'
tag
'
,
bracket
:
modes
.
Bracket
.
Open
},
{
text
:
'
>
'
,
type
:
'
delim
'
},
{
text
:
'
</
'
,
type
:
'
delim
'
},
{
text
:
'
TAg
'
,
type
:
'
tag
'
,
bracket
:
modes
.
Bracket
.
Close
},
{
text
:
'
>
'
,
type
:
'
delim
'
},
]),
5
).
indentAction
,
modes
.
IndentAction
.
IndentOutdent
);
assert
.
equal
(
brackets
.
onElectricCharacter
(
modesUtil
.
createLineContextFromTokenText
([
{
text
:
'
<
'
,
type
:
'
delim
'
},
{
text
:
'
tag
'
,
type
:
'
tag
'
,
bracket
:
modes
.
Bracket
.
Open
},
...
...
src/vs/editor/test/common/modesUtil.ts
浏览文件 @
6ec574f6
...
...
@@ -25,11 +25,6 @@ export interface ITestItem {
tokens
:
IRelaxedToken
[];
}
export
interface
IOnEnterFunc
{
(
line
:
string
,
offset
:
number
,
state
?:
modes
.
IState
):
modes
.
IEnterAction
;
}
export
interface
IOnElectricCharacterFunc
{
(
line
:
string
,
offset
:
number
,
state
?:
modes
.
IState
):
modes
.
IElectricAction
;
}
...
...
@@ -46,14 +41,6 @@ export function assertWords(actual:string[], expected:string[], message?:string)
assert
.
deepEqual
(
actual
,
expected
,
message
);
}
export
function
createOnEnter
(
mode
:
modes
.
IMode
):
IOnEnterFunc
{
return
function
onEnter
(
line
:
string
,
offset
:
number
,
state
?:
modes
.
IState
):
modes
.
IEnterAction
{
state
=
state
||
mode
.
tokenizationSupport
.
getInitialState
();
var
lineTokens
=
mode
.
tokenizationSupport
.
tokenize
(
line
,
state
);
return
mode
.
richEditSupport
.
electricCharacter
.
onEnter
(
createLineContext
(
line
,
lineTokens
),
offset
);
};
}
export
function
load
(
modeId
:
string
,
preloadModes
:
string
[]
=
[]
):
TPromise
<
modes
.
IMode
>
{
var
toLoad
:
string
[]
=
[].
concat
(
preloadModes
).
concat
([
modeId
]);
...
...
src/vs/languages/handlebars/common/handlebars.ts
浏览文件 @
6ec574f6
...
...
@@ -155,7 +155,19 @@ export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
{
open
:
'
"
'
,
close
:
'
"
'
},
{
open
:
'
\'
'
,
close
:
'
\'
'
}
]
}
},
onEnterRules
:
[
{
beforeText
:
new
RegExp
(
`<(?!(?:
${
htmlMode
.
EMPTY_ELEMENTS
.
join
(
"
|
"
)}
))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`
,
'
i
'
),
afterText
:
/^<
\/(\w[\w\d]
*
)\s
*>$/i
,
action
:
{
indentAction
:
Modes
.
IndentAction
.
IndentOutdent
}
},
{
beforeText
:
new
RegExp
(
`<(?!(?:
${
htmlMode
.
EMPTY_ELEMENTS
.
join
(
"
|
"
)}
))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`
,
'
i
'
),
action
:
{
indentAction
:
Modes
.
IndentAction
.
Indent
}
}
],
});
}
...
...
src/vs/languages/html/common/html.ts
浏览文件 @
6ec574f6
...
...
@@ -368,7 +368,19 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode<W> i
{
open
:
'
"
'
,
close
:
'
"
'
},
{
open
:
'
\'
'
,
close
:
'
\'
'
}
]
}
},
onEnterRules
:
[
{
beforeText
:
new
RegExp
(
`<(?!(?:
${
EMPTY_ELEMENTS
.
join
(
"
|
"
)}
))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`
,
'
i
'
),
afterText
:
/^<
\/(\w[\w\d]
*
)\s
*>$/i
,
action
:
{
indentAction
:
Modes
.
IndentAction
.
IndentOutdent
}
},
{
beforeText
:
new
RegExp
(
`<(?!(?:
${
EMPTY_ELEMENTS
.
join
(
"
|
"
)}
))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`
,
'
i
'
),
action
:
{
indentAction
:
Modes
.
IndentAction
.
Indent
}
}
],
});
}
...
...
src/vs/languages/html/test/common/html.test.ts
浏览文件 @
6ec574f6
...
...
@@ -14,18 +14,18 @@ import modesUtil = require('vs/editor/test/common/modesUtil');
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
Supports
=
require
(
'
vs/editor/common/modes/supports
'
);
import
{
getTag
,
DELIM_END
,
DELIM_START
,
DELIM_ASSIGN
,
ATTRIB_NAME
,
ATTRIB_VALUE
,
COMMENT
,
DELIM_COMMENT
,
DELIM_DOCTYPE
,
DOCTYPE
}
from
'
vs/languages/html/common/htmlTokenTypes
'
;
import
{
getRawEnterActionAtPosition
}
from
'
vs/editor/common/modes/supports/onEnter
'
;
import
{
TextModelWithTokens
}
from
'
vs/editor/common/model/textModelWithTokens
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
suite
(
'
Colorizing - HTML
'
,
()
=>
{
var
onEnter
:
modesUtil
.
IOnEnterFunc
;
var
tokenizationSupport
:
Modes
.
ITokenizationSupport
;
var
_mode
:
Modes
.
IMode
;
suiteSetup
((
done
)
=>
{
modesUtil
.
load
(
'
html
'
).
then
(
mode
=>
{
tokenizationSupport
=
mode
.
tokenizationSupport
;
onEnter
=
modesUtil
.
createOnEnter
(
mode
);
_mode
=
mode
;
done
();
});
...
...
@@ -620,21 +620,38 @@ suite('Colorizing - HTML', () => {
});
test
(
'
onEnter
'
,
function
()
{
assert
.
equal
(
onEnter
(
''
,
0
),
null
);
assert
.
equal
(
onEnter
(
'
>
'
,
1
),
null
);
assert
.
equal
(
onEnter
(
'
span>
'
,
5
),
null
);
assert
.
equal
(
onEnter
(
'
</span>
'
,
7
),
null
);
assert
.
equal
(
onEnter
(
'
<img />
'
,
7
),
null
);
assert
.
equal
(
onEnter
(
'
<span>
'
,
6
).
indentAction
,
Modes
.
IndentAction
.
Indent
);
assert
.
equal
(
onEnter
(
'
<p>
'
,
3
).
indentAction
,
Modes
.
IndentAction
.
Indent
);
assert
.
equal
(
onEnter
(
'
<span><span>
'
,
6
).
indentAction
,
Modes
.
IndentAction
.
Indent
);
assert
.
equal
(
onEnter
(
'
<p><span>
'
,
3
).
indentAction
,
Modes
.
IndentAction
.
Indent
);
assert
.
equal
(
onEnter
(
'
<span></span>
'
,
6
).
indentAction
,
Modes
.
IndentAction
.
IndentOutdent
);
assert
.
equal
(
onEnter
(
'
<p></p>
'
,
3
).
indentAction
,
Modes
.
IndentAction
.
IndentOutdent
);
assert
.
equal
(
onEnter
(
'
<span>a</span>
'
,
6
).
indentAction
,
Modes
.
IndentAction
.
Indent
);
assert
.
equal
(
onEnter
(
'
<span>a</span>
'
,
7
).
indentAction
,
Modes
.
IndentAction
.
IndentOutdent
);
assert
.
equal
(
onEnter
(
'
<span> </span>
'
,
6
).
indentAction
,
Modes
.
IndentAction
.
Indent
);
assert
.
equal
(
onEnter
(
'
<span> </span>
'
,
7
).
indentAction
,
Modes
.
IndentAction
.
IndentOutdent
);
function
onEnter
(
line
:
string
,
offset
:
number
):
Modes
.
IEnterAction
{
let
model
=
new
TextModelWithTokens
([],
TextModel
.
toRawText
(
line
),
false
,
_mode
);
let
result
=
getRawEnterActionAtPosition
(
model
,
1
,
offset
+
1
);
model
.
dispose
();
return
result
;
}
function
assertOnEnter
(
text
:
string
,
offset
:
number
,
expected
:
Modes
.
IndentAction
):
void
{
let
_actual
=
onEnter
(
text
,
offset
);
let
actual
=
_actual
?
_actual
.
indentAction
:
null
;
let
actualStr
=
actual
?
Modes
.
IndentAction
[
actual
]
:
null
;
let
expectedStr
=
expected
?
Modes
.
IndentAction
[
expected
]
:
null
;
assert
.
equal
(
actualStr
,
expectedStr
,
'
TEXT: <<
'
+
text
+
'
>>, OFFSET: <<
'
+
offset
+
'
>>
'
);
}
assertOnEnter
(
''
,
0
,
null
);
assertOnEnter
(
'
>
'
,
1
,
null
);
assertOnEnter
(
'
span>
'
,
5
,
null
);
assertOnEnter
(
'
</span>
'
,
7
,
null
);
assertOnEnter
(
'
<img />
'
,
7
,
null
);
assertOnEnter
(
'
<span>
'
,
6
,
Modes
.
IndentAction
.
Indent
);
assertOnEnter
(
'
<p>
'
,
3
,
Modes
.
IndentAction
.
Indent
);
assertOnEnter
(
'
<span><span>
'
,
6
,
Modes
.
IndentAction
.
Indent
);
assertOnEnter
(
'
<p><span>
'
,
3
,
Modes
.
IndentAction
.
Indent
);
assertOnEnter
(
'
<span></SPan>
'
,
6
,
Modes
.
IndentAction
.
IndentOutdent
);
assertOnEnter
(
'
<span></span>
'
,
6
,
Modes
.
IndentAction
.
IndentOutdent
);
assertOnEnter
(
'
<p></p>
'
,
3
,
Modes
.
IndentAction
.
IndentOutdent
);
assertOnEnter
(
'
<span>a</span>
'
,
6
,
Modes
.
IndentAction
.
Indent
);
assertOnEnter
(
'
<span>a</span>
'
,
7
,
Modes
.
IndentAction
.
IndentOutdent
);
assertOnEnter
(
'
<span> </span>
'
,
6
,
Modes
.
IndentAction
.
Indent
);
assertOnEnter
(
'
<span> </span>
'
,
7
,
Modes
.
IndentAction
.
IndentOutdent
);
});
});
src/vs/languages/razor/common/razor.ts
浏览文件 @
6ec574f6
...
...
@@ -102,7 +102,19 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
{
open
:
'
"
'
,
close
:
'
"
'
},
{
open
:
'
\'
'
,
close
:
'
\'
'
}
]
}
},
onEnterRules
:
[
{
beforeText
:
new
RegExp
(
`<(?!(?:
${
htmlMode
.
EMPTY_ELEMENTS
.
join
(
"
|
"
)}
))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`
,
'
i
'
),
afterText
:
/^<
\/(\w[\w\d]
*
)\s
*>$/i
,
action
:
{
indentAction
:
Modes
.
IndentAction
.
IndentOutdent
}
},
{
beforeText
:
new
RegExp
(
`<(?!(?:
${
htmlMode
.
EMPTY_ELEMENTS
.
join
(
"
|
"
)}
))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`
,
'
i
'
),
action
:
{
indentAction
:
Modes
.
IndentAction
.
Indent
}
}
],
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录