Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
d5610587
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,发现更多精彩内容 >>
提交
d5610587
编写于
2月 13, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better handling of cross-mode bracket matching
上级
568c9e51
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
87 addition
and
8 deletion
+87
-8
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+1
-0
src/vs/editor/common/model/textModelWithTokens.ts
src/vs/editor/common/model/textModelWithTokens.ts
+31
-5
src/vs/editor/common/modes/supports/electricCharacter.ts
src/vs/editor/common/modes/supports/electricCharacter.ts
+1
-0
src/vs/languages/html/common/html.ts
src/vs/languages/html/common/html.ts
+6
-2
src/vs/languages/html/test/common/html.test.ts
src/vs/languages/html/test/common/html.test.ts
+48
-1
未找到文件。
src/vs/editor/common/editorCommon.ts
浏览文件 @
d5610587
...
...
@@ -1377,6 +1377,7 @@ export interface ITextModel {
}
export
interface
IRichEditBracket
{
modeId
:
string
;
open
:
string
;
close
:
string
;
forwardRegex
:
RegExp
;
...
...
src/vs/editor/common/model/textModelWithTokens.ts
浏览文件 @
d5610587
...
...
@@ -998,9 +998,8 @@ export class TextModelWithTokens extends TextModel implements EditorCommon.IToke
private
_findMatchingBracketUp
(
bracket
:
EditorCommon
.
IRichEditBracket
,
position
:
EditorCommon
.
IEditorPosition
):
Range
{
// console.log('_findMatchingBracketUp: ', 'bracket: ', JSON.stringify(bracket), 'startPosition: ', String(position));
let
modeId
=
bracket
.
modeId
;
let
tokensMap
=
this
.
_tokensInflatorMap
;
// TODO@Alex: account for mode transitions
let
reversedBracketRegex
=
bracket
.
reversedRegex
;
let
count
=
-
1
;
...
...
@@ -1008,12 +1007,20 @@ export class TextModelWithTokens extends TextModel implements EditorCommon.IToke
let
lineTokens
=
this
.
_lines
[
lineNumber
-
1
].
getTokens
();
let
lineText
=
this
.
_lines
[
lineNumber
-
1
].
text
;
let
tokens
=
lineTokens
.
getBinaryEncodedTokens
();
let
modeTransitions
=
this
.
_lines
[
lineNumber
-
1
].
getModeTransitions
().
toArray
(
this
.
_mode
);
let
currentModeIndex
=
modeTransitions
.
length
-
1
;
let
currentModeStart
=
modeTransitions
[
currentModeIndex
].
startIndex
;
let
currentModeId
=
modeTransitions
[
currentModeIndex
].
mode
.
getId
();
let
tokensLength
=
tokens
.
length
-
1
;
let
currentTokenEnd
=
lineText
.
length
;
if
(
lineNumber
===
position
.
lineNumber
)
{
tokensLength
=
lineTokens
.
findIndexOfOffset
(
position
.
column
-
1
);
currentTokenEnd
=
position
.
column
-
1
;
currentModeIndex
=
Arrays
.
findIndexInSegmentsArray
(
modeTransitions
,
position
.
column
-
1
);
currentModeStart
=
modeTransitions
[
currentModeIndex
].
startIndex
;
currentModeId
=
modeTransitions
[
currentModeIndex
].
mode
.
getId
();
}
for
(
let
tokenIndex
=
tokensLength
;
tokenIndex
>=
0
;
tokenIndex
--
)
{
...
...
@@ -1021,7 +1028,13 @@ export class TextModelWithTokens extends TextModel implements EditorCommon.IToke
let
currentTokenType
=
getType
(
tokensMap
,
currentToken
);
let
currentTokenStart
=
getStartIndex
(
currentToken
);
if
(
!
ignoreBracketsInToken
(
currentTokenType
))
{
if
(
currentTokenStart
<
currentModeStart
)
{
currentModeIndex
--
;
currentModeStart
=
modeTransitions
[
currentModeIndex
].
startIndex
;
currentModeId
=
modeTransitions
[
currentModeIndex
].
mode
.
getId
();
}
if
(
currentModeId
===
modeId
&&
!
ignoreBracketsInToken
(
currentTokenType
))
{
while
(
true
)
{
let
r
=
BracketsUtils
.
findPrevBracketInToken
(
reversedBracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
,
currentTokenEnd
);
...
...
@@ -1055,8 +1068,8 @@ export class TextModelWithTokens extends TextModel implements EditorCommon.IToke
private
_findMatchingBracketDown
(
bracket
:
EditorCommon
.
IRichEditBracket
,
position
:
EditorCommon
.
IEditorPosition
):
Range
{
// console.log('_findMatchingBracketDown: ', 'bracket: ', JSON.stringify(bracket), 'startPosition: ', String(position));
let
modeId
=
bracket
.
modeId
;
let
tokensMap
=
this
.
_tokensInflatorMap
;
// TODO@Alex: account for mode transitions
let
bracketRegex
=
bracket
.
forwardRegex
;
let
count
=
1
;
...
...
@@ -1064,12 +1077,20 @@ export class TextModelWithTokens extends TextModel implements EditorCommon.IToke
let
lineTokens
=
this
.
_lines
[
lineNumber
-
1
].
getTokens
();
let
lineText
=
this
.
_lines
[
lineNumber
-
1
].
text
;
let
tokens
=
lineTokens
.
getBinaryEncodedTokens
();
let
modeTransitions
=
this
.
_lines
[
lineNumber
-
1
].
getModeTransitions
().
toArray
(
this
.
_mode
);
let
currentModeIndex
=
0
;
let
nextModeStart
=
(
currentModeIndex
+
1
<
modeTransitions
.
length
?
modeTransitions
[
currentModeIndex
+
1
].
startIndex
:
lineText
.
length
);
let
currentModeId
=
modeTransitions
[
currentModeIndex
].
mode
.
getId
();
let
startTokenIndex
=
0
;
let
currentTokenStart
=
getStartIndex
(
startTokenIndex
);
if
(
lineNumber
===
position
.
lineNumber
)
{
startTokenIndex
=
lineTokens
.
findIndexOfOffset
(
position
.
column
-
1
);
currentTokenStart
=
Math
.
max
(
currentTokenStart
,
position
.
column
-
1
);
currentModeIndex
=
Arrays
.
findIndexInSegmentsArray
(
modeTransitions
,
position
.
column
-
1
);
nextModeStart
=
(
currentModeIndex
+
1
<
modeTransitions
.
length
?
modeTransitions
[
currentModeIndex
+
1
].
startIndex
:
lineText
.
length
);
currentModeId
=
modeTransitions
[
currentModeIndex
].
mode
.
getId
();
}
for
(
let
tokenIndex
=
startTokenIndex
,
tokensLength
=
tokens
.
length
;
tokenIndex
<
tokensLength
;
tokenIndex
++
)
{
...
...
@@ -1077,8 +1098,13 @@ export class TextModelWithTokens extends TextModel implements EditorCommon.IToke
let
currentTokenType
=
getType
(
tokensMap
,
currentToken
);
let
currentTokenEnd
=
tokenIndex
+
1
<
tokensLength
?
getStartIndex
(
tokens
[
tokenIndex
+
1
])
:
lineText
.
length
;
if
(
currentTokenStart
>=
nextModeStart
)
{
currentModeIndex
++
;
nextModeStart
=
(
currentModeIndex
+
1
<
modeTransitions
.
length
?
modeTransitions
[
currentModeIndex
+
1
].
startIndex
:
lineText
.
length
);
currentModeId
=
modeTransitions
[
currentModeIndex
].
mode
.
getId
();
}
if
(
!
ignoreBracketsInToken
(
currentTokenType
))
{
if
(
currentModeId
===
modeId
&&
!
ignoreBracketsInToken
(
currentTokenType
))
{
while
(
true
)
{
let
r
=
BracketsUtils
.
findNextBracketInToken
(
bracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
,
currentTokenEnd
);
if
(
!
r
)
{
...
...
src/vs/editor/common/modes/supports/electricCharacter.ts
浏览文件 @
d5610587
...
...
@@ -84,6 +84,7 @@ export class Brackets {
this
.
_modeId
=
modeId
;
this
.
_brackets
=
brackets
.
map
((
b
)
=>
{
return
{
modeId
:
modeId
,
open
:
b
.
open
,
close
:
b
.
close
,
forwardRegex
:
getRegexForBracketPair
({
open
:
b
.
open
,
close
:
b
.
close
}),
...
...
src/vs/languages/html/common/html.ts
浏览文件 @
d5610587
...
...
@@ -347,11 +347,15 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode<W> i
},
brackets
:
[
[
'
<!--
'
,
'
-->
'
]
[
'
<!--
'
,
'
-->
'
],
[
'
<
'
,
'
>
'
],
],
__electricCharacterSupport
:
{
brackets
:
[],
brackets
:
[
{
tokenType
:
'
bla
'
,
open
:
'
<!--
'
,
close
:
'
-->
'
,
isElectric
:
true
},
{
tokenType
:
'
bla
'
,
open
:
'
<
'
,
close
:
'
>
'
,
isElectric
:
true
}
],
caseInsensitive
:
true
,
embeddedElectricCharacters
:
[
'
*
'
,
'
}
'
,
'
]
'
,
'
)
'
]
},
...
...
src/vs/languages/html/test/common/html.test.ts
浏览文件 @
d5610587
...
...
@@ -17,6 +17,7 @@ import {getTag, DELIM_END, DELIM_START, DELIM_ASSIGN, ATTRIB_NAME, ATTRIB_VALUE,
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
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
suite
(
'
Colorizing - HTML
'
,
()
=>
{
...
...
@@ -653,5 +654,51 @@ suite('Colorizing - HTML', () => {
assertOnEnter
(
'
<span> </span>
'
,
6
,
Modes
.
IndentAction
.
Indent
);
assertOnEnter
(
'
<span> </span>
'
,
7
,
Modes
.
IndentAction
.
IndentOutdent
);
});
});
test
(
'
matchBracket
'
,
()
=>
{
function
toString
(
brackets
:
EditorCommon
.
IEditorRange
[]):
string
[]
{
if
(
!
brackets
)
{
return
null
;
}
brackets
.
sort
(
Range
.
compareRangesUsingStarts
);
return
brackets
.
map
(
b
=>
b
.
toString
());
}
function
assertBracket
(
lines
:
string
[],
lineNumber
:
number
,
column
:
number
,
expected
:
EditorCommon
.
IEditorRange
[]):
void
{
let
model
=
new
TextModelWithTokens
([],
TextModel
.
toRawText
(
lines
.
join
(
'
\n
'
)),
false
,
_mode
);
// force tokenization
model
.
getLineContext
(
model
.
getLineCount
());
let
actual
=
model
.
matchBracket
({
lineNumber
:
lineNumber
,
column
:
column
});
let
actualStr
=
actual
?
toString
(
actual
.
brackets
)
:
null
;
let
expectedStr
=
toString
(
expected
);
assert
.
deepEqual
(
actualStr
,
expectedStr
,
'
TEXT <<
'
+
lines
.
join
(
'
\n
'
)
+
'
>>, POS:
'
+
lineNumber
+
'
,
'
+
column
);
}
assertBracket
([
'
<p></p>
'
],
1
,
1
,
[
new
Range
(
1
,
1
,
1
,
2
),
new
Range
(
1
,
3
,
1
,
4
)]);
assertBracket
([
'
<p></p>
'
],
1
,
2
,
[
new
Range
(
1
,
1
,
1
,
2
),
new
Range
(
1
,
3
,
1
,
4
)]);
assertBracket
([
'
<p></p>
'
],
1
,
3
,
[
new
Range
(
1
,
1
,
1
,
2
),
new
Range
(
1
,
3
,
1
,
4
)]);
assertBracket
([
'
<p></p>
'
],
1
,
4
,
[
new
Range
(
1
,
1
,
1
,
2
),
new
Range
(
1
,
3
,
1
,
4
)]);
assertBracket
([
'
<p></p>
'
],
1
,
5
,
[
new
Range
(
1
,
4
,
1
,
5
),
new
Range
(
1
,
7
,
1
,
8
)]);
assertBracket
([
'
<p></p>
'
],
1
,
6
,
null
);
assertBracket
([
'
<p></p>
'
],
1
,
7
,
[
new
Range
(
1
,
4
,
1
,
5
),
new
Range
(
1
,
7
,
1
,
8
)]);
assertBracket
([
'
<p></p>
'
],
1
,
8
,
[
new
Range
(
1
,
4
,
1
,
5
),
new
Range
(
1
,
7
,
1
,
8
)]);
assertBracket
([
'
<script>a[a</script>a[a<script>a]a
'
],
1
,
10
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
assertBracket
([
'
<script>a[a</script>a[a<script>a]a
'
],
1
,
11
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
assertBracket
([
'
<script>a[a</script>a[a<script>a]a
'
],
1
,
22
,
null
);
assertBracket
([
'
<script>a[a</script>a[a<script>a]a
'
],
1
,
23
,
null
);
assertBracket
([
'
<script>a[a</script>a[a<script>a]a
'
],
1
,
33
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
assertBracket
([
'
<script>a[a</script>a[a<script>a]a
'
],
1
,
34
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
assertBracket
([
'
<script>a[a</script>a]a<script>a]a
'
],
1
,
10
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
assertBracket
([
'
<script>a[a</script>a]a<script>a]a
'
],
1
,
11
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
assertBracket
([
'
<script>a[a</script>a]a<script>a]a
'
],
1
,
22
,
null
);
assertBracket
([
'
<script>a[a</script>a]a<script>a]a
'
],
1
,
23
,
null
);
assertBracket
([
'
<script>a[a</script>a]a<script>a]a
'
],
1
,
33
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
assertBracket
([
'
<script>a[a</script>a]a<script>a]a
'
],
1
,
34
,
[
new
Range
(
1
,
10
,
1
,
11
),
new
Range
(
1
,
33
,
1
,
34
)]);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录