Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
088acbb7
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,发现更多精彩内容 >>
提交
088acbb7
编写于
2月 16, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adopt richEditSupport brackets in tokenSelectionSupport
上级
2706f731
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
29 deletion
+79
-29
src/vs/editor/common/modes/supports.ts
src/vs/editor/common/modes/supports.ts
+0
-11
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
+73
-12
src/vs/editor/contrib/smartSelect/test/common/tokenSelectionSupport.test.ts
...rib/smartSelect/test/common/tokenSelectionSupport.test.ts
+6
-6
未找到文件。
src/vs/editor/common/modes/supports.ts
浏览文件 @
088acbb7
...
...
@@ -151,14 +151,3 @@ export class FilteredLineContext implements Modes.ILineContext {
export
function
ignoreBracketsInToken
(
tokenType
:
string
):
boolean
{
return
/
\b(
comment|string|regex
)\b
/
.
test
(
tokenType
);
}
// TODO@Alex -> refactor to use `brackets` from language configuration
export
function
getBracketFor
(
tokenType
:
string
,
tokenText
:
string
,
mode
:
Modes
.
IMode
):
Modes
.
Bracket
{
if
(
tokenText
===
'
{
'
||
tokenText
===
'
(
'
||
tokenText
===
'
[
'
)
{
return
Modes
.
Bracket
.
Open
;
}
if
(
tokenText
===
'
}
'
||
tokenText
===
'
)
'
||
tokenText
===
'
]
'
)
{
return
Modes
.
Bracket
.
Close
;
}
return
Modes
.
Bracket
.
None
;
}
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
浏览文件 @
088acbb7
...
...
@@ -8,7 +8,8 @@ import EditorCommon = require('vs/editor/common/editorCommon');
import
Modes
=
require
(
'
vs/editor/common/modes
'
);
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
getBracketFor
}
from
'
vs/editor/common/modes/supports
'
;
import
{
ignoreBracketsInToken
}
from
'
vs/editor/common/modes/supports
'
;
import
{
BracketsUtils
}
from
'
vs/editor/common/modes/supports/electricCharacter
'
;
export
class
Node
{
...
...
@@ -108,7 +109,12 @@ class TokenScanner {
private
_versionId
:
number
;
private
_currentLineNumber
:
number
;
private
_currentTokenIndex
:
number
;
private
_currentTokenStart
:
number
;
private
_currentLineTokens
:
EditorCommon
.
ILineTokens
;
private
_currentLineModeTransitions
:
Modes
.
IModeTransition
[];
private
_currentModeIndex
:
number
;
private
_nextModeStart
:
number
;
private
_currentModeBrackets
:
Modes
.
IRichEditBrackets
;
private
_currentLineText
:
string
;
constructor
(
model
:
EditorCommon
.
IModel
)
{
...
...
@@ -130,31 +136,86 @@ class TokenScanner {
// no tokens for this line
this
.
_currentLineTokens
=
this
.
_model
.
getLineTokens
(
this
.
_currentLineNumber
);
this
.
_currentLineText
=
this
.
_model
.
getLineContent
(
this
.
_currentLineNumber
);
this
.
_currentLineModeTransitions
=
this
.
_model
.
_getLineModeTransitions
(
this
.
_currentLineNumber
);
this
.
_currentTokenIndex
=
0
;
this
.
_currentTokenStart
=
0
;
this
.
_currentModeIndex
=
-
1
;
this
.
_nextModeStart
=
0
;
}
if
(
this
.
_currentTokenIndex
>=
this
.
_currentLineTokens
.
getTokenCount
())
{
// last token of line visited
this
.
_currentLineNumber
+=
1
;
this
.
_currentLineTokens
=
null
;
this
.
_currentLineText
=
null
;
return
this
.
next
();
}
if
(
this
.
_currentTokenStart
>=
this
.
_nextModeStart
)
{
this
.
_currentModeIndex
++
;
this
.
_nextModeStart
=
(
this
.
_currentModeIndex
+
1
<
this
.
_currentLineModeTransitions
.
length
?
this
.
_currentLineModeTransitions
[
this
.
_currentModeIndex
+
1
].
startIndex
:
this
.
_currentLineText
.
length
+
1
);
let
mode
=
(
this
.
_currentModeIndex
<
this
.
_currentLineModeTransitions
.
length
?
this
.
_currentLineModeTransitions
[
this
.
_currentModeIndex
]
:
null
);
this
.
_currentModeBrackets
=
(
mode
&&
mode
.
mode
.
richEditSupport
?
mode
.
mode
.
richEditSupport
.
brackets
:
null
);
}
let
tokenType
=
this
.
_currentLineTokens
.
getTokenType
(
this
.
_currentTokenIndex
);
let
tokenStartIndex
=
this
.
_currentLineTokens
.
getTokenStartIndex
(
this
.
_currentTokenIndex
);
let
tokenEndIndex
=
this
.
_currentLineTokens
.
getTokenEndIndex
(
this
.
_currentTokenIndex
,
this
.
_currentLineText
.
length
+
1
);
let
tokenText
=
this
.
_currentLineText
.
substring
(
tokenStartIndex
,
tokenEndIndex
);
var
token
:
Token
=
{
type
:
tokenType
,
bracket
:
getBracketFor
(
tokenType
,
tokenText
,
this
.
_model
.
getMode
()),
let
tokenEndIndex
=
this
.
_currentLineTokens
.
getTokenEndIndex
(
this
.
_currentTokenIndex
,
this
.
_currentLineText
.
length
);
let
nextBracket
:
Range
=
null
;
if
(
this
.
_currentModeBrackets
&&
!
ignoreBracketsInToken
(
tokenType
))
{
nextBracket
=
BracketsUtils
.
findNextBracketInToken
(
this
.
_currentModeBrackets
.
forwardRegex
,
this
.
_currentLineNumber
,
this
.
_currentLineText
,
this
.
_currentTokenStart
,
tokenEndIndex
);
}
if
(
nextBracket
&&
this
.
_currentTokenStart
<
nextBracket
.
startColumn
-
1
)
{
// found a bracket, but it is not at the beginning of the token
tokenEndIndex
=
nextBracket
.
startColumn
-
1
;
nextBracket
=
null
;
}
let
bracketData
:
EditorCommon
.
IRichEditBracket
=
null
;
let
bracketIsOpen
:
boolean
=
false
;
if
(
nextBracket
)
{
let
bracketText
=
this
.
_currentLineText
.
substring
(
nextBracket
.
startColumn
-
1
,
nextBracket
.
endColumn
-
1
);
bracketData
=
this
.
_currentModeBrackets
.
textIsBracket
[
bracketText
];
bracketIsOpen
=
this
.
_currentModeBrackets
.
textIsOpenBracket
[
bracketText
];
}
if
(
!
bracketData
)
{
let
token
:
Token
=
{
type
:
tokenType
,
bracket
:
Modes
.
Bracket
.
None
,
range
:
{
startLineNumber
:
this
.
_currentLineNumber
,
startColumn
:
1
+
this
.
_currentTokenStart
,
endLineNumber
:
this
.
_currentLineNumber
,
endColumn
:
1
+
tokenEndIndex
}
};
// console.log('TOKEN: <<' + this._currentLineText.substring(this._currentTokenStart, tokenEndIndex) + '>>');
this
.
_currentTokenIndex
+=
1
;
this
.
_currentTokenStart
=
(
this
.
_currentTokenIndex
<
this
.
_currentLineTokens
.
getTokenCount
()
?
this
.
_currentLineTokens
.
getTokenStartIndex
(
this
.
_currentTokenIndex
)
:
0
);
return
token
;
}
let
type
=
`
${
bracketData
.
modeId
}
;
${
bracketData
.
open
}
;
${
bracketData
.
close
}
`
;
let
token
:
Token
=
{
type
:
type
,
bracket
:
bracketIsOpen
?
Modes
.
Bracket
.
Open
:
Modes
.
Bracket
.
Close
,
range
:
{
startLineNumber
:
this
.
_currentLineNumber
,
startColumn
:
1
+
t
okenStartIndex
,
startColumn
:
1
+
t
his
.
_currentTokenStart
,
endLineNumber
:
this
.
_currentLineNumber
,
endColumn
:
1
+
tokenEndIndex
endColumn
:
nextBracket
.
endColumn
}
};
// token.__debugContent = this._model.getValueInRange(token.range);
this
.
_currentTokenIndex
+=
1
;
// console.log('BRACKET: <<' + this._currentLineText.substring(this._currentTokenStart, nextBracket.endColumn - 1) + '>>');
if
(
nextBracket
.
endColumn
-
1
<
tokenEndIndex
)
{
// found a bracket, but it is not at the end of the token
this
.
_currentTokenStart
=
nextBracket
.
endColumn
-
1
;
}
else
{
this
.
_currentTokenIndex
+=
1
;
this
.
_currentTokenStart
=
(
this
.
_currentTokenIndex
<
this
.
_currentLineTokens
.
getTokenCount
()
?
this
.
_currentLineTokens
.
getTokenStartIndex
(
this
.
_currentTokenIndex
)
:
0
);
}
return
token
;
}
}
...
...
src/vs/editor/contrib/smartSelect/test/common/tokenSelectionSupport.test.ts
浏览文件 @
088acbb7
...
...
@@ -52,13 +52,13 @@ suite('TokenSelectionSupport', () => {
'
\t
}
'
,
'
}
'
],
3
,
20
,
[
new
Range
(
1
,
1
,
5
,
3
),
new
Range
(
1
,
21
,
5
,
3
),
new
Range
(
2
,
1
,
4
,
4
),
new
Range
(
2
,
11
,
4
,
4
),
new
Range
(
1
,
1
,
5
,
2
),
new
Range
(
1
,
21
,
5
,
2
),
new
Range
(
2
,
1
,
4
,
3
),
new
Range
(
2
,
11
,
4
,
3
),
new
Range
(
3
,
1
,
4
,
2
),
new
Range
(
3
,
1
,
3
,
2
8
),
new
Range
(
3
,
10
,
3
,
2
8
),
new
Range
(
3
,
1
,
3
,
2
7
),
new
Range
(
3
,
10
,
3
,
2
7
),
new
Range
(
3
,
11
,
3
,
26
),
new
Range
(
3
,
17
,
3
,
26
),
new
Range
(
3
,
18
,
3
,
25
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录