Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
84d6cce7
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,发现更多精彩内容 >>
提交
84d6cce7
编写于
2月 19, 2019
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tweaks for #67287
上级
e6781fd1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
91 addition
and
30 deletion
+91
-30
src/vs/editor/contrib/linesOperations/linesOperations.ts
src/vs/editor/contrib/linesOperations/linesOperations.ts
+30
-27
src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts
...itor/contrib/linesOperations/test/linesOperations.test.ts
+61
-3
未找到文件。
src/vs/editor/contrib/linesOperations/linesOperations.ts
浏览文件 @
84d6cce7
...
...
@@ -6,7 +6,7 @@
import
*
as
nls
from
'
vs/nls
'
;
import
{
KeyChord
,
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
CoreEditingCommands
}
from
'
vs/editor/browser/controller/coreCommands
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
ICodeEditor
,
IActiveCodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
EditorAction
,
IActionOptions
,
ServicesAccessor
,
registerEditorAction
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
ReplaceCommand
,
ReplaceCommandThatPreservesSelection
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
TrimTrailingWhitespaceCommand
}
from
'
vs/editor/common/commands/trimTrailingWhitespaceCommand
'
;
...
...
@@ -261,6 +261,7 @@ export class TrimTrailingWhitespaceAction extends EditorAction {
}
// delete lines
interface
IDeleteLinesOperation
{
startLineNumber
:
number
;
selectionStartColumn
:
number
;
...
...
@@ -285,47 +286,50 @@ export class DeleteLinesAction extends EditorAction {
}
public
run
(
_accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
{
if
(
!
editor
.
hasModel
())
{
return
;
}
let
ops
=
this
.
_getLinesToRemove
(
editor
);
let
model
:
ITextModel
|
null
=
editor
.
getModel
();
if
(
model
!
.
getLineCount
()
===
1
&&
model
!
.
getLineMaxColumn
(
1
)
===
1
)
{
let
model
:
ITextModel
=
editor
.
getModel
();
if
(
model
.
getLineCount
()
===
1
&&
model
.
getLineMaxColumn
(
1
)
===
1
)
{
// Model is empty
return
;
}
let
edits
:
IIdentifiedSingleEditOperation
[]
=
ops
.
map
((
op
)
=>
{
let
linesDeleted
=
0
;
let
edits
:
IIdentifiedSingleEditOperation
[]
=
[];
let
cursorState
:
Selection
[]
=
[];
for
(
let
i
=
0
,
len
=
ops
.
length
;
i
<
len
;
i
++
)
{
const
op
=
ops
[
i
];
let
startLineNumber
=
op
.
startLineNumber
;
let
endLineNumber
=
op
.
endLineNumber
;
let
startColumn
=
1
;
let
endColumn
=
model
!
.
getLineMaxColumn
(
endLineNumber
);
if
(
endLineNumber
<
model
!
.
getLineCount
())
{
let
endColumn
=
model
.
getLineMaxColumn
(
endLineNumber
);
if
(
endLineNumber
<
model
.
getLineCount
())
{
endLineNumber
+=
1
;
endColumn
=
1
;
}
else
if
(
startLineNumber
>
1
)
{
startLineNumber
-=
1
;
startColumn
=
model
!
.
getLineMaxColumn
(
startLineNumber
);
startColumn
=
model
.
getLineMaxColumn
(
startLineNumber
);
}
return
EditOperation
.
replace
(
new
Selection
(
startLineNumber
,
startColumn
,
endLineNumber
,
endColumn
),
''
);
});
let
cursorState
:
Selection
[]
=
ops
.
map
((
op
)
=>
{
return
new
Selection
(
op
.
startLineNumber
,
op
.
selectionStartColumn
,
op
.
startLineNumber
,
op
.
selectionStartColumn
);
});
edits
.
push
(
EditOperation
.
replace
(
new
Selection
(
startLineNumber
,
startColumn
,
endLineNumber
,
endColumn
),
''
));
cursorState
.
push
(
new
Selection
(
startLineNumber
-
linesDeleted
,
op
.
positionColumn
,
startLineNumber
-
linesDeleted
,
op
.
positionColumn
));
linesDeleted
+=
(
op
.
endLineNumber
-
op
.
startLineNumber
+
1
);
}
editor
.
pushUndoStop
();
editor
.
executeEdits
(
this
.
id
,
edits
,
cursorState
);
editor
.
pushUndoStop
();
}
private
_getLinesToRemove
(
editor
:
ICodeEditor
):
IDeleteLinesOperation
[]
{
private
_getLinesToRemove
(
editor
:
I
Active
CodeEditor
):
IDeleteLinesOperation
[]
{
// Construct delete operations
let
selections
=
editor
.
getSelections
();
if
(
selections
===
null
)
{
return
[];
}
let
operations
:
IDeleteLinesOperation
[]
=
selections
.
map
((
s
)
=>
{
let
operations
:
IDeleteLinesOperation
[]
=
editor
.
getSelections
().
map
((
s
)
=>
{
let
endLineNumber
=
s
.
endLineNumber
;
if
(
s
.
startLineNumber
<
s
.
endLineNumber
&&
s
.
endColumn
===
1
)
{
...
...
@@ -338,7 +342,6 @@ export class DeleteLinesAction extends EditorAction {
endLineNumber
:
endLineNumber
,
positionColumn
:
s
.
positionColumn
};
});
// Sort delete operations
...
...
@@ -359,7 +362,7 @@ export class DeleteLinesAction extends EditorAction {
}
else
{
// Push previous operation
mergedOperations
.
push
(
previousOperation
);
previousOperation
=
selec
tions
[
i
];
previousOperation
=
opera
tions
[
i
];
}
}
// Push the last operation
...
...
@@ -467,10 +470,10 @@ export class InsertLineAfterAction extends EditorAction {
export
abstract
class
AbstractDeleteAllToBoundaryAction
extends
EditorAction
{
public
run
(
_accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
{
const
primaryCursor
=
editor
.
getSelection
();
if
(
primaryCursor
===
null
)
{
if
(
!
editor
.
hasModel
())
{
return
;
}
const
primaryCursor
=
editor
.
getSelection
();
let
rangesToDelete
=
this
.
_getRangesToDelete
(
editor
);
// merge overlapping selections
...
...
@@ -505,7 +508,7 @@ export abstract class AbstractDeleteAllToBoundaryAction extends EditorAction {
*/
protected
abstract
_getEndCursorState
(
primaryCursor
:
Range
,
rangesToDelete
:
Range
[]):
Selection
[];
protected
abstract
_getRangesToDelete
(
editor
:
ICodeEditor
):
Range
[];
protected
abstract
_getRangesToDelete
(
editor
:
I
Active
CodeEditor
):
Range
[];
}
export
class
DeleteAllLeftAction
extends
AbstractDeleteAllToBoundaryAction
{
...
...
@@ -554,7 +557,7 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction {
return
endCursorState
;
}
_getRangesToDelete
(
editor
:
ICodeEditor
):
Range
[]
{
_getRangesToDelete
(
editor
:
I
Active
CodeEditor
):
Range
[]
{
let
selections
=
editor
.
getSelections
();
if
(
selections
===
null
)
{
return
[];
...
...
@@ -572,7 +575,7 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction {
if
(
selection
.
isEmpty
())
{
if
(
selection
.
startColumn
===
1
)
{
let
deleteFromLine
=
Math
.
max
(
1
,
selection
.
startLineNumber
-
1
);
let
deleteFromColumn
=
selection
.
startLineNumber
===
1
?
1
:
model
!
.
getLineContent
(
deleteFromLine
).
length
+
1
;
let
deleteFromColumn
=
selection
.
startLineNumber
===
1
?
1
:
model
.
getLineContent
(
deleteFromLine
).
length
+
1
;
return
new
Range
(
deleteFromLine
,
deleteFromColumn
,
selection
.
startLineNumber
,
1
);
}
else
{
return
new
Range
(
selection
.
startLineNumber
,
1
,
selection
.
startLineNumber
,
selection
.
startColumn
);
...
...
@@ -623,7 +626,7 @@ export class DeleteAllRightAction extends AbstractDeleteAllToBoundaryAction {
return
endCursorState
;
}
_getRangesToDelete
(
editor
:
ICodeEditor
):
Range
[]
{
_getRangesToDelete
(
editor
:
I
Active
CodeEditor
):
Range
[]
{
let
model
=
editor
.
getModel
();
if
(
model
===
null
)
{
return
[];
...
...
@@ -637,7 +640,7 @@ export class DeleteAllRightAction extends AbstractDeleteAllToBoundaryAction {
let
rangesToDelete
:
Range
[]
=
selections
.
map
((
sel
)
=>
{
if
(
sel
.
isEmpty
())
{
const
maxColumn
=
model
!
.
getLineMaxColumn
(
sel
.
startLineNumber
);
const
maxColumn
=
model
.
getLineMaxColumn
(
sel
.
startLineNumber
);
if
(
sel
.
startColumn
===
maxColumn
)
{
return
new
Range
(
sel
.
startLineNumber
,
sel
.
startColumn
,
sel
.
startLineNumber
+
1
,
1
);
...
...
src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts
浏览文件 @
84d6cce7
...
...
@@ -900,14 +900,16 @@ suite('Editor Contrib - Line Operations', () => {
});
});
function
testDeleteLinesCommand
(
initialText
:
string
[],
initialSelection
:
Selection
,
resultingText
:
string
[],
resultingSelection
:
Selection
):
void
{
function
testDeleteLinesCommand
(
initialText
:
string
[],
_initialSelections
:
Selection
|
Selection
[],
resultingText
:
string
[],
_resultingSelections
:
Selection
|
Selection
[]):
void
{
const
initialSelections
=
Array
.
isArray
(
_initialSelections
)
?
_initialSelections
:
[
_initialSelections
];
const
resultingSelections
=
Array
.
isArray
(
_resultingSelections
)
?
_resultingSelections
:
[
_resultingSelections
];
withTestCodeEditor
(
initialText
,
{},
(
editor
)
=>
{
editor
.
setSelection
(
initialSelection
);
editor
.
setSelection
s
(
initialSelections
);
const
deleteLinesAction
=
new
DeleteLinesAction
();
deleteLinesAction
.
run
(
null
!
,
editor
);
assert
.
equal
(
editor
.
getValue
(),
resultingText
.
join
(
'
\n
'
));
assert
.
deepEqual
(
editor
.
getSelection
(),
resultingSelection
);
assert
.
deepEqual
(
editor
.
getSelection
s
(),
resultingSelections
);
});
}
...
...
@@ -1087,4 +1089,60 @@ suite('Editor Contrib - Line Operations', () => {
new
Selection
(
3
,
2
,
3
,
2
)
);
});
test
(
'
multicursor 1
'
,
function
()
{
testDeleteLinesCommand
(
[
'
class P {
'
,
''
,
'
getA() {
'
,
'
if (true) {
'
,
'
return "a";
'
,
'
}
'
,
'
}
'
,
''
,
'
getB() {
'
,
'
if (true) {
'
,
'
return "b";
'
,
'
}
'
,
'
}
'
,
''
,
'
getC() {
'
,
'
if (true) {
'
,
'
return "c";
'
,
'
}
'
,
'
}
'
,
'
}
'
,
],
[
new
Selection
(
4
,
1
,
5
,
1
),
new
Selection
(
10
,
1
,
11
,
1
),
new
Selection
(
16
,
1
,
17
,
1
),
],
[
'
class P {
'
,
''
,
'
getA() {
'
,
'
return "a";
'
,
'
}
'
,
'
}
'
,
''
,
'
getB() {
'
,
'
return "b";
'
,
'
}
'
,
'
}
'
,
''
,
'
getC() {
'
,
'
return "c";
'
,
'
}
'
,
'
}
'
,
'
}
'
,
],
[
new
Selection
(
4
,
1
,
4
,
1
),
new
Selection
(
9
,
1
,
9
,
1
),
new
Selection
(
14
,
1
,
14
,
1
),
]
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录