Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a9b5966a
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,发现更多精彩内容 >>
未验证
提交
a9b5966a
编写于
3月 12, 2020
作者:
R
Rob Lourens
提交者:
GitHub
3月 12, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #92404 from microsoft/roblou/focusNextCellAfterExecute
Add some notebook commands
上级
4c58ef49
3f3dcf16
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
182 addition
and
16 deletion
+182
-16
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
...bench/contrib/notebook/browser/contrib/notebookActions.ts
+174
-9
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
+1
-1
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
+2
-1
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
...h/contrib/notebook/browser/view/renderers/cellRenderer.ts
+4
-4
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
+1
-1
未找到文件。
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
浏览文件 @
a9b5966a
...
...
@@ -13,30 +13,93 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import
{
NOTEBOOK_EDITOR_FOCUSED
,
NotebookEditor
}
from
'
vs/workbench/contrib/notebook/browser/notebookEditor
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
CellKind
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel
'
;
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
workbench.action.executeNotebookCell
'
,
title
:
'
Execute Notebook Cell
'
title
:
'
Execute Notebook Cell
'
,
keybinding
:
{
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
InputFocusedContext
),
primary
:
KeyMod
.
WinCtrl
|
KeyCode
.
Enter
,
weight
:
KeybindingWeight
.
WorkbenchContrib
}
});
}
async
run
(
accessor
:
ServicesAccessor
):
Promise
<
void
>
{
let
editorService
=
accessor
.
get
(
IEditorService
);
let
notebookService
=
accessor
.
get
(
INotebookService
);
runActiveCell
(
accessor
);
}
});
let
resource
=
editorService
.
activeEditor
?.
resource
;
if
(
!
resource
)
{
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
workbench.action.executeNotebookCellSelectBelow
'
,
title
:
'
Execute Notebook Cell and Select Below
'
,
keybinding
:
{
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
InputFocusedContext
),
primary
:
KeyMod
.
Shift
|
KeyCode
.
Enter
,
weight
:
KeybindingWeight
.
WorkbenchContrib
}
});
}
async
run
(
accessor
:
ServicesAccessor
):
Promise
<
void
>
{
const
editorService
=
accessor
.
get
(
IEditorService
);
const
activeCell
=
runActiveCell
(
accessor
);
if
(
!
activeCell
)
{
return
;
}
let
notebookProviders
=
notebookService
.
getContributedNotebookProviders
(
resource
!
);
const
editor
=
getActiveNotebookEditor
(
editorService
);
if
(
!
editor
)
{
return
;
}
if
(
notebookProviders
.
length
>
0
)
{
let
viewType
=
notebookProviders
[
0
].
id
;
notebookService
.
executeNotebookActiveCell
(
viewType
,
resource
);
const
idx
=
editor
.
viewModel
?.
getViewCellIndex
(
activeCell
);
if
(
typeof
idx
!==
'
number
'
)
{
return
;
}
// Try to select below, fall back on inserting
const
nextCell
=
editor
.
viewModel
?.
viewCells
[
idx
+
1
];
if
(
nextCell
)
{
editor
.
focusNotebookCell
(
nextCell
,
false
);
}
else
{
editor
.
insertNotebookCell
(
activeCell
,
CellKind
.
Code
,
'
below
'
);
}
}
});
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
workbench.action.executeNotebookCellInsertBelow
'
,
title
:
'
Execute Notebook Cell and Insert Below
'
,
keybinding
:
{
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
InputFocusedContext
),
primary
:
KeyMod
.
Alt
|
KeyCode
.
Enter
,
weight
:
KeybindingWeight
.
WorkbenchContrib
}
});
}
async
run
(
accessor
:
ServicesAccessor
):
Promise
<
void
>
{
const
editorService
=
accessor
.
get
(
IEditorService
);
const
activeCell
=
runActiveCell
(
accessor
);
if
(
!
activeCell
)
{
return
;
}
const
editor
=
getActiveNotebookEditor
(
editorService
);
if
(
!
editor
)
{
return
;
}
editor
.
insertNotebookCell
(
activeCell
,
CellKind
.
Code
,
'
below
'
);
}
});
...
...
@@ -191,8 +254,110 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
when
:
NOTEBOOK_EDITOR_FOCUSED
});
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
workbench.action.changeCellToCode
'
,
title
:
'
Change Cell to Code
'
,
keybinding
:
{
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
ContextKeyExpr
.
not
(
InputFocusedContextKey
)),
primary
:
KeyCode
.
KEY_Y
,
weight
:
KeybindingWeight
.
WorkbenchContrib
}
});
}
async
run
(
accessor
:
ServicesAccessor
):
Promise
<
void
>
{
return
changeActiveCellToKind
(
CellKind
.
Code
,
accessor
);
}
});
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
workbench.action.changeCellToMarkdown
'
,
title
:
'
Change Cell to Markdown
'
,
keybinding
:
{
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
ContextKeyExpr
.
not
(
InputFocusedContextKey
)),
primary
:
KeyCode
.
KEY_M
,
weight
:
KeybindingWeight
.
WorkbenchContrib
}
});
}
async
run
(
accessor
:
ServicesAccessor
):
Promise
<
void
>
{
return
changeActiveCellToKind
(
CellKind
.
Markdown
,
accessor
);
}
});
function
getActiveNotebookEditor
(
editorService
:
IEditorService
):
NotebookEditor
|
undefined
{
const
activeEditorPane
=
editorService
.
activeEditorPane
as
NotebookEditor
|
undefined
;
return
activeEditorPane
?.
isNotebookEditor
?
activeEditorPane
:
undefined
;
}
function
runActiveCell
(
accessor
:
ServicesAccessor
):
CellViewModel
|
undefined
{
const
editorService
=
accessor
.
get
(
IEditorService
);
const
notebookService
=
accessor
.
get
(
INotebookService
);
const
resource
=
editorService
.
activeEditor
?.
resource
;
if
(
!
resource
)
{
return
;
}
const
editor
=
getActiveNotebookEditor
(
editorService
);
if
(
!
editor
)
{
return
;
}
const
notebookProviders
=
notebookService
.
getContributedNotebookProviders
(
resource
);
if
(
!
notebookProviders
.
length
)
{
return
;
}
const
activeCell
=
editor
.
getActiveCell
();
if
(
!
activeCell
)
{
return
;
}
const
idx
=
editor
.
viewModel
?.
getViewCellIndex
(
activeCell
);
if
(
typeof
idx
!==
'
number
'
)
{
return
;
}
const
viewType
=
notebookProviders
[
0
].
id
;
notebookService
.
executeNotebookActiveCell
(
viewType
,
resource
);
return
activeCell
;
}
function
changeActiveCellToKind
(
kind
:
CellKind
,
accessor
:
ServicesAccessor
):
void
{
const
editorService
=
accessor
.
get
(
IEditorService
);
const
editor
=
getActiveNotebookEditor
(
editorService
);
if
(
!
editor
)
{
return
;
}
const
activeCell
=
editor
.
getActiveCell
();
if
(
!
activeCell
)
{
return
;
}
if
(
activeCell
.
cellKind
===
kind
)
{
return
;
}
const
text
=
activeCell
.
getText
();
editor
.
insertNotebookCell
(
activeCell
,
kind
,
'
below
'
,
text
);
const
idx
=
editor
.
viewModel
?.
getViewCellIndex
(
activeCell
);
if
(
typeof
idx
!==
'
number
'
)
{
return
;
}
const
newCell
=
editor
.
viewModel
?.
viewCells
[
idx
+
1
];
if
(
!
newCell
)
{
return
;
}
editor
.
focusNotebookCell
(
newCell
,
false
);
editor
.
deleteNotebookCell
(
activeCell
);
}
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
浏览文件 @
a9b5966a
...
...
@@ -46,7 +46,7 @@ export interface INotebookEditor {
/**
* Insert a new cell around `cell`
*/
insert
EmptyNotebookCell
(
cell
:
CellViewModel
,
type
:
CellKind
,
direction
:
'
above
'
|
'
below
'
):
Promise
<
void
>
;
insert
NotebookCell
(
cell
:
CellViewModel
,
type
:
CellKind
,
direction
:
'
above
'
|
'
below
'
,
initialText
?:
string
):
Promise
<
void
>
;
/**
* Delete a cell from the notebook
...
...
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
浏览文件 @
a9b5966a
...
...
@@ -534,12 +534,13 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
});
}
async
insert
EmptyNotebookCell
(
cell
:
CellViewModel
,
type
:
CellKind
,
direction
:
'
above
'
|
'
below
'
):
Promise
<
void
>
{
async
insert
NotebookCell
(
cell
:
CellViewModel
,
type
:
CellKind
,
direction
:
'
above
'
|
'
below
'
,
initialText
:
string
=
'
'
):
Promise
<
void
>
{
const
newLanguages
=
this
.
notebookViewModel
!
.
languages
;
const
language
=
newLanguages
&&
newLanguages
.
length
?
newLanguages
[
0
]
:
'
markdown
'
;
const
index
=
this
.
notebookViewModel
!
.
getViewCellIndex
(
cell
);
const
insertIndex
=
direction
===
'
above
'
?
index
:
index
+
1
;
const
newModeCell
=
await
this
.
notebookService
.
createNotebookCell
(
this
.
notebookViewModel
!
.
viewType
,
this
.
notebookViewModel
!
.
uri
,
insertIndex
,
language
,
type
);
newModeCell
!
.
source
=
initialText
.
split
(
/
\r?\n
/g
);
const
newCell
=
this
.
notebookViewModel
!
.
insertCell
(
insertIndex
,
newModeCell
!
);
this
.
list
?.
splice
(
insertIndex
,
0
,
[
newCell
]);
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
浏览文件 @
a9b5966a
...
...
@@ -89,7 +89,7 @@ class AbstractCellRenderer {
undefined
,
true
,
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Code
,
'
above
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Code
,
'
above
'
);
}
);
actions
.
push
(
insertAbove
);
...
...
@@ -100,7 +100,7 @@ class AbstractCellRenderer {
undefined
,
true
,
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Code
,
'
below
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Code
,
'
below
'
);
}
);
actions
.
push
(
insertBelow
);
...
...
@@ -111,7 +111,7 @@ class AbstractCellRenderer {
undefined
,
true
,
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Markdown
,
'
above
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Markdown
,
'
above
'
);
}
);
actions
.
push
(
insertMarkdownAbove
);
...
...
@@ -122,7 +122,7 @@ class AbstractCellRenderer {
undefined
,
true
,
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Markdown
,
'
below
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Markdown
,
'
below
'
);
}
);
actions
.
push
(
insertMarkdownBelow
);
...
...
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
浏览文件 @
a9b5966a
...
...
@@ -134,7 +134,7 @@ export class TestNotebookEditor implements INotebookEditor {
revealInCenterIfOutsideViewport
(
cell
:
CellViewModel
):
void
{
throw
new
Error
(
'
Method not implemented.
'
);
}
async
insert
Empty
NotebookCell
(
cell
:
CellViewModel
,
type
:
CellKind
,
direction
:
'
above
'
|
'
below
'
):
Promise
<
void
>
{
async
insertNotebookCell
(
cell
:
CellViewModel
,
type
:
CellKind
,
direction
:
'
above
'
|
'
below
'
):
Promise
<
void
>
{
// throw new Error('Method not implemented.');
}
deleteNotebookCell
(
cell
:
CellViewModel
):
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录