Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
537ebcf4
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,发现更多精彩内容 >>
未验证
提交
537ebcf4
编写于
11月 14, 2017
作者:
A
Alexandru Dima
提交者:
GitHub
11月 14, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #37196 from Takadimi/Takadimi/36562
#36562 Sort multiple selections
上级
ee854778
4c8d50ca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
131 addition
and
12 deletion
+131
-12
src/vs/editor/contrib/linesOperations/linesOperations.ts
src/vs/editor/contrib/linesOperations/linesOperations.ts
+12
-10
src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts
...itor/contrib/linesOperations/test/linesOperations.test.ts
+118
-1
src/vs/editor/contrib/linesOperations/test/sortLinesCommand.test.ts
...tor/contrib/linesOperations/test/sortLinesCommand.test.ts
+1
-1
未找到文件。
src/vs/editor/contrib/linesOperations/linesOperations.ts
浏览文件 @
537ebcf4
...
...
@@ -140,7 +140,7 @@ class MoveLinesDownAction extends AbstractMoveLinesAction {
}
}
abstract
class
AbstractSortLinesAction
extends
EditorAction
{
export
abstract
class
AbstractSortLinesAction
extends
EditorAction
{
private
descending
:
boolean
;
constructor
(
descending
:
boolean
,
opts
:
IActionOptions
)
{
...
...
@@ -149,16 +149,18 @@ abstract class AbstractSortLinesAction extends EditorAction {
}
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
{
const
selections
=
editor
.
getSelections
();
if
(
!
SortLinesCommand
.
canRun
(
editor
.
getModel
(),
editor
.
getSelection
(),
this
.
descending
))
{
return
;
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
const
selection
=
selections
[
i
];
if
(
!
SortLinesCommand
.
canRun
(
editor
.
getModel
(),
selection
,
this
.
descending
))
{
return
;
}
}
var
commands
:
ICommand
[]
=
[];
var
selections
=
editor
.
getSelections
();
for
(
var
i
=
0
;
i
<
selections
.
length
;
i
++
)
{
commands
.
push
(
new
SortLinesCommand
(
selections
[
i
],
this
.
descending
));
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
commands
[
i
]
=
new
SortLinesCommand
(
selections
[
i
],
this
.
descending
);
}
editor
.
pushUndoStop
();
...
...
@@ -167,7 +169,7 @@ abstract class AbstractSortLinesAction extends EditorAction {
}
}
class
SortLinesAscendingAction
extends
AbstractSortLinesAction
{
export
class
SortLinesAscendingAction
extends
AbstractSortLinesAction
{
constructor
()
{
super
(
false
,
{
id
:
'
editor.action.sortLinesAscending
'
,
...
...
@@ -178,7 +180,7 @@ class SortLinesAscendingAction extends AbstractSortLinesAction {
}
}
class
SortLinesDescendingAction
extends
AbstractSortLinesAction
{
export
class
SortLinesDescendingAction
extends
AbstractSortLinesAction
{
constructor
()
{
super
(
true
,
{
id
:
'
editor.action.sortLinesDescending
'
,
...
...
src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts
浏览文件 @
537ebcf4
...
...
@@ -9,12 +9,129 @@ import { Selection } from 'vs/editor/common/core/selection';
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Handler
,
IModel
,
DefaultEndOfLine
}
from
'
vs/editor/common/editorCommon
'
;
import
{
withTestCodeEditor
}
from
'
vs/editor/test/browser/testCodeEditor
'
;
import
{
DeleteAllLeftAction
,
JoinLinesAction
,
TransposeAction
,
UpperCaseAction
,
LowerCaseAction
,
DeleteAllRightAction
,
InsertLineBeforeAction
,
InsertLineAfterAction
,
IndentLinesAction
}
from
'
vs/editor/contrib/linesOperations/linesOperations
'
;
import
{
DeleteAllLeftAction
,
JoinLinesAction
,
TransposeAction
,
UpperCaseAction
,
LowerCaseAction
,
DeleteAllRightAction
,
InsertLineBeforeAction
,
InsertLineAfterAction
,
IndentLinesAction
,
SortLinesAscendingAction
,
SortLinesDescendingAction
}
from
'
vs/editor/contrib/linesOperations/linesOperations
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
CoreEditingCommands
}
from
'
vs/editor/browser/controller/coreCommands
'
;
suite
(
'
Editor Contrib - Line Operations
'
,
()
=>
{
suite
(
'
SortLinesAscendingAction
'
,
()
=>
{
test
(
'
should sort selected lines in ascending order
'
,
function
()
{
withTestCodeEditor
(
[
'
omicron
'
,
'
beta
'
,
'
alpha
'
],
{},
(
editor
,
cursor
)
=>
{
let
model
=
editor
.
getModel
();
let
sortLinesAscendingAction
=
new
SortLinesAscendingAction
();
editor
.
setSelection
(
new
Selection
(
1
,
1
,
3
,
5
));
sortLinesAscendingAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
model
.
getLinesContent
(),
[
'
alpha
'
,
'
beta
'
,
'
omicron
'
]);
assert
.
deepEqual
(
editor
.
getSelection
().
toString
(),
new
Selection
(
1
,
1
,
3
,
7
).
toString
());
});
});
test
(
'
should sort multiple selections in ascending order
'
,
function
()
{
withTestCodeEditor
(
[
'
omicron
'
,
'
beta
'
,
'
alpha
'
,
''
,
'
omicron
'
,
'
beta
'
,
'
alpha
'
],
{},
(
editor
,
cursor
)
=>
{
let
model
=
editor
.
getModel
();
let
sortLinesAscendingAction
=
new
SortLinesAscendingAction
();
editor
.
setSelections
([
new
Selection
(
1
,
1
,
3
,
5
),
new
Selection
(
5
,
1
,
7
,
5
)]);
sortLinesAscendingAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
model
.
getLinesContent
(),
[
'
alpha
'
,
'
beta
'
,
'
omicron
'
,
''
,
'
alpha
'
,
'
beta
'
,
'
omicron
'
]);
let
expectedSelections
=
[
new
Selection
(
1
,
1
,
3
,
7
),
new
Selection
(
5
,
1
,
7
,
7
)
];
editor
.
getSelections
().
forEach
((
actualSelection
,
index
)
=>
{
assert
.
deepEqual
(
actualSelection
.
toString
(),
expectedSelections
[
index
].
toString
());
});
});
});
});
suite
(
'
SortLinesDescendingAction
'
,
()
=>
{
test
(
'
should sort selected lines in descending order
'
,
function
()
{
withTestCodeEditor
(
[
'
alpha
'
,
'
beta
'
,
'
omicron
'
],
{},
(
editor
,
cursor
)
=>
{
let
model
=
editor
.
getModel
();
let
sortLinesDescendingAction
=
new
SortLinesDescendingAction
();
editor
.
setSelection
(
new
Selection
(
1
,
1
,
3
,
7
));
sortLinesDescendingAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
model
.
getLinesContent
(),
[
'
omicron
'
,
'
beta
'
,
'
alpha
'
]);
assert
.
deepEqual
(
editor
.
getSelection
().
toString
(),
new
Selection
(
1
,
1
,
3
,
5
).
toString
());
});
});
test
(
'
should sort multiple selections in descending order
'
,
function
()
{
withTestCodeEditor
(
[
'
alpha
'
,
'
beta
'
,
'
omicron
'
,
''
,
'
alpha
'
,
'
beta
'
,
'
omicron
'
],
{},
(
editor
,
cursor
)
=>
{
let
model
=
editor
.
getModel
();
let
sortLinesDescendingAction
=
new
SortLinesDescendingAction
();
editor
.
setSelections
([
new
Selection
(
1
,
1
,
3
,
7
),
new
Selection
(
5
,
1
,
7
,
7
)]);
sortLinesDescendingAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
model
.
getLinesContent
(),
[
'
omicron
'
,
'
beta
'
,
'
alpha
'
,
''
,
'
omicron
'
,
'
beta
'
,
'
alpha
'
]);
let
expectedSelections
=
[
new
Selection
(
1
,
1
,
3
,
5
),
new
Selection
(
5
,
1
,
7
,
5
)
];
editor
.
getSelections
().
forEach
((
actualSelection
,
index
)
=>
{
assert
.
deepEqual
(
actualSelection
.
toString
(),
expectedSelections
[
index
].
toString
());
});
});
});
});
suite
(
'
DeleteAllLeftAction
'
,
()
=>
{
test
(
'
should delete to the left of the cursor
'
,
function
()
{
withTestCodeEditor
(
...
...
src/vs/editor/contrib/linesOperations/test/sortLinesCommand.test.ts
浏览文件 @
537ebcf4
...
...
@@ -123,7 +123,7 @@ suite('Editor Contrib - Sort Lines Command', () => {
);
});
test
(
'
sorting first 4 lines des
s
cending
'
,
function
()
{
test
(
'
sorting first 4 lines descending
'
,
function
()
{
testSortLinesDescendingCommand
(
[
'
first
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录