Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3f3dcf16
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,发现更多精彩内容 >>
提交
3f3dcf16
编写于
3月 10, 2020
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add commands to convert cell to markdown/code
上级
e814a196
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
77 addition
and
9 deletion
+77
-9
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
...bench/contrib/notebook/browser/contrib/notebookActions.ts
+69
-2
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
浏览文件 @
3f3dcf16
...
@@ -69,7 +69,7 @@ registerAction2(class extends Action2 {
...
@@ -69,7 +69,7 @@ registerAction2(class extends Action2 {
if
(
nextCell
)
{
if
(
nextCell
)
{
editor
.
focusNotebookCell
(
nextCell
,
false
);
editor
.
focusNotebookCell
(
nextCell
,
false
);
}
else
{
}
else
{
editor
.
insert
Empty
NotebookCell
(
activeCell
,
CellKind
.
Code
,
'
below
'
);
editor
.
insertNotebookCell
(
activeCell
,
CellKind
.
Code
,
'
below
'
);
}
}
}
}
});
});
...
@@ -99,7 +99,7 @@ registerAction2(class extends Action2 {
...
@@ -99,7 +99,7 @@ registerAction2(class extends Action2 {
return
;
return
;
}
}
editor
.
insert
Empty
NotebookCell
(
activeCell
,
CellKind
.
Code
,
'
below
'
);
editor
.
insertNotebookCell
(
activeCell
,
CellKind
.
Code
,
'
below
'
);
}
}
});
});
...
@@ -254,6 +254,41 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
...
@@ -254,6 +254,41 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
when
:
NOTEBOOK_EDITOR_FOCUSED
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
{
function
getActiveNotebookEditor
(
editorService
:
IEditorService
):
NotebookEditor
|
undefined
{
const
activeEditorPane
=
editorService
.
activeEditorPane
as
NotebookEditor
|
undefined
;
const
activeEditorPane
=
editorService
.
activeEditorPane
as
NotebookEditor
|
undefined
;
...
@@ -294,3 +329,35 @@ function runActiveCell(accessor: ServicesAccessor): CellViewModel | undefined {
...
@@ -294,3 +329,35 @@ function runActiveCell(accessor: ServicesAccessor): CellViewModel | undefined {
return
activeCell
;
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
浏览文件 @
3f3dcf16
...
@@ -46,7 +46,7 @@ export interface INotebookEditor {
...
@@ -46,7 +46,7 @@ export interface INotebookEditor {
/**
/**
* Insert a new cell around `cell`
* 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
* Delete a cell from the notebook
...
...
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
浏览文件 @
3f3dcf16
...
@@ -534,12 +534,13 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
...
@@ -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
newLanguages
=
this
.
notebookViewModel
!
.
languages
;
const
language
=
newLanguages
&&
newLanguages
.
length
?
newLanguages
[
0
]
:
'
markdown
'
;
const
language
=
newLanguages
&&
newLanguages
.
length
?
newLanguages
[
0
]
:
'
markdown
'
;
const
index
=
this
.
notebookViewModel
!
.
getViewCellIndex
(
cell
);
const
index
=
this
.
notebookViewModel
!
.
getViewCellIndex
(
cell
);
const
insertIndex
=
direction
===
'
above
'
?
index
:
index
+
1
;
const
insertIndex
=
direction
===
'
above
'
?
index
:
index
+
1
;
const
newModeCell
=
await
this
.
notebookService
.
createNotebookCell
(
this
.
notebookViewModel
!
.
viewType
,
this
.
notebookViewModel
!
.
uri
,
insertIndex
,
language
,
type
);
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
!
);
const
newCell
=
this
.
notebookViewModel
!
.
insertCell
(
insertIndex
,
newModeCell
!
);
this
.
list
?.
splice
(
insertIndex
,
0
,
[
newCell
]);
this
.
list
?.
splice
(
insertIndex
,
0
,
[
newCell
]);
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
浏览文件 @
3f3dcf16
...
@@ -89,7 +89,7 @@ class AbstractCellRenderer {
...
@@ -89,7 +89,7 @@ class AbstractCellRenderer {
undefined
,
undefined
,
true
,
true
,
async
()
=>
{
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Code
,
'
above
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Code
,
'
above
'
);
}
}
);
);
actions
.
push
(
insertAbove
);
actions
.
push
(
insertAbove
);
...
@@ -100,7 +100,7 @@ class AbstractCellRenderer {
...
@@ -100,7 +100,7 @@ class AbstractCellRenderer {
undefined
,
undefined
,
true
,
true
,
async
()
=>
{
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Code
,
'
below
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Code
,
'
below
'
);
}
}
);
);
actions
.
push
(
insertBelow
);
actions
.
push
(
insertBelow
);
...
@@ -111,7 +111,7 @@ class AbstractCellRenderer {
...
@@ -111,7 +111,7 @@ class AbstractCellRenderer {
undefined
,
undefined
,
true
,
true
,
async
()
=>
{
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Markdown
,
'
above
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Markdown
,
'
above
'
);
}
}
);
);
actions
.
push
(
insertMarkdownAbove
);
actions
.
push
(
insertMarkdownAbove
);
...
@@ -122,7 +122,7 @@ class AbstractCellRenderer {
...
@@ -122,7 +122,7 @@ class AbstractCellRenderer {
undefined
,
undefined
,
true
,
true
,
async
()
=>
{
async
()
=>
{
await
this
.
notebookEditor
.
insert
Empty
NotebookCell
(
element
,
CellKind
.
Markdown
,
'
below
'
);
await
this
.
notebookEditor
.
insertNotebookCell
(
element
,
CellKind
.
Markdown
,
'
below
'
);
}
}
);
);
actions
.
push
(
insertMarkdownBelow
);
actions
.
push
(
insertMarkdownBelow
);
...
...
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
浏览文件 @
3f3dcf16
...
@@ -134,7 +134,7 @@ export class TestNotebookEditor implements INotebookEditor {
...
@@ -134,7 +134,7 @@ export class TestNotebookEditor implements INotebookEditor {
revealInCenterIfOutsideViewport
(
cell
:
CellViewModel
):
void
{
revealInCenterIfOutsideViewport
(
cell
:
CellViewModel
):
void
{
throw
new
Error
(
'
Method not implemented.
'
);
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.');
// throw new Error('Method not implemented.');
}
}
deleteNotebookCell
(
cell
:
CellViewModel
):
void
{
deleteNotebookCell
(
cell
:
CellViewModel
):
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录