Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
297b28ab
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,发现更多精彩内容 >>
提交
297b28ab
编写于
11月 05, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prepare type cursor command for moving out of oneCursor
上级
ed259cc8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
83 deletion
+85
-83
src/vs/editor/common/controller/cursorCommon.ts
src/vs/editor/common/controller/cursorCommon.ts
+6
-0
src/vs/editor/common/controller/oneCursor.ts
src/vs/editor/common/controller/oneCursor.ts
+79
-83
未找到文件。
src/vs/editor/common/controller/cursorCommon.ts
浏览文件 @
297b28ab
...
...
@@ -26,6 +26,9 @@ export class CursorConfiguration {
public
readonly
wordSeparators
:
string
;
public
readonly
autoClosingBrackets
:
boolean
;
public
readonly
autoClosingPairsOpen
:
CharacterMap
;
public
readonly
autoClosingPairsClose
:
CharacterMap
;
public
readonly
surroundingPairs
:
CharacterMap
;
public
readonly
electricChars
:
{
[
key
:
string
]:
boolean
;
};
public
static
shouldRecreate
(
e
:
IConfigurationChangedEvent
):
boolean
{
return
(
...
...
@@ -52,6 +55,9 @@ export class CursorConfiguration {
this
.
wordSeparators
=
c
.
wordSeparators
;
this
.
autoClosingBrackets
=
c
.
autoClosingBrackets
;
this
.
autoClosingPairsOpen
=
modeConfiguration
.
autoClosingPairsOpen
;
this
.
autoClosingPairsClose
=
modeConfiguration
.
autoClosingPairsClose
;
this
.
surroundingPairs
=
modeConfiguration
.
surroundingPairs
;
this
.
electricChars
=
modeConfiguration
.
electricChars
;
}
public
normalizeIndentation
(
str
:
string
):
string
{
...
...
src/vs/editor/common/controller/oneCursor.ts
浏览文件 @
297b28ab
...
...
@@ -1215,13 +1215,7 @@ export class OneCursorOp {
// -------------------- START type interceptors & co.
private
static
_typeInterceptorEnter
(
cursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
ch
!==
'
\n
'
)
{
return
false
;
}
return
this
.
_enter
(
cursor
,
false
,
ctx
,
cursor
.
modelState
.
selection
);
}
public
static
lineInsertBefore
(
cursor
:
OneCursor
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
lineNumber
=
cursor
.
modelState
.
position
.
lineNumber
;
...
...
@@ -1254,61 +1248,68 @@ export class OneCursorOp {
);
}
private
static
_typeInterceptor
AutoClosingCloseChar
(
cursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
!
cursor
.
config
.
autoClosingBrackets
)
{
return
false
;
private
static
_typeInterceptor
Enter
(
config
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
ch
!==
'
\n
'
)
{
return
null
;
}
let
selection
=
cursor
.
modelState
.
selection
;
return
TypeOperations
.
_enter
(
config
,
model
,
false
,
cursor
.
selection
);
}
if
(
!
selection
.
isEmpty
()
||
!
cursor
.
modeConfiguration
.
autoClosingPairsClose
.
hasOwnProperty
(
ch
))
{
return
false
;
private
static
_typeInterceptorAutoClosingCloseChar
(
config
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
position
=
cursor
.
modelState
.
position
;
let
selection
=
cursor
.
selection
;
if
(
!
selection
.
isEmpty
()
||
!
config
.
autoClosingPairsClose
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
position
=
cursor
.
position
;
let
lineText
=
cursor
.
model
.
getLineContent
(
position
.
lineNumber
);
let
beforeCharacter
=
lineText
[
position
.
column
-
1
]
;
let
lineText
=
model
.
getLineContent
(
position
.
lineNumber
);
let
beforeCharacter
=
lineText
.
charAt
(
position
.
column
-
1
)
;
if
(
beforeCharacter
!==
ch
)
{
return
false
;
return
null
;
}
let
typeSelection
=
new
Range
(
position
.
lineNumber
,
position
.
column
,
position
.
lineNumber
,
position
.
column
+
1
);
ctx
.
executeCommand
=
new
ReplaceCommand
(
typeSelection
,
ch
);
return
true
;
return
new
EditOperationResult
(
new
ReplaceCommand
(
typeSelection
,
ch
));
}
private
static
_typeInterceptorAutoClosingOpenChar
(
c
ursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
!
c
ursor
.
c
onfig
.
autoClosingBrackets
)
{
return
false
;
private
static
_typeInterceptorAutoClosingOpenChar
(
c
onfig
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
modelState
.
selection
;
let
selection
=
cursor
.
selection
;
if
(
!
selection
.
isEmpty
()
||
!
c
ursor
.
modeConfiguration
.
autoClosingPairsOpen
.
hasOwnProperty
(
ch
))
{
return
false
;
if
(
!
selection
.
isEmpty
()
||
!
c
onfig
.
autoClosingPairsOpen
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
position
=
cursor
.
modelState
.
position
;
let
lineText
=
cursor
.
model
.
getLineContent
(
position
.
lineNumber
);
let
beforeCharacter
=
lineText
[
position
.
column
-
1
]
;
let
position
=
cursor
.
position
;
let
lineText
=
model
.
getLineContent
(
position
.
lineNumber
);
let
beforeCharacter
=
lineText
.
charAt
(
position
.
column
-
1
)
;
// Only consider auto closing the pair if a space follows or if another autoclosed pair follows
if
(
beforeCharacter
)
{
let
isBeforeCloseBrace
=
false
;
for
(
let
closeBrace
in
c
ursor
.
modeConfiguration
.
autoClosingPairsClose
)
{
for
(
let
closeBrace
in
c
onfig
.
autoClosingPairsClose
)
{
if
(
beforeCharacter
===
closeBrace
)
{
isBeforeCloseBrace
=
true
;
break
;
}
}
if
(
!
isBeforeCloseBrace
&&
!
/
\s
/
.
test
(
beforeCharacter
))
{
return
false
;
return
null
;
}
}
let
lineTokens
=
cursor
.
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
lineTokens
=
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
shouldAutoClosePair
=
false
;
try
{
...
...
@@ -1318,30 +1319,31 @@ export class OneCursorOp {
}
if
(
!
shouldAutoClosePair
)
{
return
false
;
return
null
;
}
ctx
.
shouldPushStackElementBefore
=
true
;
let
closeCharacter
=
cursor
.
modeConfiguration
.
autoClosingPairsOpen
[
ch
];
ctx
.
executeCommand
=
new
ReplaceCommandWithOffsetCursorState
(
selection
,
ch
+
closeCharacter
,
0
,
-
closeCharacter
.
length
);
return
true
;
let
closeCharacter
=
config
.
autoClosingPairsOpen
[
ch
];
return
new
EditOperationResult
(
new
ReplaceCommandWithOffsetCursorState
(
selection
,
ch
+
closeCharacter
,
0
,
-
closeCharacter
.
length
),
{
shouldPushStackElementBefore
:
true
,
shouldPushStackElementAfter
:
false
});
}
private
static
_typeInterceptorSurroundSelection
(
c
ursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
!
c
ursor
.
c
onfig
.
autoClosingBrackets
)
{
return
false
;
private
static
_typeInterceptorSurroundSelection
(
c
onfig
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
modelState
.
selection
;
let
selection
=
cursor
.
selection
;
if
(
selection
.
isEmpty
()
||
!
c
ursor
.
modeConfiguration
.
surroundingPairs
.
hasOwnProperty
(
ch
))
{
return
false
;
if
(
selection
.
isEmpty
()
||
!
c
onfig
.
surroundingPairs
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
selectionContainsOnlyWhitespace
=
true
;
for
(
let
lineNumber
=
selection
.
startLineNumber
;
lineNumber
<=
selection
.
endLineNumber
;
lineNumber
++
)
{
let
lineText
=
cursor
.
model
.
getLineContent
(
lineNumber
);
let
lineText
=
model
.
getLineContent
(
lineNumber
);
let
startIndex
=
(
lineNumber
===
selection
.
startLineNumber
?
selection
.
startColumn
-
1
:
0
);
let
endIndex
=
(
lineNumber
===
selection
.
endLineNumber
?
selection
.
endColumn
-
1
:
lineText
.
length
);
for
(
let
charIndex
=
startIndex
;
charIndex
<
endIndex
;
charIndex
++
)
{
...
...
@@ -1359,24 +1361,24 @@ export class OneCursorOp {
}
if
(
selectionContainsOnlyWhitespace
)
{
return
false
;
return
null
;
}
let
closeCharacter
=
c
ursor
.
modeConfiguration
.
surroundingPairs
[
ch
];
let
closeCharacter
=
c
onfig
.
surroundingPairs
[
ch
];
ctx
.
shouldPushStackElementBefore
=
true
;
ctx
.
shouldPushStackElementAfter
=
true
;
ctx
.
executeCommand
=
new
SurroundSelectionCommand
(
selection
,
ch
,
closeCharacter
);
return
true
;
return
new
EditOperationResult
(
new
SurroundSelectionCommand
(
selection
,
ch
,
closeCharacter
),
{
shouldPushStackElementBefore
:
true
,
shouldPushStackElementAfter
:
true
})
;
}
private
static
_typeInterceptorElectricChar
(
c
ursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
!
c
ursor
.
modeConfiguration
.
electricChars
.
hasOwnProperty
(
ch
))
{
return
false
;
private
static
_typeInterceptorElectricChar
(
c
onfig
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
c
onfig
.
electricChars
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
position
=
cursor
.
modelState
.
position
;
let
lineTokens
=
cursor
.
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
position
=
cursor
.
position
;
let
lineTokens
=
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
electricAction
:
IElectricAction
;
try
{
...
...
@@ -1386,40 +1388,43 @@ export class OneCursorOp {
}
if
(
!
electricAction
)
{
return
false
;
return
null
;
}
if
(
electricAction
.
appendText
)
{
ctx
.
shouldPushStackElementAfter
=
true
;
ctx
.
executeCommand
=
new
ReplaceCommandWithOffsetCursorState
(
cursor
.
modelState
.
selection
,
ch
+
electricAction
.
appendText
,
0
,
-
electricAction
.
appendText
.
length
);
return
true
;
return
new
EditOperationResult
(
new
ReplaceCommandWithOffsetCursorState
(
cursor
.
selection
,
ch
+
electricAction
.
appendText
,
0
,
-
electricAction
.
appendText
.
length
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
true
});
}
if
(
electricAction
.
matchOpenBracket
)
{
let
match
=
cursor
.
model
.
findMatchingBracketUp
(
electricAction
.
matchOpenBracket
,
{
let
match
=
model
.
findMatchingBracketUp
(
electricAction
.
matchOpenBracket
,
{
lineNumber
:
position
.
lineNumber
,
column
:
position
.
column
});
if
(
match
)
{
let
matchLine
=
cursor
.
model
.
getLineContent
(
match
.
startLineNumber
);
let
matchLine
=
model
.
getLineContent
(
match
.
startLineNumber
);
let
matchLineIndentation
=
strings
.
getLeadingWhitespace
(
matchLine
);
let
newIndentation
=
c
ursor
.
model
.
normalizeIndentation
(
matchLineIndentation
);
let
newIndentation
=
c
onfig
.
normalizeIndentation
(
matchLineIndentation
);
let
lineText
=
cursor
.
model
.
getLineContent
(
position
.
lineNumber
);
let
lineFirstNonBlankColumn
=
cursor
.
model
.
getLineFirstNonWhitespaceColumn
(
position
.
lineNumber
)
||
position
.
column
;
let
lineText
=
model
.
getLineContent
(
position
.
lineNumber
);
let
lineFirstNonBlankColumn
=
model
.
getLineFirstNonWhitespaceColumn
(
position
.
lineNumber
)
||
position
.
column
;
let
prefix
=
lineText
.
substring
(
lineFirstNonBlankColumn
-
1
,
position
.
column
-
1
);
let
typeText
=
newIndentation
+
prefix
+
ch
;
let
typeSelection
=
new
Range
(
position
.
lineNumber
,
1
,
position
.
lineNumber
,
position
.
column
);
ctx
.
shouldPushStackElementAfter
=
true
;
ctx
.
executeCommand
=
new
ReplaceCommand
(
typeSelection
,
typeText
);
return
true
;
return
new
EditOperationResult
(
new
ReplaceCommand
(
typeSelection
,
typeText
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
true
});
}
}
return
false
;
return
null
;
}
public
static
actualType
(
cursor
:
OneCursor
,
text
:
string
,
keepPosition
:
boolean
,
ctx
:
IOneCursorOperationContext
):
boolean
{
...
...
@@ -1428,25 +1433,16 @@ export class OneCursorOp {
}
public
static
type
(
cursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
r
:
EditOperationResult
=
null
;
if
(
this
.
_typeInterceptorEnter
(
cursor
,
ch
,
ctx
))
{
return
true
;
}
if
(
this
.
_typeInterceptorAutoClosingCloseChar
(
cursor
,
ch
,
ctx
))
{
return
true
;
}
if
(
this
.
_typeInterceptorAutoClosingOpenChar
(
cursor
,
ch
,
ctx
))
{
return
true
;
}
if
(
this
.
_typeInterceptorSurroundSelection
(
cursor
,
ch
,
ctx
))
{
return
true
;
}
r
=
r
||
this
.
_typeInterceptorEnter
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
,
ch
);
r
=
r
||
this
.
_typeInterceptorAutoClosingCloseChar
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
,
ch
);
r
=
r
||
this
.
_typeInterceptorAutoClosingOpenChar
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
,
ch
);
r
=
r
||
this
.
_typeInterceptorSurroundSelection
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
,
ch
);
r
=
r
||
this
.
_typeInterceptorElectricChar
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
,
ch
);
if
(
this
.
_typeInterceptorElectricChar
(
cursor
,
ch
,
ctx
)
)
{
return
t
rue
;
if
(
r
)
{
return
t
his
.
_applyEditOperation
(
ctx
,
r
)
;
}
ctx
.
executeCommand
=
TypeOperations
.
typeCommand
(
cursor
.
modelState
.
selection
,
ch
,
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录