Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d86c17e7
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,发现更多精彩内容 >>
提交
d86c17e7
编写于
3月 27, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add CursorContext
上级
6fdf8a1e
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
435 addition
and
483 deletion
+435
-483
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+93
-71
src/vs/editor/common/controller/cursorCollection.ts
src/vs/editor/common/controller/cursorCollection.ts
+23
-92
src/vs/editor/common/controller/cursorCommon.ts
src/vs/editor/common/controller/cursorCommon.ts
+60
-7
src/vs/editor/common/controller/oneCursor.ts
src/vs/editor/common/controller/oneCursor.ts
+259
-313
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
d86c17e7
此差异已折叠。
点击以展开。
src/vs/editor/common/controller/cursorCollection.ts
浏览文件 @
d86c17e7
...
...
@@ -4,13 +4,10 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
IModeConfiguration
,
IOneCursorState
,
IViewModelHelper
,
OneCursor
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
IOneCursorState
,
OneCursor
,
CursorContext
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
IConfiguration
,
IModel
,
ISelection
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IAutoClosingPair
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
import
{
ISelection
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
CursorState
}
from
'
vs/editor/common/controller/cursorCommon
'
;
export
interface
ICursorCollectionState
{
...
...
@@ -20,9 +17,7 @@ export interface ICursorCollectionState {
export
class
CursorCollection
{
private
model
:
IModel
;
private
configuration
:
IConfiguration
;
private
modeConfiguration
:
IModeConfiguration
;
private
context
:
CursorContext
;
private
primaryCursor
:
OneCursor
;
private
secondaryCursors
:
OneCursor
[];
...
...
@@ -30,28 +25,26 @@ export class CursorCollection {
// An index which identifies the last cursor that was added / moved (think Ctrl+drag)
private
lastAddedCursorIndex
:
number
;
private
viewModelHelper
:
IViewModelHelper
;
constructor
(
model
:
IModel
,
configuration
:
IConfiguration
,
viewModelHelper
:
IViewModelHelper
)
{
this
.
model
=
model
;
this
.
configuration
=
configuration
;
this
.
viewModelHelper
=
viewModelHelper
;
this
.
modeConfiguration
=
this
.
getModeConfiguration
();
this
.
primaryCursor
=
new
OneCursor
(
this
.
model
,
this
.
configuration
,
this
.
modeConfiguration
,
this
.
viewModelHelper
);
constructor
(
context
:
CursorContext
)
{
this
.
context
=
context
;
this
.
primaryCursor
=
new
OneCursor
(
context
);
this
.
secondaryCursors
=
[];
this
.
lastAddedCursorIndex
=
0
;
}
public
dispose
():
void
{
this
.
primaryCursor
.
dispose
();
this
.
primaryCursor
.
dispose
(
this
.
context
);
this
.
killSecondaryCursors
();
}
public
updateContext
(
context
:
CursorContext
):
void
{
this
.
context
=
context
;
}
public
ensureValidState
():
void
{
this
.
primaryCursor
.
ensureValidState
();
this
.
primaryCursor
.
ensureValidState
(
this
.
context
);
for
(
let
i
=
0
,
len
=
this
.
secondaryCursors
.
length
;
i
<
len
;
i
++
)
{
this
.
secondaryCursors
[
i
].
ensureValidState
();
this
.
secondaryCursors
[
i
].
ensureValidState
(
this
.
context
);
}
}
...
...
@@ -63,22 +56,14 @@ export class CursorCollection {
}
public
restoreState
(
state
:
ICursorCollectionState
):
void
{
this
.
primaryCursor
.
restoreState
(
state
.
primary
);
this
.
primaryCursor
.
restoreState
(
this
.
context
,
state
.
primary
);
this
.
killSecondaryCursors
();
for
(
var
i
=
0
;
i
<
state
.
secondary
.
length
;
i
++
)
{
this
.
addSecondaryCursor
(
null
);
this
.
secondaryCursors
[
i
].
restoreState
(
state
.
secondary
[
i
]);
this
.
secondaryCursors
[
i
].
restoreState
(
this
.
context
,
state
.
secondary
[
i
]);
}
}
public
updateMode
():
void
{
this
.
modeConfiguration
=
this
.
getModeConfiguration
();
this
.
getAll
().
forEach
((
cursor
)
=>
{
cursor
.
updateModeConfiguration
(
this
.
modeConfiguration
);
});
}
public
getAll
():
OneCursor
[]
{
var
result
:
OneCursor
[]
=
[];
result
.
push
(
this
.
primaryCursor
);
...
...
@@ -147,7 +132,7 @@ export class CursorCollection {
}
public
setSelections
(
selections
:
ISelection
[],
viewSelections
?:
ISelection
[]):
void
{
this
.
primaryCursor
.
setSelection
(
selections
[
0
],
viewSelections
?
viewSelections
[
0
]
:
null
);
this
.
primaryCursor
.
setSelection
(
this
.
context
,
selections
[
0
],
viewSelections
?
viewSelections
[
0
]
:
null
);
this
.
_setSecondarySelections
(
selections
.
slice
(
1
),
viewSelections
?
viewSelections
.
slice
(
1
)
:
null
);
}
...
...
@@ -159,7 +144,7 @@ export class CursorCollection {
if
(
states
===
null
)
{
return
;
}
this
.
primaryCursor
.
setState
(
states
[
0
].
modelState
,
states
[
0
].
viewState
,
ensureInEditableRange
);
this
.
primaryCursor
.
setState
(
this
.
context
,
states
[
0
].
modelState
,
states
[
0
].
viewState
,
ensureInEditableRange
);
this
.
_setSecondaryStates
(
states
.
slice
(
1
),
ensureInEditableRange
);
}
...
...
@@ -183,7 +168,7 @@ export class CursorCollection {
}
for
(
let
i
=
0
;
i
<
secondaryStatesLength
;
i
++
)
{
this
.
secondaryCursors
[
i
].
setState
(
secondaryStates
[
i
].
modelState
,
secondaryStates
[
i
].
viewState
,
ensureInEditableRange
);
this
.
secondaryCursors
[
i
].
setState
(
this
.
context
,
secondaryStates
[
i
].
modelState
,
secondaryStates
[
i
].
viewState
,
ensureInEditableRange
);
}
}
...
...
@@ -196,9 +181,9 @@ export class CursorCollection {
}
public
addSecondaryCursor
(
selection
:
ISelection
):
void
{
var
newCursor
=
new
OneCursor
(
this
.
model
,
this
.
configuration
,
this
.
modeConfiguration
,
this
.
viewModelHelper
);
var
newCursor
=
new
OneCursor
(
this
.
context
);
if
(
selection
)
{
newCursor
.
setSelection
(
selection
);
newCursor
.
setSelection
(
this
.
context
,
selection
);
}
this
.
secondaryCursors
.
push
(
newCursor
);
this
.
lastAddedCursorIndex
=
this
.
secondaryCursors
.
length
;
...
...
@@ -237,7 +222,7 @@ export class CursorCollection {
for
(
var
i
=
0
;
i
<
secondarySelectionsLength
;
i
++
)
{
if
(
secondarySelections
[
i
])
{
this
.
secondaryCursors
[
i
].
setSelection
(
secondarySelections
[
i
],
viewSelections
?
viewSelections
[
i
]
:
null
);
this
.
secondaryCursors
[
i
].
setSelection
(
this
.
context
,
secondarySelections
[
i
],
viewSelections
?
viewSelections
[
i
]
:
null
);
}
}
...
...
@@ -248,7 +233,7 @@ export class CursorCollection {
if
(
this
.
lastAddedCursorIndex
>=
removeIndex
+
1
)
{
this
.
lastAddedCursorIndex
--
;
}
this
.
secondaryCursors
[
removeIndex
].
dispose
();
this
.
secondaryCursors
[
removeIndex
].
dispose
(
this
.
context
);
this
.
secondaryCursors
.
splice
(
removeIndex
,
1
);
}
...
...
@@ -317,7 +302,7 @@ export class CursorCollection {
}
sortedCursors
[
winnerSortedCursorIndex
].
selection
=
resultingSelection
;
cursors
[
winnerIndex
].
setSelection
(
resultingSelection
);
cursors
[
winnerIndex
].
setSelection
(
this
.
context
,
resultingSelection
);
}
for
(
var
j
=
0
;
j
<
sortedCursors
.
length
;
j
++
)
{
...
...
@@ -334,58 +319,4 @@ export class CursorCollection {
}
}
}
private
getModeConfiguration
():
IModeConfiguration
{
let
i
:
number
;
let
result
:
IModeConfiguration
=
{
electricChars
:
{},
autoClosingPairsOpen
:
{},
autoClosingPairsClose
:
{},
surroundingPairs
:
{}
};
let
electricChars
:
string
[]
=
null
;
try
{
electricChars
=
LanguageConfigurationRegistry
.
getElectricCharacters
(
this
.
model
.
getLanguageIdentifier
().
id
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
electricChars
=
null
;
}
if
(
electricChars
)
{
for
(
i
=
0
;
i
<
electricChars
.
length
;
i
++
)
{
result
.
electricChars
[
electricChars
[
i
]]
=
true
;
}
}
let
autoClosingPairs
:
IAutoClosingPair
[];
try
{
autoClosingPairs
=
LanguageConfigurationRegistry
.
getAutoClosingPairs
(
this
.
model
.
getLanguageIdentifier
().
id
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
autoClosingPairs
=
null
;
}
if
(
autoClosingPairs
)
{
for
(
i
=
0
;
i
<
autoClosingPairs
.
length
;
i
++
)
{
result
.
autoClosingPairsOpen
[
autoClosingPairs
[
i
].
open
]
=
autoClosingPairs
[
i
].
close
;
result
.
autoClosingPairsClose
[
autoClosingPairs
[
i
].
close
]
=
autoClosingPairs
[
i
].
open
;
}
}
let
surroundingPairs
:
IAutoClosingPair
[];
try
{
surroundingPairs
=
LanguageConfigurationRegistry
.
getSurroundingPairs
(
this
.
model
.
getLanguageIdentifier
().
id
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
surroundingPairs
=
null
;
}
if
(
surroundingPairs
)
{
for
(
i
=
0
;
i
<
surroundingPairs
.
length
;
i
++
)
{
result
.
surroundingPairs
[
surroundingPairs
[
i
].
open
]
=
surroundingPairs
[
i
].
close
;
}
}
return
result
;
}
}
src/vs/editor/common/controller/cursorCommon.ts
浏览文件 @
d86c17e7
...
...
@@ -7,11 +7,14 @@
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
IModeConfiguration
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
ICommand
,
IConfigurationChangedEvent
,
TextModelResolvedOptions
,
IConfiguration
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
IAutoClosingPair
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
export
interface
CharacterMap
{
[
char
:
string
]:
string
;
...
...
@@ -42,10 +45,10 @@ export class CursorConfiguration {
}
constructor
(
languageIdentifier
:
LanguageIdentifier
,
oneIndent
:
string
,
modelOptions
:
TextModelResolvedOptions
,
configuration
:
IConfiguration
,
modeConfiguration
:
IModeConfiguration
configuration
:
IConfiguration
)
{
let
c
=
configuration
.
editor
;
...
...
@@ -56,15 +59,65 @@ export class CursorConfiguration {
this
.
useTabStops
=
c
.
useTabStops
;
this
.
wordSeparators
=
c
.
wordSeparators
;
this
.
autoClosingBrackets
=
c
.
autoClosingBrackets
;
this
.
autoClosingPairsOpen
=
modeConfiguration
.
autoClosingPairsOpen
;
this
.
autoClosingPairsClose
=
modeConfiguration
.
autoClosingPairsClose
;
this
.
surroundingPairs
=
modeConfiguration
.
surroundingPairs
;
this
.
electricChars
=
modeConfiguration
.
electricChars
;
this
.
autoClosingPairsOpen
=
{};
this
.
autoClosingPairsClose
=
{};
this
.
surroundingPairs
=
{};
this
.
electricChars
=
{};
let
electricChars
=
CursorConfiguration
.
_getElectricCharacters
(
languageIdentifier
);
if
(
electricChars
)
{
for
(
let
i
=
0
;
i
<
electricChars
.
length
;
i
++
)
{
this
.
electricChars
[
electricChars
[
i
]]
=
true
;
}
}
let
autoClosingPairs
=
CursorConfiguration
.
_getAutoClosingPairs
(
languageIdentifier
);
if
(
autoClosingPairs
)
{
for
(
let
i
=
0
;
i
<
autoClosingPairs
.
length
;
i
++
)
{
this
.
autoClosingPairsOpen
[
autoClosingPairs
[
i
].
open
]
=
autoClosingPairs
[
i
].
close
;
this
.
autoClosingPairsClose
[
autoClosingPairs
[
i
].
close
]
=
autoClosingPairs
[
i
].
open
;
}
}
let
surroundingPairs
=
CursorConfiguration
.
_getSurroundingPairs
(
languageIdentifier
);
if
(
surroundingPairs
)
{
for
(
let
i
=
0
;
i
<
surroundingPairs
.
length
;
i
++
)
{
this
.
surroundingPairs
[
surroundingPairs
[
i
].
open
]
=
surroundingPairs
[
i
].
close
;
}
}
}
public
normalizeIndentation
(
str
:
string
):
string
{
return
TextModel
.
normalizeIndentation
(
str
,
this
.
tabSize
,
this
.
insertSpaces
);
}
private
static
_getElectricCharacters
(
languageIdentifier
:
LanguageIdentifier
):
string
[]
{
try
{
return
LanguageConfigurationRegistry
.
getElectricCharacters
(
languageIdentifier
.
id
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
return
null
;
}
}
private
static
_getAutoClosingPairs
(
languageIdentifier
:
LanguageIdentifier
):
IAutoClosingPair
[]
{
try
{
return
LanguageConfigurationRegistry
.
getAutoClosingPairs
(
languageIdentifier
.
id
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
return
null
;
}
}
private
static
_getSurroundingPairs
(
languageIdentifier
:
LanguageIdentifier
):
IAutoClosingPair
[]
{
try
{
return
LanguageConfigurationRegistry
.
getSurroundingPairs
(
languageIdentifier
.
id
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
return
null
;
}
}
}
/**
...
...
src/vs/editor/common/controller/oneCursor.ts
浏览文件 @
d86c17e7
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录