Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
628d2a46
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,发现更多精彩内容 >>
提交
628d2a46
编写于
10月 24, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify WordHelper
上级
429be924
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
20 addition
and
37 deletion
+20
-37
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+0
-6
src/vs/editor/common/model/textModelWithTokens.ts
src/vs/editor/common/model/textModelWithTokens.ts
+11
-6
src/vs/editor/common/model/textModelWithTokensHelpers.ts
src/vs/editor/common/model/textModelWithTokensHelpers.ts
+9
-25
未找到文件。
src/vs/editor/common/editorCommon.ts
浏览文件 @
628d2a46
...
...
@@ -17,7 +17,6 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
ModeTransition
}
from
'
vs/editor/common/core/modeTransition
'
;
import
{
IndentRange
}
from
'
vs/editor/common/model/indentRanges
'
;
import
{
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ContextKeyExpr
,
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
@@ -1870,11 +1869,6 @@ export interface ITokenizedModel extends ITextModel {
*/
getLineContext
(
lineNumber
:
number
):
ILineContext
;
/**
* @internal
*/
_getLineModeTransitions
(
lineNumber
:
number
):
ModeTransition
[];
/**
* Get the current language mode associated with the model.
*/
...
...
src/vs/editor/common/model/textModelWithTokens.ts
浏览文件 @
628d2a46
...
...
@@ -500,16 +500,21 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
// Having tokens allows implementing additional helper methods
_lineIsTokenized
(
lineNumber
:
number
):
boolean
{
return
this
.
_invalidLineStartIndex
>
lineNumber
-
1
;
}
protected
_getWordDefinition
():
RegExp
{
return
WordHelper
.
massageWordDefinitionOf
(
this
.
getModeId
());
}
public
getWordAtPosition
(
position
:
editorCommon
.
IPosition
):
editorCommon
.
IWordAtPosition
{
return
WordHelper
.
getWordAtPosition
(
this
,
this
.
validatePosition
(
position
));
public
getWordAtPosition
(
_position
:
editorCommon
.
IPosition
):
editorCommon
.
IWordAtPosition
{
let
position
=
this
.
validatePosition
(
_position
);
let
lineContent
=
this
.
getLineContent
(
position
.
lineNumber
);
if
(
this
.
_invalidLineStartIndex
<=
position
.
lineNumber
)
{
// this line is not tokenized
return
WordHelper
.
getWordAtPosition
(
lineContent
,
position
.
column
,
this
.
getModeId
(),
null
);
}
let
modeTransitions
=
this
.
_getLineModeTransitions
(
position
.
lineNumber
);
return
WordHelper
.
getWordAtPosition
(
lineContent
,
position
.
column
,
this
.
getModeId
(),
modeTransitions
);
}
public
getWordUntilPosition
(
position
:
editorCommon
.
IPosition
):
editorCommon
.
IWordAtPosition
{
...
...
src/vs/editor/common/model/textModelWithTokensHelpers.ts
浏览文件 @
628d2a46
...
...
@@ -4,30 +4,16 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
I
Position
,
I
WordAtPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IWordAtPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ModeTransition
}
from
'
vs/editor/common/core/modeTransition
'
;
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
getWordAtText
,
ensureValidWordDefinition
}
from
'
vs/editor/common/model/wordHelper
'
;
export
interface
ITextSource
{
_lineIsTokenized
(
lineNumber
:
number
):
boolean
;
getLineContent
(
lineNumber
:
number
):
string
;
getModeId
():
string
;
_getLineModeTransitions
(
lineNumber
:
number
):
ModeTransition
[];
}
export
class
WordHelper
{
private
static
_safeGetWordDefinition
(
modeId
:
string
):
RegExp
{
return
LanguageConfigurationRegistry
.
getWordDefinition
(
modeId
);
}
public
static
massageWordDefinitionOf
(
modeId
:
string
):
RegExp
{
return
ensureValidWordDefinition
(
WordHelper
.
_safeGetWordDefinition
(
modeId
));
let
wordDefinition
=
LanguageConfigurationRegistry
.
getWordDefinition
(
modeId
);
return
ensureValidWordDefinition
(
wordDefinition
);
}
private
static
_getWordAtColumn
(
txt
:
string
,
column
:
number
,
modeIndex
:
number
,
modeTransitions
:
ModeTransition
[]):
IWordAtPosition
{
...
...
@@ -41,23 +27,21 @@ export class WordHelper {
);
}
public
static
getWordAtPosition
(
textSource
:
ITextSource
,
position
:
IPosition
):
IWordAtPosition
{
public
static
getWordAtPosition
(
lineContent
:
string
,
column
:
number
,
topModeId
:
string
,
modeTransitions
:
ModeTransition
[]
):
IWordAtPosition
{
if
(
!
textSource
.
_lineIsTokenized
(
position
.
lineNumber
)
)
{
return
getWordAtText
(
position
.
column
,
WordHelper
.
massageWordDefinitionOf
(
textSource
.
getModeId
()),
textSource
.
getLineContent
(
position
.
lineNumber
)
,
0
);
if
(
!
modeTransitions
||
modeTransitions
.
length
===
0
)
{
return
getWordAtText
(
column
,
WordHelper
.
massageWordDefinitionOf
(
topModeId
),
lineContent
,
0
);
}
let
result
:
IWordAtPosition
=
null
;
let
txt
=
textSource
.
getLineContent
(
position
.
lineNumber
);
let
modeTransitions
=
textSource
.
_getLineModeTransitions
(
position
.
lineNumber
);
let
columnIndex
=
position
.
column
-
1
;
let
columnIndex
=
column
-
1
;
let
modeIndex
=
ModeTransition
.
findIndexInSegmentsArray
(
modeTransitions
,
columnIndex
);
result
=
WordHelper
.
_getWordAtColumn
(
txt
,
position
.
column
,
modeIndex
,
modeTransitions
);
result
=
WordHelper
.
_getWordAtColumn
(
lineContent
,
column
,
modeIndex
,
modeTransitions
);
if
(
!
result
&&
modeIndex
>
0
&&
modeTransitions
[
modeIndex
].
startIndex
===
columnIndex
)
{
// The position is right at the beginning of `modeIndex`, so try looking at `modeIndex` - 1 too
result
=
WordHelper
.
_getWordAtColumn
(
txt
,
position
.
column
,
modeIndex
-
1
,
modeTransitions
);
result
=
WordHelper
.
_getWordAtColumn
(
lineContent
,
column
,
modeIndex
-
1
,
modeTransitions
);
}
return
result
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录