Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
a29d44c6
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,发现更多精彩内容 >>
提交
a29d44c6
编写于
1月 23, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #41940
上级
1502c8c2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
31 deletion
+82
-31
src/vs/workbench/browser/parts/editor/editorCommands.ts
src/vs/workbench/browser/parts/editor/editorCommands.ts
+69
-28
src/vs/workbench/browser/parts/editor/titleControl.ts
src/vs/workbench/browser/parts/editor/titleControl.ts
+3
-3
src/vs/workbench/common/editor.ts
src/vs/workbench/common/editor.ts
+10
-0
未找到文件。
src/vs/workbench/browser/parts/editor/editorCommands.ts
浏览文件 @
a29d44c6
...
...
@@ -8,7 +8,7 @@ import * as types from 'vs/base/common/types';
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
ActiveEditorMoveArguments
,
ActiveEditorMovePositioning
,
ActiveEditorMovePositioningBy
,
EditorCommands
,
TextCompareEditorVisible
,
EditorInput
,
IEditorIdentifier
}
from
'
vs/workbench/common/editor
'
;
import
{
ActiveEditorMoveArguments
,
ActiveEditorMovePositioning
,
ActiveEditorMovePositioningBy
,
EditorCommands
,
TextCompareEditorVisible
,
EditorInput
,
IEditorIdentifier
,
IEditorCommandsContext
}
from
'
vs/workbench/common/editor
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEditor
,
Position
,
POSITIONS
,
Direction
,
IEditorInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
...
...
@@ -190,10 +190,18 @@ function registerDiffEditorCommands(): void {
weight
:
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
(),
when
:
void
0
,
primary
:
void
0
,
handler
:
(
accessor
)
=>
{
handler
:
(
accessor
,
resource
,
context
:
IEditorCommandsContext
)
=>
{
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
let
editor
:
IEditor
;
if
(
context
)
{
const
position
=
positionAndInput
(
editorGroupService
,
editorService
,
context
).
position
;
editor
=
editorService
.
getVisibleEditors
()[
position
];
}
else
{
editor
=
editorService
.
getActiveEditor
();
}
const
editor
=
editorService
.
getActiveEditor
();
if
(
editor
instanceof
TextDiffEditor
)
{
const
control
=
editor
.
getControl
();
const
isInlineMode
=
!
control
.
renderSideBySide
;
...
...
@@ -262,15 +270,15 @@ function registerEditorCommands() {
weight
:
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
(),
when
:
void
0
,
primary
:
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyCode
.
KEY_U
),
handler
:
(
accessor
,
resource
:
URI
,
editorContext
:
IEditorIdentifier
)
=>
{
handler
:
(
accessor
,
resource
:
URI
,
context
:
IEditorIdentifier
|
IEditorCommandsContext
)
=>
{
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
const
model
=
editorGroupService
.
getStacksModel
();
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
contexts
=
getMultiSelectedEditorContexts
(
editorContext
,
accessor
.
get
(
IListService
));
const
contexts
=
getMultiSelectedEditorContexts
(
toEditorIdentifier
(
context
,
editorGroupService
)
,
accessor
.
get
(
IListService
));
let
positionOne
:
{
unmodifiedOnly
:
boolean
}
=
undefined
;
let
positionTwo
:
{
unmodifiedOnly
:
boolean
}
=
undefined
;
let
positionThree
:
{
unmodifiedOnly
:
boolean
}
=
undefined
;
let
positionOne
:
{
unmodifiedOnly
:
boolean
}
=
void
0
;
let
positionTwo
:
{
unmodifiedOnly
:
boolean
}
=
void
0
;
let
positionThree
:
{
unmodifiedOnly
:
boolean
}
=
void
0
;
contexts
.
forEach
(
c
=>
{
switch
(
model
.
positionOfGroup
(
c
.
group
))
{
case
Position
.
ONE
:
positionOne
=
{
unmodifiedOnly
:
true
};
break
;
...
...
@@ -288,10 +296,10 @@ function registerEditorCommands() {
weight
:
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
(),
when
:
void
0
,
primary
:
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyCode
.
KEY_W
),
handler
:
(
accessor
,
resource
:
URI
,
editorContext
:
IEditorIdentifier
)
=>
{
handler
:
(
accessor
,
resource
:
URI
,
context
:
IEditorIdentifier
|
IEditorCommandsContext
)
=>
{
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
contexts
=
getMultiSelectedEditorContexts
(
editorContext
,
accessor
.
get
(
IListService
));
const
contexts
=
getMultiSelectedEditorContexts
(
toEditorIdentifier
(
context
,
editorGroupService
)
,
accessor
.
get
(
IListService
));
const
distinctGroups
=
distinct
(
contexts
.
map
(
c
=>
c
.
group
));
if
(
distinctGroups
.
length
)
{
...
...
@@ -312,11 +320,11 @@ function registerEditorCommands() {
when
:
void
0
,
primary
:
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_W
,
win
:
{
primary
:
KeyMod
.
CtrlCmd
|
KeyCode
.
F4
,
secondary
:
[
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_W
]
},
handler
:
(
accessor
,
resource
:
URI
,
editorContext
:
IEditorIdentifier
)
=>
{
handler
:
(
accessor
,
resource
:
URI
,
context
:
IEditorIdentifier
|
IEditorCommandsContext
)
=>
{
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
contexts
=
getMultiSelectedEditorContexts
(
editorContext
,
accessor
.
get
(
IListService
));
const
contexts
=
getMultiSelectedEditorContexts
(
toEditorIdentifier
(
context
,
editorGroupService
)
,
accessor
.
get
(
IListService
));
const
groups
=
distinct
(
contexts
.
map
(
context
=>
context
.
group
));
const
editorsToClose
=
new
Map
<
Position
,
IEditorInput
[]
>
();
...
...
@@ -326,7 +334,7 @@ function registerEditorCommands() {
if
(
position
>=
0
)
{
editorsToClose
.
set
(
position
,
contexts
.
map
(
c
=>
{
if
(
group
===
c
.
group
)
{
let
input
=
c
?
c
.
editor
:
undefined
;
let
input
=
c
?
c
.
editor
:
void
0
;
if
(
!
input
)
{
// Get Top Editor at Position
...
...
@@ -339,7 +347,7 @@ function registerEditorCommands() {
return
input
;
}
return
undefined
;
return
void
0
;
}).
filter
(
input
=>
!!
input
));
}
});
...
...
@@ -365,10 +373,10 @@ function registerEditorCommands() {
when
:
void
0
,
primary
:
void
0
,
mac
:
{
primary
:
KeyMod
.
CtrlCmd
|
KeyMod
.
Alt
|
KeyCode
.
KEY_T
},
handler
:
(
accessor
,
resource
:
URI
,
editorContext
:
IEditorIdentifier
)
=>
{
handler
:
(
accessor
,
resource
:
URI
,
context
:
IEditorIdentifier
|
IEditorCommandsContext
)
=>
{
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
contexts
=
getMultiSelectedEditorContexts
(
editorContext
,
accessor
.
get
(
IListService
));
const
contexts
=
getMultiSelectedEditorContexts
(
toEditorIdentifier
(
context
,
editorGroupService
)
,
accessor
.
get
(
IListService
));
const
groups
=
distinct
(
contexts
.
map
(
context
=>
context
.
group
));
const
editorsToClose
=
new
Map
<
Position
,
IEditorInput
[]
>
();
...
...
@@ -378,7 +386,7 @@ function registerEditorCommands() {
return
c
.
editor
;
}
return
undefined
;
return
void
0
;
}).
filter
(
input
=>
!!
input
);
const
toClose
=
group
.
getEditors
().
filter
(
input
=>
inputsToSkip
.
indexOf
(
input
)
===
-
1
);
...
...
@@ -398,11 +406,11 @@ function registerEditorCommands() {
weight
:
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
(),
when
:
void
0
,
primary
:
void
0
,
handler
:
(
accessor
,
resource
:
URI
,
editorContext
:
IEditorIdentifier
)
=>
{
handler
:
(
accessor
,
resource
:
URI
,
context
:
IEditorIdentifier
|
IEditorCommandsContext
)
=>
{
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
{
position
,
input
}
=
positionAndInput
(
editorGroupService
,
editorService
,
editorC
ontext
);
const
{
position
,
input
}
=
positionAndInput
(
editorGroupService
,
editorService
,
c
ontext
);
if
(
typeof
position
===
'
number
'
&&
input
)
{
return
editorService
.
closeEditors
(
position
,
{
except
:
input
,
direction
:
Direction
.
RIGHT
});
...
...
@@ -417,11 +425,11 @@ function registerEditorCommands() {
weight
:
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
(),
when
:
void
0
,
primary
:
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyCode
.
Enter
),
handler
:
(
accessor
,
resource
:
URI
,
editorContext
:
IEditorIdentifier
)
=>
{
handler
:
(
accessor
,
resource
:
URI
,
context
:
IEditorIdentifier
|
IEditorCommandsContext
)
=>
{
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
{
position
,
input
}
=
positionAndInput
(
editorGroupService
,
editorService
,
editorC
ontext
);
const
{
position
,
input
}
=
positionAndInput
(
editorGroupService
,
editorService
,
c
ontext
);
if
(
typeof
position
===
'
number
'
&&
input
)
{
return
editorGroupService
.
pinEditor
(
position
,
input
);
...
...
@@ -436,7 +444,7 @@ function registerEditorCommands() {
weight
:
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
(),
when
:
void
0
,
primary
:
void
0
,
handler
:
(
accessor
,
resource
:
URI
,
editorContext
:
IEditorIdentifier
)
=>
{
handler
:
(
accessor
,
resource
:
URI
,
context
:
IEditorCommandsContext
)
=>
{
const
editorGroupService
=
accessor
.
get
(
IEditorGroupService
);
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
const
quickOpenService
=
accessor
.
get
(
IQuickOpenService
);
...
...
@@ -447,7 +455,7 @@ function registerEditorCommands() {
return
quickOpenService
.
show
(
NAVIGATE_ALL_EDITORS_GROUP_PREFIX
);
}
const
{
position
}
=
positionAndInput
(
editorGroupService
,
editorService
,
editorC
ontext
);
const
{
position
}
=
positionAndInput
(
editorGroupService
,
editorService
,
c
ontext
);
switch
(
position
)
{
case
Position
.
TWO
:
...
...
@@ -481,7 +489,10 @@ function registerEditorCommands() {
});
}
function
positionAndInput
(
editorGroupService
:
IEditorGroupService
,
editorService
:
IWorkbenchEditorService
,
editorContext
?:
IEditorIdentifier
):
{
position
:
Position
,
input
:
IEditorInput
}
{
function
positionAndInput
(
editorGroupService
:
IEditorGroupService
,
editorService
:
IWorkbenchEditorService
,
context
?:
IEditorIdentifier
|
IEditorCommandsContext
):
{
position
:
Position
,
input
:
IEditorInput
}
{
// Resolve from context
const
editorContext
=
toEditorIdentifier
(
context
,
editorGroupService
);
let
position
=
editorContext
?
editorGroupService
.
getStacksModel
().
positionOfGroup
(
editorContext
.
group
)
:
null
;
let
input
=
editorContext
?
editorContext
.
editor
:
null
;
...
...
@@ -496,14 +507,14 @@ function positionAndInput(editorGroupService: IEditorGroupService, editorService
}
export
function
getMultiSelectedEditorContexts
(
editorContext
:
IEditorIdentifier
,
listService
:
IListService
):
IEditorIdentifier
[]
{
const
list
=
listService
.
lastFocusedList
;
// Mapping for open editors view
const
isEditorIdentifier
=
(
element
:
any
)
=>
'
group
'
in
element
&&
'
editor
'
in
element
;
const
elementToContext
=
(
element
:
IEditorIdentifier
|
EditorGroup
)
=>
element
instanceof
EditorGroup
?
{
group
:
element
,
editor
:
undefined
}
:
element
;
const
elementToContext
=
(
element
:
IEditorIdentifier
|
EditorGroup
)
=>
element
instanceof
EditorGroup
?
{
group
:
element
,
editor
:
void
0
}
:
element
;
// First check for a focused list to return the selected items from
const
list
=
listService
.
lastFocusedList
;
if
(
list
instanceof
List
&&
list
.
isDOMFocused
())
{
const
selection
=
list
.
getSelectedElements
();
const
focus
=
list
.
getFocusedElements
();
// Only respect selection if it contains focused element
if
(
focus
.
length
&&
selection
&&
selection
.
indexOf
(
focus
[
0
])
>=
0
)
{
return
list
.
getSelectedElements
().
filter
(
e
=>
e
instanceof
EditorGroup
||
isEditorIdentifier
(
e
)).
map
(
elementToContext
);
...
...
@@ -514,5 +525,35 @@ export function getMultiSelectedEditorContexts(editorContext: IEditorIdentifier,
}
}
// Otherwise go with passed in context
return
!!
editorContext
?
[
editorContext
]
:
[];
}
function
isEditorIdentifier
(
object
:
any
):
object
is
IEditorIdentifier
{
const
identifier
=
object
as
IEditorIdentifier
;
return
identifier
&&
!!
identifier
.
group
&&
!!
identifier
.
editor
;
}
function
isEditorGroupContext
(
object
:
any
):
object
is
IEditorCommandsContext
{
const
context
=
object
as
IEditorCommandsContext
;
return
context
&&
typeof
context
.
groupId
===
'
number
'
;
}
function
toEditorIdentifier
(
object
:
IEditorIdentifier
|
IEditorCommandsContext
,
editorGroupService
:
IEditorGroupService
):
IEditorIdentifier
{
if
(
isEditorIdentifier
(
object
))
{
return
object
as
IEditorIdentifier
;
}
if
(
isEditorGroupContext
(
object
))
{
const
stacks
=
editorGroupService
.
getStacksModel
();
const
group
=
stacks
.
getGroup
(
object
.
groupId
);
return
{
group
,
editor
:
typeof
object
.
editorIndex
===
'
number
'
?
group
.
getEditor
(
object
.
editorIndex
)
:
void
0
};
}
return
void
0
;
}
\ No newline at end of file
src/vs/workbench/browser/parts/editor/titleControl.ts
浏览文件 @
a29d44c6
...
...
@@ -15,7 +15,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
BaseEditor
}
from
'
vs/workbench/browser/parts/editor/baseEditor
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
arrays
=
require
(
'
vs/base/common/arrays
'
);
import
{
IEditorStacksModel
,
IEditorGroup
,
IEditorIdentifier
,
EditorInput
,
IStacksModelChangeEvent
,
toResource
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorStacksModel
,
IEditorGroup
,
IEditorIdentifier
,
EditorInput
,
IStacksModelChangeEvent
,
toResource
,
IEditorCommandsContext
}
from
'
vs/workbench/common/editor
'
;
import
{
IActionItem
,
ActionsOrientation
}
from
'
vs/base/browser/ui/actionbar/actionbar
'
;
import
{
ToolBar
}
from
'
vs/base/browser/ui/toolbar/toolbar
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
...
...
@@ -171,7 +171,7 @@ export abstract class TitleControl extends Themable implements ITitleAreaControl
public
setContext
(
group
:
IEditorGroup
):
void
{
this
.
context
=
group
;
this
.
editorActionsToolbar
.
context
=
{
group
}
;
this
.
editorActionsToolbar
.
context
=
{
group
Id
:
group
?
group
.
id
:
void
0
}
as
IEditorCommandsContext
;
}
public
hasContext
():
boolean
{
...
...
@@ -398,7 +398,7 @@ export abstract class TitleControl extends Themable implements ITitleAreaControl
this
.
contextMenuService
.
showContextMenu
({
getAnchor
:
()
=>
anchor
,
getActions
:
()
=>
TPromise
.
as
(
actions
),
getActionsContext
:
()
=>
identifier
,
getActionsContext
:
()
=>
({
groupId
:
identifier
.
group
.
id
,
editorIndex
:
identifier
.
group
.
indexOf
(
identifier
.
editor
)
}
as
IEditorCommandsContext
)
,
getKeyBinding
:
(
action
)
=>
this
.
getKeybinding
(
action
),
onHide
:
(
cancel
)
=>
{
...
...
src/vs/workbench/common/editor.ts
浏览文件 @
a29d44c6
...
...
@@ -788,6 +788,16 @@ export interface IEditorIdentifier {
editor
:
IEditorInput
;
}
/**
* The editor commands context is used for editor commands (e.g. in the editor title)
* and we must ensure that the context is serializable because it potentially travels
* to the extension host!
*/
export
interface
IEditorCommandsContext
{
groupId
:
GroupIdentifier
;
editorIndex
?:
number
;
}
export
interface
IEditorCloseEvent
extends
IEditorIdentifier
{
replaced
:
boolean
;
index
:
number
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录