Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
af1cf7a4
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,发现更多精彩内容 >>
提交
af1cf7a4
编写于
11月 05, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move type operations out of oneCursor
上级
297b28ab
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
298 addition
and
279 deletion
+298
-279
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+1
-1
src/vs/editor/common/controller/cursorCommon.ts
src/vs/editor/common/controller/cursorCommon.ts
+48
-1
src/vs/editor/common/controller/cursorDeleteOperations.ts
src/vs/editor/common/controller/cursorDeleteOperations.ts
+1
-49
src/vs/editor/common/controller/cursorTypeOperations.ts
src/vs/editor/common/controller/cursorTypeOperations.ts
+225
-3
src/vs/editor/common/controller/cursorWordOperations.ts
src/vs/editor/common/controller/cursorWordOperations.ts
+2
-2
src/vs/editor/common/controller/oneCursor.ts
src/vs/editor/common/controller/oneCursor.ts
+21
-223
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
af1cf7a4
...
@@ -1402,7 +1402,7 @@ export class Cursor extends EventEmitter {
...
@@ -1402,7 +1402,7 @@ export class Cursor extends EventEmitter {
}
}
}
else
{
}
else
{
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
actualType
(
oneCursor
,
text
,
false
,
oneCtx
));
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
actualType
(
oneCursor
,
text
,
oneCtx
));
}
}
return
true
;
return
true
;
...
...
src/vs/editor/common/controller/cursorCommon.ts
浏览文件 @
af1cf7a4
...
@@ -8,7 +8,7 @@ import { Position } from 'vs/editor/common/core/position';
...
@@ -8,7 +8,7 @@ import { Position } from 'vs/editor/common/core/position';
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
IModeConfiguration
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
IModeConfiguration
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
IConfigurationChangedEvent
,
TextModelResolvedOptions
,
IConfiguration
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ICo
mmand
,
CursorChangeReason
,
ICo
nfigurationChangedEvent
,
TextModelResolvedOptions
,
IConfiguration
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
export
interface
CharacterMap
{
export
interface
CharacterMap
{
...
@@ -74,6 +74,53 @@ export interface ICursorSimpleModel {
...
@@ -74,6 +74,53 @@ export interface ICursorSimpleModel {
getLineLastNonWhitespaceColumn
(
lineNumber
:
number
):
number
;
getLineLastNonWhitespaceColumn
(
lineNumber
:
number
):
number
;
}
}
export
class
EditOperationResult
{
_editOperationBrand
:
void
;
readonly
command
:
ICommand
;
readonly
shouldPushStackElementBefore
:
boolean
;
readonly
shouldPushStackElementAfter
:
boolean
;
readonly
isAutoWhitespaceCommand
:
boolean
;
readonly
shouldRevealHorizontal
:
boolean
;
readonly
cursorPositionChangeReason
:
CursorChangeReason
;
constructor
(
command
:
ICommand
,
opts
?:
{
shouldPushStackElementBefore
:
boolean
;
shouldPushStackElementAfter
:
boolean
;
isAutoWhitespaceCommand
?:
boolean
;
shouldRevealHorizontal
?:
boolean
;
cursorPositionChangeReason
?:
CursorChangeReason
;
}
)
{
this
.
command
=
command
;
this
.
shouldPushStackElementBefore
=
false
;
this
.
shouldPushStackElementAfter
=
false
;
this
.
isAutoWhitespaceCommand
=
false
;
this
.
shouldRevealHorizontal
=
true
;
this
.
cursorPositionChangeReason
=
CursorChangeReason
.
NotSet
;
if
(
typeof
opts
!==
'
undefined
'
)
{
if
(
typeof
opts
.
shouldPushStackElementBefore
!==
'
undefined
'
)
{
this
.
shouldPushStackElementBefore
=
opts
.
shouldPushStackElementBefore
;
}
if
(
typeof
opts
.
shouldPushStackElementAfter
!==
'
undefined
'
)
{
this
.
shouldPushStackElementAfter
=
opts
.
shouldPushStackElementAfter
;
}
if
(
typeof
opts
.
isAutoWhitespaceCommand
!==
'
undefined
'
)
{
this
.
isAutoWhitespaceCommand
=
opts
.
isAutoWhitespaceCommand
;
}
if
(
typeof
opts
.
shouldRevealHorizontal
!==
'
undefined
'
)
{
this
.
shouldRevealHorizontal
=
opts
.
shouldRevealHorizontal
;
}
if
(
typeof
opts
.
cursorPositionChangeReason
!==
'
undefined
'
)
{
this
.
cursorPositionChangeReason
=
opts
.
cursorPositionChangeReason
;
}
}
}
}
/**
/**
* Common operations that work and make sense both on the model and on the view model.
* Common operations that work and make sense both on the model and on the view model.
*/
*/
...
...
src/vs/editor/common/controller/cursorDeleteOperations.ts
浏览文件 @
af1cf7a4
...
@@ -5,60 +5,12 @@
...
@@ -5,60 +5,12 @@
'
use strict
'
;
'
use strict
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
EditOperationResult
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ICommand
,
CursorChangeReason
}
from
'
vs/editor/common/editorCommon
'
;
import
{
MoveOperations
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
MoveOperations
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
export
class
EditOperationResult
{
_editOperationBrand
:
void
;
readonly
command
:
ICommand
;
readonly
shouldPushStackElementBefore
:
boolean
;
readonly
shouldPushStackElementAfter
:
boolean
;
readonly
isAutoWhitespaceCommand
:
boolean
;
readonly
shouldRevealHorizontal
:
boolean
;
readonly
cursorPositionChangeReason
:
CursorChangeReason
;
constructor
(
command
:
ICommand
,
opts
?:
{
shouldPushStackElementBefore
:
boolean
;
shouldPushStackElementAfter
:
boolean
;
isAutoWhitespaceCommand
?:
boolean
;
shouldRevealHorizontal
?:
boolean
;
cursorPositionChangeReason
?:
CursorChangeReason
;
}
)
{
this
.
command
=
command
;
this
.
shouldPushStackElementBefore
=
false
;
this
.
shouldPushStackElementAfter
=
false
;
this
.
isAutoWhitespaceCommand
=
false
;
this
.
shouldRevealHorizontal
=
true
;
this
.
cursorPositionChangeReason
=
CursorChangeReason
.
NotSet
;
if
(
typeof
opts
!==
'
undefined
'
)
{
if
(
typeof
opts
.
shouldPushStackElementBefore
!==
'
undefined
'
)
{
this
.
shouldPushStackElementBefore
=
opts
.
shouldPushStackElementBefore
;
}
if
(
typeof
opts
.
shouldPushStackElementAfter
!==
'
undefined
'
)
{
this
.
shouldPushStackElementAfter
=
opts
.
shouldPushStackElementAfter
;
}
if
(
typeof
opts
.
isAutoWhitespaceCommand
!==
'
undefined
'
)
{
this
.
isAutoWhitespaceCommand
=
opts
.
isAutoWhitespaceCommand
;
}
if
(
typeof
opts
.
shouldRevealHorizontal
!==
'
undefined
'
)
{
this
.
shouldRevealHorizontal
=
opts
.
shouldRevealHorizontal
;
}
if
(
typeof
opts
.
cursorPositionChangeReason
!==
'
undefined
'
)
{
this
.
cursorPositionChangeReason
=
opts
.
cursorPositionChangeReason
;
}
}
}
}
export
class
DeleteOperations
{
export
class
DeleteOperations
{
public
static
deleteRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
):
EditOperationResult
{
public
static
deleteRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
):
EditOperationResult
{
...
...
src/vs/editor/common/controller/cursorTypeOperations.ts
浏览文件 @
af1cf7a4
...
@@ -4,18 +4,21 @@
...
@@ -4,18 +4,21 @@
*--------------------------------------------------------------------------------------------*/
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
'
use strict
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
ReplaceCommand
,
ReplaceCommandWithoutChangingPosition
,
ReplaceCommandWithOffsetCursorState
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
ReplaceCommand
,
ReplaceCommandWithoutChangingPosition
,
ReplaceCommandWithOffsetCursorState
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
EditOperationResult
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
CursorChangeReason
,
ICommand
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorChangeReason
,
ICommand
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
EditOperationResult
}
from
'
vs/editor/common/controller/cursorDeleteOperations
'
;
import
{
ShiftCommand
}
from
'
vs/editor/common/commands/shiftCommand
'
;
import
{
ShiftCommand
}
from
'
vs/editor/common/commands/shiftCommand
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
ITokenizedModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ITokenizedModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IndentAction
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
import
{
IndentAction
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
SurroundSelectionCommand
}
from
'
vs/editor/common/commands/surroundSelectionCommand
'
;
import
{
IElectricAction
}
from
'
vs/editor/common/modes/supports/electricCharacter
'
;
export
class
TypeOperations
{
export
class
TypeOperations
{
...
@@ -187,7 +190,7 @@ export class TypeOperations {
...
@@ -187,7 +190,7 @@ export class TypeOperations {
}
}
}
}
static
_enter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
keepPosition
:
boolean
,
range
:
Range
):
EditOperationResult
{
private
static
_enter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
keepPosition
:
boolean
,
range
:
Range
):
EditOperationResult
{
let
r
=
LanguageConfigurationRegistry
.
getEnterActionAtPosition
(
model
,
range
.
startLineNumber
,
range
.
startColumn
);
let
r
=
LanguageConfigurationRegistry
.
getEnterActionAtPosition
(
model
,
range
.
startLineNumber
,
range
.
startColumn
);
let
enterAction
=
r
.
enterAction
;
let
enterAction
=
r
.
enterAction
;
...
@@ -229,4 +232,223 @@ export class TypeOperations {
...
@@ -229,4 +232,223 @@ export class TypeOperations {
isAutoWhitespaceCommand
:
true
isAutoWhitespaceCommand
:
true
});
});
}
}
private
static
_typeInterceptorEnter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
ch
!==
'
\n
'
)
{
return
null
;
}
return
TypeOperations
.
_enter
(
config
,
model
,
false
,
cursor
.
selection
);
}
private
static
_typeInterceptorAutoClosingCloseChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
selection
;
if
(
!
selection
.
isEmpty
()
||
!
config
.
autoClosingPairsClose
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
position
=
cursor
.
position
;
let
lineText
=
model
.
getLineContent
(
position
.
lineNumber
);
let
beforeCharacter
=
lineText
.
charAt
(
position
.
column
-
1
);
if
(
beforeCharacter
!==
ch
)
{
return
null
;
}
let
typeSelection
=
new
Range
(
position
.
lineNumber
,
position
.
column
,
position
.
lineNumber
,
position
.
column
+
1
);
return
new
EditOperationResult
(
new
ReplaceCommand
(
typeSelection
,
ch
));
}
private
static
_typeInterceptorAutoClosingOpenChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
selection
;
if
(
!
selection
.
isEmpty
()
||
!
config
.
autoClosingPairsOpen
.
hasOwnProperty
(
ch
))
{
return
null
;
}
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
config
.
autoClosingPairsClose
)
{
if
(
beforeCharacter
===
closeBrace
)
{
isBeforeCloseBrace
=
true
;
break
;
}
}
if
(
!
isBeforeCloseBrace
&&
!
/
\s
/
.
test
(
beforeCharacter
))
{
return
null
;
}
}
let
lineTokens
=
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
shouldAutoClosePair
=
false
;
try
{
shouldAutoClosePair
=
LanguageConfigurationRegistry
.
shouldAutoClosePair
(
ch
,
lineTokens
,
position
.
column
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
if
(
!
shouldAutoClosePair
)
{
return
null
;
}
let
closeCharacter
=
config
.
autoClosingPairsOpen
[
ch
];
return
new
EditOperationResult
(
new
ReplaceCommandWithOffsetCursorState
(
selection
,
ch
+
closeCharacter
,
0
,
-
closeCharacter
.
length
),
{
shouldPushStackElementBefore
:
true
,
shouldPushStackElementAfter
:
false
});
}
private
static
_typeInterceptorSurroundSelection
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
selection
;
if
(
selection
.
isEmpty
()
||
!
config
.
surroundingPairs
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
selectionContainsOnlyWhitespace
=
true
;
for
(
let
lineNumber
=
selection
.
startLineNumber
;
lineNumber
<=
selection
.
endLineNumber
;
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
++
)
{
let
charCode
=
lineText
.
charCodeAt
(
charIndex
);
if
(
charCode
!==
CharCode
.
Tab
&&
charCode
!==
CharCode
.
Space
)
{
selectionContainsOnlyWhitespace
=
false
;
// Break outer loop
lineNumber
=
selection
.
endLineNumber
+
1
;
// Break inner loop
charIndex
=
endIndex
;
}
}
}
if
(
selectionContainsOnlyWhitespace
)
{
return
null
;
}
let
closeCharacter
=
config
.
surroundingPairs
[
ch
];
return
new
EditOperationResult
(
new
SurroundSelectionCommand
(
selection
,
ch
,
closeCharacter
),
{
shouldPushStackElementBefore
:
true
,
shouldPushStackElementAfter
:
true
});
}
private
static
_typeInterceptorElectricChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
electricChars
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
position
=
cursor
.
position
;
let
lineTokens
=
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
electricAction
:
IElectricAction
;
try
{
electricAction
=
LanguageConfigurationRegistry
.
onElectricCharacter
(
ch
,
lineTokens
,
position
.
column
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
if
(
!
electricAction
)
{
return
null
;
}
if
(
electricAction
.
appendText
)
{
return
new
EditOperationResult
(
new
ReplaceCommandWithOffsetCursorState
(
cursor
.
selection
,
ch
+
electricAction
.
appendText
,
0
,
-
electricAction
.
appendText
.
length
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
true
});
}
if
(
electricAction
.
matchOpenBracket
)
{
let
match
=
model
.
findMatchingBracketUp
(
electricAction
.
matchOpenBracket
,
{
lineNumber
:
position
.
lineNumber
,
column
:
position
.
column
});
if
(
match
)
{
let
matchLine
=
model
.
getLineContent
(
match
.
startLineNumber
);
let
matchLineIndentation
=
strings
.
getLeadingWhitespace
(
matchLine
);
let
newIndentation
=
config
.
normalizeIndentation
(
matchLineIndentation
);
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
);
return
new
EditOperationResult
(
new
ReplaceCommand
(
typeSelection
,
typeText
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
true
});
}
}
return
null
;
}
public
static
typeWithInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
let
r
:
EditOperationResult
=
null
;
r
=
r
||
this
.
_typeInterceptorEnter
(
config
,
model
,
cursor
,
ch
);
r
=
r
||
this
.
_typeInterceptorAutoClosingCloseChar
(
config
,
model
,
cursor
,
ch
);
r
=
r
||
this
.
_typeInterceptorAutoClosingOpenChar
(
config
,
model
,
cursor
,
ch
);
r
=
r
||
this
.
_typeInterceptorSurroundSelection
(
config
,
model
,
cursor
,
ch
);
r
=
r
||
this
.
_typeInterceptorElectricChar
(
config
,
model
,
cursor
,
ch
);
r
=
r
||
this
.
typeWithoutInterceptors
(
config
,
model
,
cursor
,
ch
);
return
r
;
}
public
static
typeWithoutInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
,
str
:
string
):
EditOperationResult
{
return
new
EditOperationResult
(
TypeOperations
.
typeCommand
(
cursor
.
selection
,
str
,
false
));
}
public
static
lineInsertBefore
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
):
EditOperationResult
{
let
lineNumber
=
cursor
.
position
.
lineNumber
;
if
(
lineNumber
===
1
)
{
return
new
EditOperationResult
(
new
ReplaceCommandWithoutChangingPosition
(
new
Range
(
1
,
1
,
1
,
1
),
'
\n
'
));
}
lineNumber
--
;
let
column
=
model
.
getLineMaxColumn
(
lineNumber
);
return
this
.
_enter
(
config
,
model
,
false
,
new
Range
(
lineNumber
,
column
,
lineNumber
,
column
));
}
public
static
lineInsertAfter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
):
EditOperationResult
{
let
position
=
cursor
.
position
;
let
column
=
model
.
getLineMaxColumn
(
position
.
lineNumber
);
return
this
.
_enter
(
config
,
model
,
false
,
new
Range
(
position
.
lineNumber
,
column
,
position
.
lineNumber
,
column
));
}
public
static
lineBreakInsert
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModelState
):
EditOperationResult
{
return
this
.
_enter
(
config
,
model
,
true
,
cursor
.
selection
);
}
}
}
src/vs/editor/common/controller/cursorWordOperations.ts
浏览文件 @
af1cf7a4
...
@@ -4,14 +4,14 @@
...
@@ -4,14 +4,14 @@
*--------------------------------------------------------------------------------------------*/
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
'
use strict
'
;
import
{
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
EditOperationResult
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
CharacterClassifier
}
from
'
vs/editor/common/core/characterClassifier
'
;
import
{
CharacterClassifier
}
from
'
vs/editor/common/core/characterClassifier
'
;
import
{
MoveOperationResult
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
MoveOperationResult
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
CursorChangeReason
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorChangeReason
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
DeleteOperations
,
EditOperationResult
}
from
'
vs/editor/common/controller/cursorDeleteOperations
'
;
import
{
DeleteOperations
}
from
'
vs/editor/common/controller/cursorDeleteOperations
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
...
...
src/vs/editor/common/controller/oneCursor.ts
浏览文件 @
af1cf7a4
...
@@ -4,24 +4,18 @@
...
@@ -4,24 +4,18 @@
*--------------------------------------------------------------------------------------------*/
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
'
use strict
'
;
import
{
onUnexpectedError
,
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
{
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
ReplaceCommand
,
ReplaceCommandWithOffsetCursorState
,
ReplaceCommandWithoutChangingPosition
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
SurroundSelectionCommand
}
from
'
vs/editor/common/commands/surroundSelectionCommand
'
;
import
{
CursorMoveHelper
,
IColumnSelectResult
}
from
'
vs/editor/common/controller/cursorMoveHelper
'
;
import
{
CursorMoveHelper
,
IColumnSelectResult
}
from
'
vs/editor/common/controller/cursorMoveHelper
'
;
import
{
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
EditOperationResult
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
,
SelectionDirection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Selection
,
SelectionDirection
}
from
'
vs/editor/common/core/selection
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
IElectricAction
}
from
'
vs/editor/common/modes/supports/electricCharacter
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
MoveOperations
,
MoveOperationResult
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
MoveOperations
,
MoveOperationResult
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
WordType
,
WordOperations
,
WordNavigationType
}
from
'
vs/editor/common/controller/cursorWordOperations
'
;
import
{
WordType
,
WordOperations
,
WordNavigationType
}
from
'
vs/editor/common/controller/cursorWordOperations
'
;
import
{
ColumnSelection
}
from
'
vs/editor/common/controller/cursorColumnSelection
'
;
import
{
ColumnSelection
}
from
'
vs/editor/common/controller/cursorColumnSelection
'
;
import
{
DeleteOperations
,
EditOperationResult
}
from
'
vs/editor/common/controller/cursorDeleteOperations
'
;
import
{
DeleteOperations
}
from
'
vs/editor/common/controller/cursorDeleteOperations
'
;
import
{
TypeOperations
}
from
'
vs/editor/common/controller/cursorTypeOperations
'
;
import
{
TypeOperations
}
from
'
vs/editor/common/controller/cursorTypeOperations
'
;
export
interface
IOneCursorOperationContext
{
export
interface
IOneCursorOperationContext
{
...
@@ -1218,235 +1212,39 @@ export class OneCursorOp {
...
@@ -1218,235 +1212,39 @@ export class OneCursorOp {
public
static
lineInsertBefore
(
cursor
:
OneCursor
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
lineInsertBefore
(
cursor
:
OneCursor
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
lineNumber
=
cursor
.
modelState
.
position
.
lineNumber
;
return
this
.
_applyEditOperation
(
ctx
,
if
(
lineNumber
===
1
)
{
TypeOperations
.
lineInsertBefore
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
)
ctx
.
executeCommand
=
new
ReplaceCommandWithoutChangingPosition
(
new
Range
(
1
,
1
,
1
,
1
),
'
\n
'
);
);
return
true
;
}
lineNumber
--
;
let
column
=
cursor
.
model
.
getLineMaxColumn
(
lineNumber
);
return
this
.
_enter
(
cursor
,
false
,
ctx
,
new
Range
(
lineNumber
,
column
,
lineNumber
,
column
));
}
}
public
static
lineInsertAfter
(
cursor
:
OneCursor
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
lineInsertAfter
(
cursor
:
OneCursor
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
position
=
cursor
.
modelState
.
position
;
return
this
.
_applyEditOperation
(
let
column
=
cursor
.
model
.
getLineMaxColumn
(
position
.
lineNumber
);
ctx
,
return
this
.
_enter
(
cursor
,
false
,
ctx
,
new
Range
(
position
.
lineNumber
,
column
,
position
.
lineNumber
,
column
));
TypeOperations
.
lineInsertAfter
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
)
);
}
}
public
static
lineBreakInsert
(
cursor
:
OneCursor
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
lineBreakInsert
(
cursor
:
OneCursor
,
ctx
:
IOneCursorOperationContext
):
boolean
{
return
this
.
_enter
(
cursor
,
true
,
ctx
,
cursor
.
modelState
.
selection
);
}
private
static
_enter
(
cursor
:
OneCursor
,
keepPosition
:
boolean
,
ctx
:
IOneCursorOperationContext
,
range
:
Range
):
boolean
{
return
this
.
_applyEditOperation
(
return
this
.
_applyEditOperation
(
ctx
,
ctx
,
TypeOperations
.
_enter
(
cursor
.
config
,
cursor
.
model
,
keepPosition
,
rang
e
)
TypeOperations
.
lineBreakInsert
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelStat
e
)
);
);
}
}
private
static
_typeInterceptorEnter
(
config
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
public
static
actualType
(
cursor
:
OneCursor
,
text
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
ch
!==
'
\n
'
)
{
return
this
.
_applyEditOperation
(
return
null
;
ctx
,
}
TypeOperations
.
typeWithoutInterceptors
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
,
text
)
);
return
TypeOperations
.
_enter
(
config
,
model
,
false
,
cursor
.
selection
);
}
private
static
_typeInterceptorAutoClosingCloseChar
(
config
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
selection
;
if
(
!
selection
.
isEmpty
()
||
!
config
.
autoClosingPairsClose
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
position
=
cursor
.
position
;
let
lineText
=
model
.
getLineContent
(
position
.
lineNumber
);
let
beforeCharacter
=
lineText
.
charAt
(
position
.
column
-
1
);
if
(
beforeCharacter
!==
ch
)
{
return
null
;
}
let
typeSelection
=
new
Range
(
position
.
lineNumber
,
position
.
column
,
position
.
lineNumber
,
position
.
column
+
1
);
return
new
EditOperationResult
(
new
ReplaceCommand
(
typeSelection
,
ch
));
}
private
static
_typeInterceptorAutoClosingOpenChar
(
config
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
selection
;
if
(
!
selection
.
isEmpty
()
||
!
config
.
autoClosingPairsOpen
.
hasOwnProperty
(
ch
))
{
return
null
;
}
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
config
.
autoClosingPairsClose
)
{
if
(
beforeCharacter
===
closeBrace
)
{
isBeforeCloseBrace
=
true
;
break
;
}
}
if
(
!
isBeforeCloseBrace
&&
!
/
\s
/
.
test
(
beforeCharacter
))
{
return
null
;
}
}
let
lineTokens
=
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
shouldAutoClosePair
=
false
;
try
{
shouldAutoClosePair
=
LanguageConfigurationRegistry
.
shouldAutoClosePair
(
ch
,
lineTokens
,
position
.
column
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
if
(
!
shouldAutoClosePair
)
{
return
null
;
}
let
closeCharacter
=
config
.
autoClosingPairsOpen
[
ch
];
return
new
EditOperationResult
(
new
ReplaceCommandWithOffsetCursorState
(
selection
,
ch
+
closeCharacter
,
0
,
-
closeCharacter
.
length
),
{
shouldPushStackElementBefore
:
true
,
shouldPushStackElementAfter
:
false
});
}
private
static
_typeInterceptorSurroundSelection
(
config
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
let
selection
=
cursor
.
selection
;
if
(
selection
.
isEmpty
()
||
!
config
.
surroundingPairs
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
selectionContainsOnlyWhitespace
=
true
;
for
(
let
lineNumber
=
selection
.
startLineNumber
;
lineNumber
<=
selection
.
endLineNumber
;
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
++
)
{
let
charCode
=
lineText
.
charCodeAt
(
charIndex
);
if
(
charCode
!==
CharCode
.
Tab
&&
charCode
!==
CharCode
.
Space
)
{
selectionContainsOnlyWhitespace
=
false
;
// Break outer loop
lineNumber
=
selection
.
endLineNumber
+
1
;
// Break inner loop
charIndex
=
endIndex
;
}
}
}
if
(
selectionContainsOnlyWhitespace
)
{
return
null
;
}
let
closeCharacter
=
config
.
surroundingPairs
[
ch
];
return
new
EditOperationResult
(
new
SurroundSelectionCommand
(
selection
,
ch
,
closeCharacter
),
{
shouldPushStackElementBefore
:
true
,
shouldPushStackElementAfter
:
true
});
}
private
static
_typeInterceptorElectricChar
(
config
:
CursorConfiguration
,
model
:
editorCommon
.
ITokenizedModel
,
cursor
:
CursorModelState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
electricChars
.
hasOwnProperty
(
ch
))
{
return
null
;
}
let
position
=
cursor
.
position
;
let
lineTokens
=
model
.
getLineTokens
(
position
.
lineNumber
,
false
);
let
electricAction
:
IElectricAction
;
try
{
electricAction
=
LanguageConfigurationRegistry
.
onElectricCharacter
(
ch
,
lineTokens
,
position
.
column
);
}
catch
(
e
)
{
onUnexpectedError
(
e
);
}
if
(
!
electricAction
)
{
return
null
;
}
if
(
electricAction
.
appendText
)
{
return
new
EditOperationResult
(
new
ReplaceCommandWithOffsetCursorState
(
cursor
.
selection
,
ch
+
electricAction
.
appendText
,
0
,
-
electricAction
.
appendText
.
length
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
true
});
}
if
(
electricAction
.
matchOpenBracket
)
{
let
match
=
model
.
findMatchingBracketUp
(
electricAction
.
matchOpenBracket
,
{
lineNumber
:
position
.
lineNumber
,
column
:
position
.
column
});
if
(
match
)
{
let
matchLine
=
model
.
getLineContent
(
match
.
startLineNumber
);
let
matchLineIndentation
=
strings
.
getLeadingWhitespace
(
matchLine
);
let
newIndentation
=
config
.
normalizeIndentation
(
matchLineIndentation
);
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
);
return
new
EditOperationResult
(
new
ReplaceCommand
(
typeSelection
,
typeText
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
true
});
}
}
return
null
;
}
public
static
actualType
(
cursor
:
OneCursor
,
text
:
string
,
keepPosition
:
boolean
,
ctx
:
IOneCursorOperationContext
):
boolean
{
ctx
.
executeCommand
=
TypeOperations
.
typeCommand
(
cursor
.
modelState
.
selection
,
text
,
keepPosition
);
return
true
;
}
}
public
static
type
(
cursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
type
(
cursor
:
OneCursor
,
ch
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
r
:
EditOperationResult
=
null
;
return
this
.
_applyEditOperation
(
ctx
,
r
=
r
||
this
.
_typeInterceptorEnter
(
cursor
.
config
,
cursor
.
model
,
cursor
.
modelState
,
ch
);
TypeOperations
.
typeWithInterceptors
(
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
(
r
)
{
return
this
.
_applyEditOperation
(
ctx
,
r
);
}
ctx
.
executeCommand
=
TypeOperations
.
typeCommand
(
cursor
.
modelState
.
selection
,
ch
,
false
);
return
true
;
}
}
public
static
replacePreviousChar
(
cursor
:
OneCursor
,
txt
:
string
,
replaceCharCnt
:
number
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
replacePreviousChar
(
cursor
:
OneCursor
,
txt
:
string
,
replaceCharCnt
:
number
,
ctx
:
IOneCursorOperationContext
):
boolean
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录