Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8b94148a
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,发现更多精彩内容 >>
提交
8b94148a
编写于
5月 19, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Renames
上级
cc38e4ea
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
103 addition
and
134 deletion
+103
-134
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+9
-24
src/vs/editor/common/controller/cursorDeleteOperations.ts
src/vs/editor/common/controller/cursorDeleteOperations.ts
+23
-25
src/vs/editor/common/controller/cursorTypeOperations.ts
src/vs/editor/common/controller/cursorTypeOperations.ts
+71
-85
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
8b94148a
...
...
@@ -14,7 +14,7 @@ import { Position } from 'vs/editor/common/core/position';
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
,
SelectionDirection
,
ISelection
}
from
'
vs/editor/common/core/selection
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorColumns
,
CursorConfiguration
,
EditOperationResult
,
SingleCursorState
,
IViewModelHelper
,
CursorContext
,
CursorState
,
RevealTarget
,
IColumnSelectData
,
ICursors
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorColumns
,
CursorConfiguration
,
EditOperationResult
,
IViewModelHelper
,
CursorContext
,
CursorState
,
RevealTarget
,
IColumnSelectData
,
ICursors
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
DeleteOperations
}
from
'
vs/editor/common/controller/cursorDeleteOperations
'
;
import
{
TypeOperations
}
from
'
vs/editor/common/controller/cursorTypeOperations
'
;
...
...
@@ -533,23 +533,6 @@ export class Cursor extends Disposable implements ICursors {
// -------------------- START editing operations
// TODO@Alex: remove
private
_getAllCursorsModelState
(
sorted
:
boolean
=
false
):
SingleCursorState
[]
{
let
cursors
=
this
.
_cursors
.
getAll
();
if
(
sorted
)
{
cursors
=
cursors
.
sort
((
a
,
b
)
=>
{
return
Range
.
compareRangesUsingStarts
(
a
.
modelState
.
selection
,
b
.
modelState
.
selection
);
});
}
let
r
:
SingleCursorState
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
r
[
i
]
=
cursors
[
i
].
modelState
;
}
return
r
;
}
private
_type
(
args
:
CursorOperationArgs
<
{
text
:
string
;
}
>
):
EditOperationResult
{
const
text
=
args
.
eventData
.
text
;
...
...
@@ -570,21 +553,21 @@ export class Cursor extends Disposable implements ICursors {
this
.
_createAndInterpretHandlerCtx
(()
=>
{
// Decide what all cursors will do up-front
return
TypeOperations
.
typeWithInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
(),
chr
);
return
TypeOperations
.
typeWithInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
chr
);
});
}
return
null
;
}
else
{
return
TypeOperations
.
typeWithoutInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
(),
text
);
return
TypeOperations
.
typeWithoutInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
text
);
}
}
private
_replacePreviousChar
(
args
:
CursorOperationArgs
<
{
text
:
string
;
replaceCharCnt
:
number
;
}
>
):
EditOperationResult
{
let
text
=
args
.
eventData
.
text
;
let
replaceCharCnt
=
args
.
eventData
.
replaceCharCnt
;
return
TypeOperations
.
replacePreviousChar
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
(),
text
,
replaceCharCnt
);
return
TypeOperations
.
replacePreviousChar
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
text
,
replaceCharCnt
);
}
private
_compositionStart
(
args
:
CursorOperationArgs
<
void
>
):
EditOperationResult
{
...
...
@@ -625,14 +608,16 @@ export class Cursor extends Disposable implements ICursors {
const
distributedPaste
=
this
.
_distributePasteToCursors
(
args
);
if
(
distributedPaste
)
{
return
TypeOperations
.
distributedPaste
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
(
true
),
distributedPaste
);
let
selections
=
this
.
getSelections
();
selections
=
selections
.
sort
(
Range
.
compareRangesUsingStarts
);
return
TypeOperations
.
distributedPaste
(
this
.
context
.
config
,
this
.
context
.
model
,
selections
,
distributedPaste
);
}
else
{
return
TypeOperations
.
paste
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
(),
args
.
eventData
.
text
,
args
.
eventData
.
pasteOnNewLine
);
return
TypeOperations
.
paste
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
args
.
eventData
.
text
,
args
.
eventData
.
pasteOnNewLine
);
}
}
private
_cut
(
args
:
CursorOperationArgs
<
void
>
):
EditOperationResult
{
return
DeleteOperations
.
cut
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
());
return
DeleteOperations
.
cut
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
());
}
// -------------------- END editing operations
...
...
src/vs/editor/common/controller/cursorDeleteOperations.ts
浏览文件 @
8b94148a
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
SingleCursorState
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
,
EditOperationResult
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
,
EditOperationResult
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
MoveOperations
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
...
...
@@ -14,16 +14,16 @@ import { ICommand } from "vs/editor/common/editorCommon";
export
class
DeleteOperations
{
public
static
deleteRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
s
:
Selection
[]):
[
boolean
,
ICommand
[]]
{
public
static
deleteRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selection
s
:
Selection
[]):
[
boolean
,
ICommand
[]]
{
let
commands
:
ICommand
[]
=
[];
let
shouldPushStackElementBefore
=
false
;
for
(
let
i
=
0
,
len
=
cursor
s
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursor
s
[
i
];
for
(
let
i
=
0
,
len
=
selection
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selection
s
[
i
];
let
deleteSelection
:
Range
=
cursor
;
let
deleteSelection
:
Range
=
selection
;
if
(
deleteSelection
.
isEmpty
())
{
let
position
=
cursor
.
getPosition
();
let
position
=
selection
.
getPosition
();
let
rightOfPosition
=
MoveOperations
.
right
(
config
,
model
,
position
.
lineNumber
,
position
.
column
);
deleteSelection
=
new
Range
(
rightOfPosition
.
lineNumber
,
...
...
@@ -48,13 +48,13 @@ export class DeleteOperations {
return
[
shouldPushStackElementBefore
,
commands
];
}
private
static
_isAutoClosingPairDelete
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
s
:
Selection
[]):
boolean
{
private
static
_isAutoClosingPairDelete
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selection
s
:
Selection
[]):
boolean
{
if
(
!
config
.
autoClosingBrackets
)
{
return
false
;
}
for
(
let
i
=
0
,
len
=
cursor
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
cursor
s
[
i
];
for
(
let
i
=
0
,
len
=
selection
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selection
s
[
i
];
const
position
=
selection
.
getPosition
();
if
(
!
selection
.
isEmpty
())
{
...
...
@@ -79,11 +79,10 @@ export class DeleteOperations {
return
true
;
}
private
static
_runAutoClosingPairDelete
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
s
:
Selection
[]):
[
boolean
,
ICommand
[]]
{
private
static
_runAutoClosingPairDelete
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selection
s
:
Selection
[]):
[
boolean
,
ICommand
[]]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
const
position
=
cursor
.
getPosition
();
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
position
=
selections
[
i
].
getPosition
();
const
deleteSelection
=
new
Range
(
position
.
lineNumber
,
position
.
column
-
1
,
...
...
@@ -95,21 +94,21 @@ export class DeleteOperations {
return
[
true
,
commands
];
}
public
static
deleteLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
s
:
Selection
[]):
[
boolean
,
ICommand
[]]
{
public
static
deleteLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selection
s
:
Selection
[]):
[
boolean
,
ICommand
[]]
{
if
(
this
.
_isAutoClosingPairDelete
(
config
,
model
,
cursor
s
))
{
return
this
.
_runAutoClosingPairDelete
(
config
,
model
,
cursor
s
);
if
(
this
.
_isAutoClosingPairDelete
(
config
,
model
,
selection
s
))
{
return
this
.
_runAutoClosingPairDelete
(
config
,
model
,
selection
s
);
}
let
commands
:
ICommand
[]
=
[];
let
shouldPushStackElementBefore
=
false
;
for
(
let
i
=
0
,
len
=
cursor
s
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursor
s
[
i
];
for
(
let
i
=
0
,
len
=
selection
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selection
s
[
i
];
let
deleteSelection
:
Range
=
cursor
;
let
deleteSelection
:
Range
=
selection
;
if
(
deleteSelection
.
isEmpty
())
{
let
position
=
cursor
.
getPosition
();
let
position
=
selection
.
getPosition
();
if
(
config
.
useTabStops
&&
position
.
column
>
1
)
{
let
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
...
...
@@ -155,17 +154,16 @@ export class DeleteOperations {
return
[
shouldPushStackElementBefore
,
commands
];
}
public
static
cut
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursors
:
SingleCursorState
[]):
EditOperationResult
{
public
static
cut
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selections
:
Selection
[]):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
let
selection
=
cursor
.
selection
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
if
(
selection
.
isEmpty
())
{
if
(
config
.
emptySelectionClipboard
)
{
// This is a full line cut
let
position
=
cursor
.
position
;
let
position
=
selection
.
getPosition
()
;
let
startLineNumber
:
number
,
startColumn
:
number
,
...
...
src/vs/editor/common/controller/cursorTypeOperations.ts
浏览文件 @
8b94148a
...
...
@@ -6,7 +6,7 @@
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
ReplaceCommand
,
ReplaceCommandWithoutChangingPosition
,
ReplaceCommandWithOffsetCursorState
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
SingleCursorState
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
,
EditOperationResult
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
,
EditOperationResult
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ICommand
,
ITokenizedModel
}
from
'
vs/editor/common/editorCommon
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
...
...
@@ -21,11 +21,10 @@ import { CursorChangeReason } from "vs/editor/common/controller/cursorEvents";
export
class
TypeOperations
{
public
static
indent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
s
:
Selection
[]):
ICommand
[]
{
public
static
indent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selection
s
:
Selection
[]):
ICommand
[]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
commands
[
i
]
=
new
ShiftCommand
(
cursor
,
{
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
new
ShiftCommand
(
selections
[
i
],
{
isUnshift
:
false
,
tabSize
:
config
.
tabSize
,
oneIndent
:
config
.
oneIndent
,
...
...
@@ -35,11 +34,10 @@ export class TypeOperations {
return
commands
;
}
public
static
outdent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
s
:
Selection
[]):
ICommand
[]
{
public
static
outdent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selection
s
:
Selection
[]):
ICommand
[]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
commands
[
i
]
=
new
ShiftCommand
(
cursor
,
{
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
new
ShiftCommand
(
selections
[
i
],
{
isUnshift
:
true
,
tabSize
:
config
.
tabSize
,
oneIndent
:
config
.
oneIndent
,
...
...
@@ -71,12 +69,10 @@ export class TypeOperations {
return
newIndentation
;
}
public
static
distributedPaste
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursors
:
SingleCursorState
[],
text
:
string
[]):
EditOperationResult
{
public
static
distributedPaste
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selections
:
Selection
[],
text
:
string
[]):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
let
selection
=
cursor
.
selection
;
commands
[
i
]
=
new
ReplaceCommand
(
selection
,
text
[
i
]);
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
new
ReplaceCommand
(
selections
[
i
],
text
[
i
]);
}
return
new
EditOperationResult
(
commands
,
{
shouldPushStackElementBefore
:
true
,
...
...
@@ -85,12 +81,11 @@ export class TypeOperations {
});
}
public
static
paste
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursors
:
SingleCursorState
[],
text
:
string
,
pasteOnNewLine
:
boolean
):
EditOperationResult
{
public
static
paste
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
selections
:
Selection
[],
text
:
string
,
pasteOnNewLine
:
boolean
):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
let
position
=
cursor
.
position
;
let
selection
=
cursor
.
selection
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
let
position
=
selection
.
getPosition
();
if
(
pasteOnNewLine
&&
text
.
indexOf
(
'
\n
'
)
!==
text
.
length
-
1
)
{
pasteOnNewLine
=
false
;
...
...
@@ -166,10 +161,10 @@ export class TypeOperations {
return
new
ReplaceCommand
(
selection
,
typeText
,
insertsAutoWhitespace
);
}
public
static
tab
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
s
:
Selection
[]):
ICommand
[]
{
public
static
tab
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selection
s
:
Selection
[]):
ICommand
[]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursor
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
cursor
s
[
i
];
for
(
let
i
=
0
,
len
=
selection
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selection
s
[
i
];
if
(
selection
.
isEmpty
())
{
...
...
@@ -207,18 +202,18 @@ export class TypeOperations {
return
commands
;
}
public
static
replacePreviousChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
txt
:
string
,
replaceCharCnt
:
number
):
EditOperationResult
{
public
static
replacePreviousChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
txt
:
string
,
replaceCharCnt
:
number
):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursor
s
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursor
s
[
i
];
if
(
!
cursor
.
selection
.
isEmpty
())
{
for
(
let
i
=
0
,
len
=
selection
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selection
s
[
i
];
if
(
!
selection
.
isEmpty
())
{
// looks like https://github.com/Microsoft/vscode/issues/2773
// where a cursor operation occured before a canceled composition
// => ignore composition
commands
[
i
]
=
null
;
continue
;
}
let
pos
=
cursor
.
position
;
let
pos
=
selection
.
getPosition
()
;
let
startColumn
=
Math
.
max
(
1
,
pos
.
column
-
replaceCharCnt
);
let
range
=
new
Range
(
pos
.
lineNumber
,
startColumn
,
pos
.
lineNumber
,
pos
.
column
);
commands
[
i
]
=
new
ReplaceCommand
(
range
,
txt
);
...
...
@@ -294,20 +289,19 @@ export class TypeOperations {
return
null
;
}
private
static
_isAutoClosingCloseCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
ch
:
string
):
boolean
{
private
static
_isAutoClosingCloseCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
ch
:
string
):
boolean
{
if
(
!
config
.
autoClosingBrackets
||
!
config
.
autoClosingPairsClose
.
hasOwnProperty
(
ch
))
{
return
false
;
}
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
const
selection
=
cursor
.
selection
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
if
(
!
selection
.
isEmpty
())
{
return
false
;
}
const
position
=
cursor
.
position
;
const
position
=
selection
.
getPosition
()
;
const
lineText
=
model
.
getLineContent
(
position
.
lineNumber
);
const
afterCharacter
=
lineText
.
charAt
(
position
.
column
-
1
);
...
...
@@ -319,11 +313,11 @@ export class TypeOperations {
return
true
;
}
private
static
_runAutoClosingCloseCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
ch
:
string
):
EditOperationResult
{
private
static
_runAutoClosingCloseCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
ch
:
string
):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursor
s
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursor
s
[
i
];
const
position
=
cursor
.
position
;
for
(
let
i
=
0
,
len
=
selection
s
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selection
s
[
i
];
const
position
=
selection
.
getPosition
()
;
const
typeSelection
=
new
Range
(
position
.
lineNumber
,
position
.
column
,
position
.
lineNumber
,
position
.
column
+
1
);
commands
[
i
]
=
new
ReplaceCommand
(
typeSelection
,
ch
);
}
...
...
@@ -333,19 +327,18 @@ export class TypeOperations {
});
}
private
static
_isAutoClosingOpenCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
ch
:
string
):
boolean
{
private
static
_isAutoClosingOpenCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
ch
:
string
):
boolean
{
if
(
!
config
.
autoClosingBrackets
||
!
config
.
autoClosingPairsOpen
.
hasOwnProperty
(
ch
))
{
return
false
;
}
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
const
selection
=
cursor
.
selection
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
if
(
!
selection
.
isEmpty
())
{
return
false
;
}
const
position
=
cursor
.
position
;
const
position
=
selection
.
getPosition
()
;
const
lineText
=
model
.
getLineContent
(
position
.
lineNumber
);
// Do not auto-close ' or " after a word character
...
...
@@ -397,11 +390,10 @@ export class TypeOperations {
return
true
;
}
private
static
_runAutoClosingOpenCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
ch
:
string
):
EditOperationResult
{
private
static
_runAutoClosingOpenCharType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
ch
:
string
):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
const
selection
=
cursor
.
selection
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
const
closeCharacter
=
config
.
autoClosingPairsOpen
[
ch
];
commands
[
i
]
=
new
ReplaceCommandWithOffsetCursorState
(
selection
,
ch
+
closeCharacter
,
0
,
-
closeCharacter
.
length
);
}
...
...
@@ -411,14 +403,13 @@ export class TypeOperations {
});
}
private
static
_isSurroundSelectionType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
ch
:
string
):
boolean
{
private
static
_isSurroundSelectionType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
ch
:
string
):
boolean
{
if
(
!
config
.
autoClosingBrackets
||
!
config
.
surroundingPairs
.
hasOwnProperty
(
ch
))
{
return
false
;
}
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
const
selection
=
cursor
.
selection
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
if
(
selection
.
isEmpty
())
{
return
false
;
...
...
@@ -446,11 +437,10 @@ export class TypeOperations {
return
true
;
}
private
static
_runSurroundSelectionType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
ch
:
string
):
EditOperationResult
{
private
static
_runSurroundSelectionType
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
ch
:
string
):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
const
selection
=
cursor
.
selection
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
const
closeCharacter
=
config
.
surroundingPairs
[
ch
];
commands
[
i
]
=
new
SurroundSelectionCommand
(
selection
,
ch
,
closeCharacter
);
}
...
...
@@ -460,12 +450,12 @@ export class TypeOperations {
});
}
private
static
_typeInterceptorElectricChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursorState
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
electricChars
.
hasOwnProperty
(
ch
)
||
!
cursor
.
selection
.
isEmpty
())
{
private
static
_typeInterceptorElectricChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
electricChars
.
hasOwnProperty
(
ch
)
||
!
selections
.
isEmpty
())
{
return
null
;
}
let
position
=
cursor
.
position
;
let
position
=
selections
.
getPosition
()
;
model
.
forceTokenization
(
position
.
lineNumber
);
let
lineTokens
=
model
.
getLineTokens
(
position
.
lineNumber
);
...
...
@@ -481,7 +471,7 @@ export class TypeOperations {
}
if
(
electricAction
.
appendText
)
{
const
command
=
new
ReplaceCommandWithOffsetCursorState
(
cursor
.
selection
,
ch
+
electricAction
.
appendText
,
0
,
-
electricAction
.
appendText
.
length
);
const
command
=
new
ReplaceCommandWithOffsetCursorState
(
selections
,
ch
+
electricAction
.
appendText
,
0
,
-
electricAction
.
appendText
.
length
);
return
new
EditOperationResult
([
command
],
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
true
...
...
@@ -523,12 +513,12 @@ export class TypeOperations {
return
null
;
}
public
static
typeWithInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
ch
:
string
):
EditOperationResult
{
public
static
typeWithInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
ch
:
string
):
EditOperationResult
{
if
(
ch
===
'
\n
'
)
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursor
s
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
TypeOperations
.
_enter
(
config
,
model
,
false
,
cursors
[
i
].
selection
);
for
(
let
i
=
0
,
len
=
selection
s
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
TypeOperations
.
_enter
(
config
,
model
,
false
,
selections
[
i
]
);
}
return
new
EditOperationResult
(
commands
,
{
shouldPushStackElementBefore
:
true
,
...
...
@@ -536,35 +526,34 @@ export class TypeOperations {
});
}
if
(
this
.
_isAutoClosingCloseCharType
(
config
,
model
,
cursor
s
,
ch
))
{
return
this
.
_runAutoClosingCloseCharType
(
config
,
model
,
cursor
s
,
ch
);
if
(
this
.
_isAutoClosingCloseCharType
(
config
,
model
,
selection
s
,
ch
))
{
return
this
.
_runAutoClosingCloseCharType
(
config
,
model
,
selection
s
,
ch
);
}
if
(
this
.
_isAutoClosingOpenCharType
(
config
,
model
,
cursor
s
,
ch
))
{
return
this
.
_runAutoClosingOpenCharType
(
config
,
model
,
cursor
s
,
ch
);
if
(
this
.
_isAutoClosingOpenCharType
(
config
,
model
,
selection
s
,
ch
))
{
return
this
.
_runAutoClosingOpenCharType
(
config
,
model
,
selection
s
,
ch
);
}
if
(
this
.
_isSurroundSelectionType
(
config
,
model
,
cursor
s
,
ch
))
{
return
this
.
_runSurroundSelectionType
(
config
,
model
,
cursor
s
,
ch
);
if
(
this
.
_isSurroundSelectionType
(
config
,
model
,
selection
s
,
ch
))
{
return
this
.
_runSurroundSelectionType
(
config
,
model
,
selection
s
,
ch
);
}
// Electric characters make sense only when dealing with a single cursor,
// as multiple cursors typing brackets for example would interfer with bracket matching
if
(
cursor
s
.
length
===
1
)
{
const
r
=
this
.
_typeInterceptorElectricChar
(
config
,
model
,
cursor
s
[
0
],
ch
);
if
(
selection
s
.
length
===
1
)
{
const
r
=
this
.
_typeInterceptorElectricChar
(
config
,
model
,
selection
s
[
0
],
ch
);
if
(
r
)
{
return
r
;
}
}
return
this
.
typeWithoutInterceptors
(
config
,
model
,
cursor
s
,
ch
);
return
this
.
typeWithoutInterceptors
(
config
,
model
,
selection
s
,
ch
);
}
public
static
typeWithoutInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[],
str
:
string
):
EditOperationResult
{
public
static
typeWithoutInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selections
:
Selection
[],
str
:
string
):
EditOperationResult
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
commands
[
i
]
=
new
ReplaceCommand
(
cursor
.
selection
,
str
);
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
new
ReplaceCommand
(
selections
[
i
],
str
);
}
return
new
EditOperationResult
(
commands
,
{
shouldPushStackElementBefore
:
false
,
...
...
@@ -572,11 +561,10 @@ export class TypeOperations {
});
}
public
static
lineInsertBefore
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
s
:
Selection
[]):
ICommand
[]
{
public
static
lineInsertBefore
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selection
s
:
Selection
[]):
ICommand
[]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
let
lineNumber
=
cursor
.
positionLineNumber
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
let
lineNumber
=
selections
[
i
].
positionLineNumber
;
if
(
lineNumber
===
1
)
{
commands
[
i
]
=
new
ReplaceCommandWithoutChangingPosition
(
new
Range
(
1
,
1
,
1
,
1
),
'
\n
'
);
...
...
@@ -590,22 +578,20 @@ export class TypeOperations {
return
commands
;
}
public
static
lineInsertAfter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
s
:
Selection
[]):
ICommand
[]
{
public
static
lineInsertAfter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selection
s
:
Selection
[]):
ICommand
[]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
let
lineNumber
=
cursor
.
positionLineNumber
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
lineNumber
=
selections
[
i
].
positionLineNumber
;
let
column
=
model
.
getLineMaxColumn
(
lineNumber
);
commands
[
i
]
=
this
.
_enter
(
config
,
model
,
false
,
new
Range
(
lineNumber
,
column
,
lineNumber
,
column
));
}
return
commands
;
}
public
static
lineBreakInsert
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
s
:
Selection
[]):
ICommand
[]
{
public
static
lineBreakInsert
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
selection
s
:
Selection
[]):
ICommand
[]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
commands
[
i
]
=
this
.
_enter
(
config
,
model
,
true
,
cursor
);
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
this
.
_enter
(
config
,
model
,
true
,
selections
[
i
]);
}
return
commands
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录