Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
344f4d3a
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
344f4d3a
编写于
6月 19, 2018
作者:
A
Alfonso Perez
提交者:
Peng Lyu
6月 19, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Keep deleting lines when triggering deleteAllLeft on column 1 (#28392)
* keep deleting lines when doing a deleteAllLeft on column 1
上级
f71c3784
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
116 addition
and
6 deletion
+116
-6
src/vs/editor/contrib/linesOperations/linesOperations.ts
src/vs/editor/contrib/linesOperations/linesOperations.ts
+21
-6
src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts
...itor/contrib/linesOperations/test/linesOperations.test.ts
+95
-0
未找到文件。
src/vs/editor/contrib/linesOperations/linesOperations.ts
浏览文件 @
344f4d3a
...
...
@@ -408,8 +408,8 @@ export abstract class AbstractDeleteAllToBoundaryAction extends EditorAction {
effectiveRanges
.
push
(
rangesToDelete
[
rangesToDelete
.
length
-
1
]);
let
endCursorState
=
this
.
_getEndCursorState
(
primaryCursor
,
effectiveRanges
);
let
edits
:
IIdentifiedSingleEditOperation
[]
=
effectiveRanges
.
map
(
range
=>
{
endCursorState
.
push
(
new
Selection
(
range
.
startLineNumber
,
range
.
startColumn
,
range
.
startLineNumber
,
range
.
startColumn
));
return
EditOperation
.
replace
(
range
,
''
);
});
...
...
@@ -444,17 +444,25 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction {
_getEndCursorState
(
primaryCursor
:
Range
,
rangesToDelete
:
Range
[]):
Selection
[]
{
let
endPrimaryCursor
:
Selection
;
let
endCursorState
:
Selection
[]
=
[];
let
deletedLines
=
0
;
for
(
let
i
=
0
,
len
=
rangesToDelete
.
length
;
i
<
len
;
i
++
)
{
let
range
=
rangesToDelete
[
i
];
let
endCursor
=
new
Selection
(
rangesToDelete
[
i
].
startLineNumber
,
rangesToDelete
[
i
].
startColumn
,
rangesToDelete
[
i
].
startLineNumber
,
rangesToDelete
[
i
].
startColumn
);
rangesToDelete
.
forEach
(
range
=>
{
let
endCursor
;
if
(
range
.
endColumn
===
1
&&
deletedLines
>
0
)
{
let
newStartLine
=
range
.
startLineNumber
-
deletedLines
;
endCursor
=
new
Selection
(
newStartLine
,
range
.
startColumn
,
newStartLine
,
range
.
startColumn
);
}
else
{
endCursor
=
new
Selection
(
range
.
startLineNumber
,
range
.
startColumn
,
range
.
startLineNumber
,
range
.
startColumn
);
}
deletedLines
+=
range
.
endLineNumber
-
range
.
startLineNumber
;
if
(
range
.
intersectRanges
(
primaryCursor
))
{
endPrimaryCursor
=
endCursor
;
}
else
{
endCursorState
.
push
(
endCursor
);
}
}
}
);
if
(
endPrimaryCursor
)
{
endCursorState
.
unshift
(
endPrimaryCursor
);
...
...
@@ -465,11 +473,18 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction {
_getRangesToDelete
(
editor
:
ICodeEditor
):
Range
[]
{
let
rangesToDelete
:
Range
[]
=
editor
.
getSelections
();
let
model
=
editor
.
getModel
();
rangesToDelete
.
sort
(
Range
.
compareRangesUsingStarts
);
rangesToDelete
=
rangesToDelete
.
map
(
selection
=>
{
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
;
return
new
Range
(
deleteFromLine
,
deleteFromColumn
,
selection
.
startLineNumber
,
1
);
}
else
{
return
new
Range
(
selection
.
startLineNumber
,
1
,
selection
.
startLineNumber
,
selection
.
startColumn
);
}
}
else
{
return
selection
;
}
...
...
src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts
浏览文件 @
344f4d3a
...
...
@@ -155,6 +155,101 @@ suite('Editor Contrib - Line Operations', () => {
});
});
test
(
'
should jump to the previous line when on first column
'
,
function
()
{
withTestCodeEditor
(
[
'
one
'
,
'
two
'
,
'
three
'
],
{},
(
editor
,
cursor
)
=>
{
let
model
=
editor
.
getModel
();
let
deleteAllLeftAction
=
new
DeleteAllLeftAction
();
editor
.
setSelection
(
new
Selection
(
2
,
1
,
2
,
1
));
deleteAllLeftAction
.
run
(
null
,
editor
);
assert
.
equal
(
model
.
getLineContent
(
1
),
'
onetwo
'
,
'
001
'
);
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
2
,
1
,
2
,
1
)]);
deleteAllLeftAction
.
run
(
null
,
editor
);
assert
.
equal
(
model
.
getLinesContent
()[
0
],
'
onetwothree
'
);
assert
.
equal
(
model
.
getLinesContent
().
length
,
1
);
editor
.
setSelection
(
new
Selection
(
1
,
1
,
1
,
1
));
deleteAllLeftAction
.
run
(
null
,
editor
);
assert
.
equal
(
model
.
getLinesContent
()[
0
],
'
onetwothree
'
);
});
});
test
(
'
should keep deleting lines in multi cursor mode
'
,
function
()
{
withTestCodeEditor
(
[
'
hi my name is Carlos Matos
'
,
'
BCC
'
,
'
waso waso waso
'
,
'
my wife doesnt believe in me
'
,
'
nonononono
'
,
'
bitconneeeect
'
],
{},
(
editor
,
cursor
)
=>
{
let
model
=
editor
.
getModel
();
let
deleteAllLeftAction
=
new
DeleteAllLeftAction
();
const
beforeSecondWasoSelection
=
new
Selection
(
3
,
5
,
3
,
5
);
const
endOfBCCSelection
=
new
Selection
(
2
,
4
,
2
,
4
);
const
endOfNonono
=
new
Selection
(
5
,
11
,
5
,
11
);
editor
.
setSelections
([
beforeSecondWasoSelection
,
endOfBCCSelection
,
endOfNonono
]);
let
selections
;
deleteAllLeftAction
.
run
(
null
,
editor
);
selections
=
editor
.
getSelections
();
assert
.
equal
(
model
.
getLineContent
(
2
),
''
);
assert
.
equal
(
model
.
getLineContent
(
3
),
'
waso waso
'
);
assert
.
equal
(
model
.
getLineContent
(
5
),
''
);
assert
.
deepEqual
([
selections
[
0
].
startLineNumber
,
selections
[
0
].
startColumn
,
selections
[
0
].
endLineNumber
,
selections
[
0
].
endColumn
],
[
3
,
1
,
3
,
1
]);
assert
.
deepEqual
([
selections
[
1
].
startLineNumber
,
selections
[
1
].
startColumn
,
selections
[
1
].
endLineNumber
,
selections
[
1
].
endColumn
],
[
2
,
1
,
2
,
1
]);
assert
.
deepEqual
([
selections
[
2
].
startLineNumber
,
selections
[
2
].
startColumn
,
selections
[
2
].
endLineNumber
,
selections
[
2
].
endColumn
],
[
5
,
1
,
5
,
1
]);
deleteAllLeftAction
.
run
(
null
,
editor
);
selections
=
editor
.
getSelections
();
assert
.
equal
(
model
.
getLineContent
(
1
),
'
hi my name is Carlos Matos waso waso
'
);
assert
.
equal
(
selections
.
length
,
2
);
assert
.
deepEqual
([
selections
[
0
].
startLineNumber
,
selections
[
0
].
startColumn
,
selections
[
0
].
endLineNumber
,
selections
[
0
].
endColumn
],
[
1
,
27
,
1
,
27
]);
assert
.
deepEqual
([
selections
[
1
].
startLineNumber
,
selections
[
1
].
startColumn
,
selections
[
1
].
endLineNumber
,
selections
[
1
].
endColumn
],
[
2
,
29
,
2
,
29
]);
});
});
test
(
'
should work in multi cursor mode
'
,
function
()
{
withTestCodeEditor
(
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录