Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2b646152
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,发现更多精彩内容 >>
提交
2b646152
编写于
3月 20, 2020
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove MenuItemActions to simplify action registration code
上级
a0d07dcf
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
131 addition
and
328 deletion
+131
-328
src/vs/workbench/api/browser/mainThreadNotebook.ts
src/vs/workbench/api/browser/mainThreadNotebook.ts
+1
-1
src/vs/workbench/api/common/extHostNotebook.ts
src/vs/workbench/api/common/extHostNotebook.ts
+1
-1
src/vs/workbench/contrib/notebook/browser/constants.ts
src/vs/workbench/contrib/notebook/browser/constants.ts
+6
-1
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
...bench/contrib/notebook/browser/contrib/notebookActions.ts
+74
-186
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
+2
-1
src/vs/workbench/contrib/notebook/browser/notebookEditorInput.ts
...workbench/contrib/notebook/browser/notebookEditorInput.ts
+1
-1
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
...h/contrib/notebook/browser/view/renderers/cellRenderer.ts
+33
-127
src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts
...ch/contrib/notebook/common/model/notebookCellTextModel.ts
+3
-2
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
...kbench/contrib/notebook/common/model/notebookTextModel.ts
+1
-1
src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts
...workbench/contrib/notebook/test/notebookViewModel.test.ts
+6
-4
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
+3
-3
未找到文件。
src/vs/workbench/api/browser/mainThreadNotebook.ts
浏览文件 @
2b646152
...
@@ -241,7 +241,7 @@ export class MainThreadNotebookController implements IMainNotebookController {
...
@@ -241,7 +241,7 @@ export class MainThreadNotebookController implements IMainNotebookController {
async
createRawCell
(
uri
:
URI
,
index
:
number
,
language
:
string
,
type
:
CellKind
):
Promise
<
NotebookCellTextModel
|
undefined
>
{
async
createRawCell
(
uri
:
URI
,
index
:
number
,
language
:
string
,
type
:
CellKind
):
Promise
<
NotebookCellTextModel
|
undefined
>
{
let
cell
=
await
this
.
_proxy
.
$createEmptyCell
(
this
.
_viewType
,
uri
,
index
,
language
,
type
);
let
cell
=
await
this
.
_proxy
.
$createEmptyCell
(
this
.
_viewType
,
uri
,
index
,
language
,
type
);
if
(
cell
)
{
if
(
cell
)
{
let
mainCell
=
new
NotebookCellTextModel
(
URI
.
revive
(
cell
.
uri
),
cell
.
handle
,
cell
.
source
,
cell
.
language
,
cell
.
cellKind
,
cell
.
outputs
);
let
mainCell
=
new
NotebookCellTextModel
(
URI
.
revive
(
cell
.
uri
),
cell
.
handle
,
cell
.
source
,
cell
.
language
,
cell
.
cellKind
,
cell
.
outputs
,
cell
.
metadata
);
return
mainCell
;
return
mainCell
;
}
}
...
...
src/vs/workbench/api/common/extHostNotebook.ts
浏览文件 @
2b646152
...
@@ -580,7 +580,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
...
@@ -580,7 +580,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
let
editor
=
this
.
_editors
.
get
(
URI
.
revive
(
uri
).
toString
());
let
editor
=
this
.
_editors
.
get
(
URI
.
revive
(
uri
).
toString
());
let
document
=
this
.
_documents
.
get
(
URI
.
revive
(
uri
).
toString
());
let
document
=
this
.
_documents
.
get
(
URI
.
revive
(
uri
).
toString
());
let
rawCell
=
editor
?.
editor
.
createCell
(
''
,
language
,
type
,
[],
undefined
)
as
ExtHostCell
;
let
rawCell
=
editor
?.
editor
.
createCell
(
''
,
language
,
type
,
[],
{
editable
:
true
}
)
as
ExtHostCell
;
document
?.
insertCell
(
index
,
rawCell
!
);
document
?.
insertCell
(
index
,
rawCell
!
);
let
allDocuments
=
this
.
_documentsAndEditors
.
allDocuments
();
let
allDocuments
=
this
.
_documentsAndEditors
.
allDocuments
();
...
...
src/vs/workbench/contrib/notebook/browser/constants.ts
浏览文件 @
2b646152
...
@@ -26,5 +26,10 @@ export const EDITOR_BOTTOM_PADDING = 8;
...
@@ -26,5 +26,10 @@ export const EDITOR_BOTTOM_PADDING = 8;
export
const
EDITOR_TOOLBAR_HEIGHT
=
22
;
export
const
EDITOR_TOOLBAR_HEIGHT
=
22
;
export
const
RUN_BUTTON_WIDTH
=
20
;
export
const
RUN_BUTTON_WIDTH
=
20
;
// C
ontext K
eys
// C
ell context k
eys
export
const
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
=
'
notebookCellType
'
;
export
const
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
=
'
notebookCellType
'
;
export
const
NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY
=
'
notebookCellEditable
'
;
export
const
NOTEBOOK_CELL_MARKDOWN_EDIT_MODE_CONTEXT_KEY
=
'
notebookCellMarkdownEditMode
'
;
// Notebook context keys
export
const
NOTEBOOK_EDITABLE_CONTEXT_KEY
=
'
notebookEditable
'
;
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
浏览文件 @
2b646152
...
@@ -11,12 +11,21 @@ import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/commo
...
@@ -11,12 +11,21 @@ import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/commo
import
{
InputFocusedContext
,
InputFocusedContextKey
,
IsDevelopmentContext
}
from
'
vs/platform/contextkey/common/contextkeys
'
;
import
{
InputFocusedContext
,
InputFocusedContextKey
,
IsDevelopmentContext
}
from
'
vs/platform/contextkey/common/contextkeys
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
KeybindingWeight
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
KeybindingWeight
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
COPY_CELL_DOWN_COMMAND_ID
,
COPY_CELL_UP_COMMAND_ID
,
DELETE_CELL_COMMAND_ID
,
EDIT_CELL_COMMAND_ID
,
EXECUTE_CELL_COMMAND_ID
,
INSERT_CODE_CELL_ABOVE_COMMAND_ID
,
INSERT_CODE_CELL_BELOW_COMMAND_ID
,
INSERT_MARKDOWN_CELL_ABOVE_COMMAND_ID
,
INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID
,
MOVE_CELL_DOWN_COMMAND_ID
,
MOVE_CELL_UP_COMMAND_ID
,
SAVE_CELL_COMMAND_ID
}
from
'
vs/workbench/contrib/notebook/browser/constants
'
;
import
{
COPY_CELL_DOWN_COMMAND_ID
,
COPY_CELL_UP_COMMAND_ID
,
DELETE_CELL_COMMAND_ID
,
EDIT_CELL_COMMAND_ID
,
EXECUTE_CELL_COMMAND_ID
,
INSERT_CODE_CELL_ABOVE_COMMAND_ID
,
INSERT_CODE_CELL_BELOW_COMMAND_ID
,
INSERT_MARKDOWN_CELL_ABOVE_COMMAND_ID
,
INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID
,
MOVE_CELL_DOWN_COMMAND_ID
,
MOVE_CELL_UP_COMMAND_ID
,
SAVE_CELL_COMMAND_ID
,
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
NOTEBOOK_EDITABLE_CONTEXT_KEY
,
NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY
}
from
'
vs/workbench/contrib/notebook/browser/constants
'
;
import
{
CellRenderTemplate
,
CellEditState
,
ICellViewModel
,
INotebookEditor
,
KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED
,
NOTEBOOK_EDITOR_FOCUSED
,
CellRunState
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
CellRenderTemplate
,
CellEditState
,
ICellViewModel
,
INotebookEditor
,
KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED
,
NOTEBOOK_EDITOR_FOCUSED
,
CellRunState
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
INotebookService
}
from
'
vs/workbench/contrib/notebook/browser/notebookService
'
;
import
{
INotebookService
}
from
'
vs/workbench/contrib/notebook/browser/notebookService
'
;
import
{
CellKind
,
NOTEBOOK_EDITOR_CURSOR_BOUNDARY
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellKind
,
NOTEBOOK_EDITOR_CURSOR_BOUNDARY
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
const
enum
CellToolbarOrder
{
MoveCellUp
,
MoveCellDown
,
EditCell
,
SaveCell
,
InsertCell
,
DeleteCell
}
registerAction2
(
class
extends
Action2
{
registerAction2
(
class
extends
Action2
{
constructor
()
{
constructor
()
{
super
({
super
({
...
@@ -29,7 +38,8 @@ registerAction2(class extends Action2 {
...
@@ -29,7 +38,8 @@ registerAction2(class extends Action2 {
primary
:
KeyMod
.
WinCtrl
|
KeyMod
.
Alt
|
KeyCode
.
Enter
primary
:
KeyMod
.
WinCtrl
|
KeyMod
.
Alt
|
KeyCode
.
Enter
},
},
weight
:
KeybindingWeight
.
WorkbenchContrib
weight
:
KeybindingWeight
.
WorkbenchContrib
}
},
icon
:
{
id
:
'
codicon/play
'
}
});
});
}
}
...
@@ -417,7 +427,18 @@ registerAction2(class extends InsertCellCommand {
...
@@ -417,7 +427,18 @@ registerAction2(class extends InsertCellCommand {
super
(
super
(
{
{
id
:
INSERT_CODE_CELL_BELOW_COMMAND_ID
,
id
:
INSERT_CODE_CELL_BELOW_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertCodeCellBelow
'
,
"
Insert Code Cell Below
"
)
title
:
localize
(
'
notebookActions.insertCodeCellBelow
'
,
"
Insert Code Cell Below
"
),
icon
:
{
id
:
'
codicon/add
'
},
menu
:
{
id
:
MenuId
.
NotebookCellTitle
,
order
:
CellToolbarOrder
.
InsertCell
,
alt
:
{
id
:
INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertMarkdownCellBelow
'
,
"
Insert Markdown Cell Below
"
),
icon
:
{
id
:
'
codicon/add
'
},
},
when
:
ContextKeyExpr
.
equals
(
NOTEBOOK_EDITABLE_CONTEXT_KEY
,
true
)
}
},
},
CellKind
.
Code
,
CellKind
.
Code
,
'
below
'
);
'
below
'
);
...
@@ -441,89 +462,13 @@ registerAction2(class extends InsertCellCommand {
...
@@ -441,89 +462,13 @@ registerAction2(class extends InsertCellCommand {
super
(
super
(
{
{
id
:
INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID
,
id
:
INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertMarkdownCellBelow
'
,
"
Insert Markdown Cell Below
"
)
,
title
:
localize
(
'
notebookActions.insertMarkdownCellBelow
'
,
"
Insert Markdown Cell Below
"
)
},
},
CellKind
.
Markdown
,
CellKind
.
Markdown
,
'
below
'
);
'
below
'
);
}
}
});
});
export
class
InsertCodeCellAboveAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
INSERT_CODE_CELL_ABOVE_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertCodeCellAbove
'
,
"
Insert Code Cell Above
"
),
icon
:
{
id
:
'
codicon/add
'
}
},
undefined
,
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
}
}
export
class
InsertCodeCellBelowAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
INSERT_CODE_CELL_BELOW_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertCodeCellBelow
'
,
"
Insert Code Cell Below
"
),
icon
:
{
id
:
'
codicon/add
'
}
},
{
id
:
INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertMarkdownCellBelow
'
,
"
Insert Markdown Cell Below
"
),
icon
:
{
id
:
'
codicon/add
'
}
},
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
}
}
export
class
InsertMarkdownCellAboveAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
INSERT_MARKDOWN_CELL_ABOVE_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertMarkdownCellAbove
'
,
"
Insert Markdown Cell Above
"
),
icon
:
{
id
:
'
codicon/add
'
}
},
undefined
,
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
}
}
export
class
InsertMarkdownCellBelowAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID
,
title
:
localize
(
'
notebookActions.insertMarkdownCellBelow
'
,
"
Insert Markdown Cell Below
"
),
icon
:
{
id
:
'
codicon/add
'
}
},
undefined
,
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
}
}
registerAction2
(
class
extends
Action2
{
registerAction2
(
class
extends
Action2
{
constructor
()
{
constructor
()
{
super
(
super
(
...
@@ -534,7 +479,15 @@ registerAction2(class extends Action2 {
...
@@ -534,7 +479,15 @@ registerAction2(class extends Action2 {
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
ContextKeyExpr
.
not
(
InputFocusedContextKey
)),
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
ContextKeyExpr
.
not
(
InputFocusedContextKey
)),
primary
:
KeyCode
.
Enter
,
primary
:
KeyCode
.
Enter
,
weight
:
KeybindingWeight
.
WorkbenchContrib
weight
:
KeybindingWeight
.
WorkbenchContrib
}
},
menu
:
{
id
:
MenuId
.
NotebookCellTitle
,
when
:
ContextKeyExpr
.
and
(
ContextKeyExpr
.
equals
(
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
'
markdown
'
),
ContextKeyExpr
.
equals
(
NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY
,
true
)),
order
:
CellToolbarOrder
.
EditCell
},
icon
:
{
id
:
'
codicon/pencil
'
}
});
});
}
}
...
@@ -550,30 +503,20 @@ registerAction2(class extends Action2 {
...
@@ -550,30 +503,20 @@ registerAction2(class extends Action2 {
}
}
});
});
export
class
EditCellAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
EDIT_CELL_COMMAND_ID
,
title
:
localize
(
'
notebookActions.editCell
'
,
"
Edit Cell
"
),
icon
:
{
id
:
'
codicon/pencil
'
}
},
undefined
,
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
}
}
registerAction2
(
class
extends
Action2
{
registerAction2
(
class
extends
Action2
{
constructor
()
{
constructor
()
{
super
(
super
(
{
{
id
:
SAVE_CELL_COMMAND_ID
,
id
:
SAVE_CELL_COMMAND_ID
,
title
:
localize
(
'
notebookActions.saveCell
'
,
"
Save Cell
"
)
title
:
localize
(
'
notebookActions.saveCell
'
,
"
Save Cell
"
),
menu
:
{
id
:
MenuId
.
NotebookCellTitle
,
when
:
ContextKeyExpr
.
and
(
ContextKeyExpr
.
equals
(
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
'
markdown
'
),
ContextKeyExpr
.
equals
(
NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY
,
true
)),
order
:
CellToolbarOrder
.
SaveCell
},
icon
:
{
id
:
'
codicon/save
'
}
});
});
}
}
...
@@ -589,30 +532,19 @@ registerAction2(class extends Action2 {
...
@@ -589,30 +532,19 @@ registerAction2(class extends Action2 {
}
}
});
});
export
class
SaveCellAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
SAVE_CELL_COMMAND_ID
,
title
:
localize
(
'
notebookActions.saveCell
'
,
"
Save Cell
"
),
icon
:
{
id
:
'
codicon/save
'
}
},
undefined
,
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
}
}
registerAction2
(
class
extends
Action2
{
registerAction2
(
class
extends
Action2
{
constructor
()
{
constructor
()
{
super
(
super
(
{
{
id
:
DELETE_CELL_COMMAND_ID
,
id
:
DELETE_CELL_COMMAND_ID
,
title
:
localize
(
'
notebookActions.deleteCell
'
,
"
Delete Cell
"
)
title
:
localize
(
'
notebookActions.deleteCell
'
,
"
Delete Cell
"
),
menu
:
{
id
:
MenuId
.
NotebookCellTitle
,
order
:
CellToolbarOrder
.
DeleteCell
,
when
:
ContextKeyExpr
.
equals
(
NOTEBOOK_EDITABLE_CONTEXT_KEY
,
true
)
},
icon
:
{
id
:
'
codicon/x
'
}
});
});
}
}
...
@@ -628,26 +560,6 @@ registerAction2(class extends Action2 {
...
@@ -628,26 +560,6 @@ registerAction2(class extends Action2 {
}
}
});
});
export
class
DeleteCellAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
DELETE_CELL_COMMAND_ID
,
title
:
localize
(
'
notebookActions.deleteCell
'
,
"
Delete Cell
"
),
icon
:
{
id
:
'
codicon/x
'
}
},
undefined
,
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
this
.
class
=
'
codicon-x
'
;
}
}
async
function
moveCell
(
context
:
INotebookCellActionContext
,
direction
:
'
up
'
|
'
down
'
):
Promise
<
void
>
{
async
function
moveCell
(
context
:
INotebookCellActionContext
,
direction
:
'
up
'
|
'
down
'
):
Promise
<
void
>
{
direction
===
'
up
'
?
direction
===
'
up
'
?
context
.
notebookEditor
.
moveCellUp
(
context
.
cell
)
:
context
.
notebookEditor
.
moveCellUp
(
context
.
cell
)
:
...
@@ -665,7 +577,18 @@ registerAction2(class extends Action2 {
...
@@ -665,7 +577,18 @@ registerAction2(class extends Action2 {
super
(
super
(
{
{
id
:
MOVE_CELL_UP_COMMAND_ID
,
id
:
MOVE_CELL_UP_COMMAND_ID
,
title
:
localize
(
'
notebookActions.moveCellUp
'
,
"
Move Cell Up
"
)
title
:
localize
(
'
notebookActions.moveCellUp
'
,
"
Move Cell Up
"
),
icon
:
{
id
:
'
codicon/arrow-up
'
},
menu
:
{
id
:
MenuId
.
NotebookCellTitle
,
order
:
CellToolbarOrder
.
MoveCellUp
,
alt
:
{
id
:
COPY_CELL_UP_COMMAND_ID
,
title
:
localize
(
'
notebookActions.copyCellUp
'
,
"
Copy Cell Up
"
),
icon
:
{
id
:
'
codicon/arrow-up
'
}
},
when
:
ContextKeyExpr
.
equals
(
NOTEBOOK_EDITABLE_CONTEXT_KEY
,
true
)
},
});
});
}
}
...
@@ -681,34 +604,23 @@ registerAction2(class extends Action2 {
...
@@ -681,34 +604,23 @@ registerAction2(class extends Action2 {
}
}
});
});
export
class
MoveCellUpAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
MOVE_CELL_UP_COMMAND_ID
,
title
:
localize
(
'
notebookActions.moveCellUp
'
,
"
Move Cell Up
"
),
icon
:
{
id
:
'
codicon/arrow-up
'
}
},
{
id
:
COPY_CELL_UP_COMMAND_ID
,
title
:
localize
(
'
notebookActions.copyCellUp
'
,
"
Copy Cell Up
"
),
icon
:
{
id
:
'
codicon/arrow-up
'
}
},
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
}
}
registerAction2
(
class
extends
Action2
{
registerAction2
(
class
extends
Action2
{
constructor
()
{
constructor
()
{
super
(
super
(
{
{
id
:
MOVE_CELL_DOWN_COMMAND_ID
,
id
:
MOVE_CELL_DOWN_COMMAND_ID
,
title
:
localize
(
'
notebookActions.moveCellDown
'
,
"
Move Cell Down
"
)
title
:
localize
(
'
notebookActions.moveCellDown
'
,
"
Move Cell Down
"
),
icon
:
{
id
:
'
codicon/arrow-down
'
},
menu
:
{
id
:
MenuId
.
NotebookCellTitle
,
order
:
CellToolbarOrder
.
MoveCellDown
,
alt
:
{
id
:
COPY_CELL_DOWN_COMMAND_ID
,
title
:
localize
(
'
notebookActions.copyCellDown
'
,
"
Copy Cell Down
"
),
icon
:
{
id
:
'
codicon/arrow-down
'
}
},
when
:
ContextKeyExpr
.
equals
(
NOTEBOOK_EDITABLE_CONTEXT_KEY
,
true
)
},
});
});
}
}
...
@@ -724,30 +636,6 @@ registerAction2(class extends Action2 {
...
@@ -724,30 +636,6 @@ registerAction2(class extends Action2 {
}
}
});
});
export
class
MoveCellDownAction
extends
MenuItemAction
{
constructor
(
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ICommandService
commandService
:
ICommandService
)
{
super
(
{
id
:
MOVE_CELL_DOWN_COMMAND_ID
,
title
:
localize
(
'
notebookActions.moveCellDown
'
,
"
Move Cell Down
"
),
icon
:
{
id
:
'
codicon/arrow-down
'
}
},
{
id
:
COPY_CELL_DOWN_COMMAND_ID
,
title
:
localize
(
'
notebookActions.copyCellDown
'
,
"
Copy Cell Down
"
),
icon
:
{
id
:
'
codicon/arrow-down
'
}
},
{
shouldForwardArgs
:
true
},
contextKeyService
,
commandService
);
this
.
class
=
'
codicon-arrow-down
'
;
}
}
registerAction2
(
class
extends
Action2
{
registerAction2
(
class
extends
Action2
{
constructor
()
{
constructor
()
{
super
(
super
(
...
...
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
浏览文件 @
2b646152
...
@@ -16,7 +16,7 @@ import { FindMatch } from 'vs/editor/common/model';
...
@@ -16,7 +16,7 @@ import { FindMatch } from 'vs/editor/common/model';
import
{
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
OutputRenderer
}
from
'
vs/workbench/contrib/notebook/browser/view/output/outputRenderer
'
;
import
{
OutputRenderer
}
from
'
vs/workbench/contrib/notebook/browser/view/output/outputRenderer
'
;
import
{
IModelDecorationsChangeAccessor
,
NotebookViewModel
,
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
IModelDecorationsChangeAccessor
,
NotebookViewModel
,
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
CellKind
,
IOutput
,
IRenderOutput
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellKind
,
IOutput
,
IRenderOutput
,
NotebookCellMetadata
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
export
const
KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED
=
new
RawContextKey
<
boolean
>
(
'
notebookFindWidgetFocused
'
,
false
);
export
const
KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED
=
new
RawContextKey
<
boolean
>
(
'
notebookFindWidgetFocused
'
,
false
);
...
@@ -73,6 +73,7 @@ export interface ICellViewModel {
...
@@ -73,6 +73,7 @@ export interface ICellViewModel {
runState
:
CellRunState
;
runState
:
CellRunState
;
focusMode
:
CellFocusMode
;
focusMode
:
CellFocusMode
;
getText
():
string
;
getText
():
string
;
metadata
:
NotebookCellMetadata
|
undefined
;
}
}
export
interface
INotebookEditor
{
export
interface
INotebookEditor
{
...
...
src/vs/workbench/contrib/notebook/browser/notebookEditorInput.ts
浏览文件 @
2b646152
...
@@ -53,7 +53,7 @@ export class NotebookEditorModel extends EditorModel {
...
@@ -53,7 +53,7 @@ export class NotebookEditorModel extends EditorModel {
let
notebook
=
this
.
getNotebook
();
let
notebook
=
this
.
getNotebook
();
if
(
notebook
)
{
if
(
notebook
)
{
let
mainCell
=
new
NotebookCellTextModel
(
URI
.
revive
(
cell
.
uri
),
cell
.
handle
,
cell
.
source
,
cell
.
language
,
cell
.
cellKind
,
cell
.
outputs
);
let
mainCell
=
new
NotebookCellTextModel
(
URI
.
revive
(
cell
.
uri
),
cell
.
handle
,
cell
.
source
,
cell
.
language
,
cell
.
cellKind
,
cell
.
outputs
,
cell
.
metadata
);
this
.
notebook
.
insertNewCell
(
index
,
mainCell
);
this
.
notebook
.
insertNewCell
(
index
,
mainCell
);
this
.
_dirty
=
true
;
this
.
_dirty
=
true
;
this
.
_onDidChangeDirty
.
fire
();
this
.
_onDidChangeDirty
.
fire
();
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
浏览文件 @
2b646152
...
@@ -18,22 +18,22 @@ import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
...
@@ -18,22 +18,22 @@ import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import
{
ContextAwareMenuEntryActionViewItem
}
from
'
vs/platform/actions/browser/menuEntryActionViewItem
'
;
import
{
ContextAwareMenuEntryActionViewItem
}
from
'
vs/platform/actions/browser/menuEntryActionViewItem
'
;
import
{
MenuItemAction
}
from
'
vs/platform/actions/common/actions
'
;
import
{
MenuItemAction
}
from
'
vs/platform/actions/common/actions
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IContextMenuService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IContextMenuService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
INotificationService
}
from
'
vs/platform/notification/common/notification
'
;
import
{
INotificationService
}
from
'
vs/platform/notification/common/notification
'
;
import
{
EDITOR_BOTTOM_PADDING
,
EDITOR_TOOLBAR_HEIGHT
,
EDITOR_TOP_PADDING
,
NOTEBOOK_CELL_
TYP
E_CONTEXT_KEY
}
from
'
vs/workbench/contrib/notebook/browser/constants
'
;
import
{
EDITOR_BOTTOM_PADDING
,
EDITOR_TOOLBAR_HEIGHT
,
EDITOR_TOP_PADDING
,
NOTEBOOK_CELL_
EDITABLE_CONTEXT_KEY
,
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
NOTEBOOK_EDITABL
E_CONTEXT_KEY
}
from
'
vs/workbench/contrib/notebook/browser/constants
'
;
import
{
DeleteCellAction
,
EditCellAction
,
ExecuteCellAction
,
INotebookCellActionContext
,
InsertCodeCellBelowAction
,
MoveCellDownAction
,
MoveCellUpAction
,
SaveCellAction
,
InsertCodeCellAboveAction
,
InsertMarkdownCellAboveAction
,
InsertMarkdownCellBelowAction
}
from
'
vs/workbench/contrib/notebook/browser/contrib/notebookActions
'
;
import
{
CellRenderTemplate
,
CellRunState
,
ICellViewModel
,
INotebookEditor
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
Cell
RenderTemplate
,
ICellViewModel
,
INotebookEditor
,
CellRunState
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
Cell
Menus
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/cellMenus
'
;
import
{
CodeCell
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/codeCell
'
;
import
{
CodeCell
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/codeCell
'
;
import
{
StatefullMarkdownCell
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/markdownCell
'
;
import
{
StatefullMarkdownCell
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/markdownCell
'
;
import
{
CodeCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel
'
;
import
{
MarkdownCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
CellKind
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellKind
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookCellActionContext
,
ExecuteCellAction
}
from
'
vs/workbench/contrib/notebook/browser/contrib/notebookActions
'
;
import
{
ProgressBar
}
from
'
vs/base/browser/ui/progressbar/progressbar
'
;
import
{
ProgressBar
}
from
'
vs/base/browser/ui/progressbar/progressbar
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
CellMenus
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/cellMenus
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
MarkdownCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel
'
;
import
{
CodeCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel
'
;
const
$
=
DOM
.
$
;
const
$
=
DOM
.
$
;
...
@@ -121,37 +121,21 @@ abstract class AbstractCellRenderer {
...
@@ -121,37 +121,21 @@ abstract class AbstractCellRenderer {
return
menu
;
return
menu
;
}
}
abstract
getCellToolbarActions
(
element
:
CellViewModel
):
IAction
[];
getCellToolbarActions
(
scopedContextKeyService
:
IContextKeyService
):
IAction
[]
{
const
viewModel
=
this
.
notebookEditor
.
viewModel
;
showContextMenu
(
listIndex
:
number
|
undefined
,
element
:
CellViewModel
,
x
:
number
,
y
:
number
)
{
const
actions
:
IAction
[]
=
[
if
(
!
viewModel
)
{
this
.
instantiationService
.
createInstance
(
InsertCodeCellAboveAction
),
return
[];
this
.
instantiationService
.
createInstance
(
InsertCodeCellBelowAction
),
}
this
.
instantiationService
.
createInstance
(
InsertMarkdownCellAboveAction
),
this
.
instantiationService
.
createInstance
(
InsertMarkdownCellBelowAction
),
const
menu
=
this
.
createMenu
().
getCellTitleActions
(
scopedContextKeyService
);
];
const
actions
:
IAction
[]
=
[];
actions
.
push
(...
this
.
getAdditionalContextMenuActions
());
for
(
let
[,
menuActions
]
of
menu
.
getActions
({
shouldForwardArgs
:
true
}))
{
actions
.
push
(...[
actions
.
push
(...
menuActions
);
this
.
instantiationService
.
createInstance
(
DeleteCellAction
)
}
]);
this
.
contextMenuService
.
showContextMenu
({
getAnchor
:
()
=>
{
return
{
x
,
y
};
},
getActions
:
()
=>
actions
,
getActionsContext
:
()
=>
<
INotebookCellActionContext
>
{
cell
:
element
,
notebookEditor
:
this
.
notebookEditor
},
autoSelectFirstItem
:
false
});
}
abstract
getAdditionalContextMenuActions
():
IAction
[];
return
actions
;
}
}
}
export
class
MarkdownCellRenderer
extends
AbstractCellRenderer
implements
IListRenderer
<
MarkdownCellViewModel
,
CellRenderTemplate
>
{
export
class
MarkdownCellRenderer
extends
AbstractCellRenderer
implements
IListRenderer
<
MarkdownCellViewModel
,
CellRenderTemplate
>
{
...
@@ -165,7 +149,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
...
@@ -165,7 +149,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
@
IContextMenuService
contextMenuService
:
IContextMenuService
,
@
IContextMenuService
contextMenuService
:
IContextMenuService
,
@
IKeybindingService
keybindingService
:
IKeybindingService
,
@
IKeybindingService
keybindingService
:
IKeybindingService
,
@
INotificationService
notificationService
:
INotificationService
,
@
INotificationService
notificationService
:
INotificationService
,
@
IContextKeyService
contextKeyService
:
IContextKeyService
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
)
{
)
{
super
(
instantiationService
,
notehookEditor
,
contextMenuService
,
configurationService
,
keybindingService
,
notificationService
,
contextKeyService
,
'
markdown
'
);
super
(
instantiationService
,
notehookEditor
,
contextMenuService
,
configurationService
,
keybindingService
,
notificationService
,
contextKeyService
,
'
markdown
'
);
}
}
...
@@ -219,7 +203,10 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
...
@@ -219,7 +203,10 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
const
contextKeyService
=
this
.
contextKeyService
.
createScoped
(
templateData
.
container
);
const
contextKeyService
=
this
.
contextKeyService
.
createScoped
(
templateData
.
container
);
contextKeyService
.
createKey
(
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
'
markdown
'
);
contextKeyService
.
createKey
(
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
'
markdown
'
);
const
toolbarActions
=
this
.
getCellToolbarActions
(
element
);
contextKeyService
.
createKey
(
NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY
,
element
.
metadata
?.
editable
);
contextKeyService
.
createKey
(
NOTEBOOK_EDITABLE_CONTEXT_KEY
,
this
.
notebookEditor
.
viewModel
?.
metadata
?.
editable
);
const
toolbarActions
=
this
.
getCellToolbarActions
(
contextKeyService
);
templateData
.
toolbar
!
.
setActions
(
toolbarActions
)();
templateData
.
toolbar
!
.
setActions
(
toolbarActions
)();
if
(
templateData
.
focusIndicator
)
{
if
(
templateData
.
focusIndicator
)
{
...
@@ -238,51 +225,6 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
...
@@ -238,51 +225,6 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
};
};
}
}
getCellToolbarActions
(
element
:
MarkdownCellViewModel
):
IAction
[]
{
const
viewModel
=
this
.
notebookEditor
.
viewModel
;
if
(
!
viewModel
)
{
return
[];
}
const
menu
=
this
.
createMenu
().
getCellTitleActions
(
this
.
contextKeyService
);
const
actions
:
IAction
[]
=
[];
for
(
let
[,
actions
]
of
menu
.
getActions
({
shouldForwardArgs
:
true
}))
{
actions
.
push
(...
actions
);
}
const
metadata
=
viewModel
.
metadata
;
if
(
!
metadata
||
metadata
.
editable
)
{
actions
.
push
(
this
.
instantiationService
.
createInstance
(
MoveCellUpAction
),
this
.
instantiationService
.
createInstance
(
MoveCellDownAction
),
this
.
instantiationService
.
createInstance
(
InsertCodeCellBelowAction
)
);
}
const
cellMetadata
=
element
.
metadata
;
if
(
!
cellMetadata
||
cellMetadata
.
editable
)
{
actions
.
push
(
this
.
instantiationService
.
createInstance
(
EditCellAction
),
this
.
instantiationService
.
createInstance
(
SaveCellAction
)
);
}
if
(
!
metadata
||
metadata
.
editable
)
{
this
.
instantiationService
.
createInstance
(
DeleteCellAction
);
}
return
actions
;
}
getAdditionalContextMenuActions
():
IAction
[]
{
return
[
this
.
instantiationService
.
createInstance
(
EditCellAction
),
this
.
instantiationService
.
createInstance
(
SaveCellAction
),
];
}
disposeTemplate
(
templateData
:
CellRenderTemplate
):
void
{
disposeTemplate
(
templateData
:
CellRenderTemplate
):
void
{
// throw nerendererw Error('Method not implemented.');
// throw nerendererw Error('Method not implemented.');
...
@@ -307,7 +249,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
...
@@ -307,7 +249,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IKeybindingService
keybindingService
:
IKeybindingService
,
@
IKeybindingService
keybindingService
:
IKeybindingService
,
@
INotificationService
notificationService
:
INotificationService
,
@
INotificationService
notificationService
:
INotificationService
,
@
IContextKeyService
contextKeyService
:
IContextKeyService
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
)
{
)
{
super
(
instantiationService
,
notebookEditor
,
contextMenuService
,
configurationService
,
keybindingService
,
notificationService
,
contextKeyService
,
'
python
'
);
super
(
instantiationService
,
notebookEditor
,
contextMenuService
,
configurationService
,
keybindingService
,
notificationService
,
contextKeyService
,
'
python
'
);
}
}
...
@@ -319,12 +261,6 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
...
@@ -319,12 +261,6 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
renderTemplate
(
container
:
HTMLElement
):
CellRenderTemplate
{
renderTemplate
(
container
:
HTMLElement
):
CellRenderTemplate
{
const
disposables
=
new
DisposableStore
();
const
disposables
=
new
DisposableStore
();
const
toolbar
=
this
.
createToolbar
(
container
);
const
toolbar
=
this
.
createToolbar
(
container
);
toolbar
.
setActions
([
this
.
instantiationService
.
createInstance
(
MoveCellUpAction
),
this
.
instantiationService
.
createInstance
(
MoveCellDownAction
),
this
.
instantiationService
.
createInstance
(
InsertCodeCellBelowAction
),
this
.
instantiationService
.
createInstance
(
DeleteCellAction
)
])();
disposables
.
add
(
toolbar
);
disposables
.
add
(
toolbar
);
const
cellContainer
=
DOM
.
append
(
container
,
$
(
'
.cell.code
'
));
const
cellContainer
=
DOM
.
append
(
container
,
$
(
'
.cell.code
'
));
...
@@ -393,7 +329,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
...
@@ -393,7 +329,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
elementDisposable
?.
add
(
element
.
onDidChangeCellRunState
(()
=>
{
elementDisposable
?.
add
(
element
.
onDidChangeCellRunState
(()
=>
{
if
(
element
.
runState
===
CellRunState
.
Running
)
{
if
(
element
.
runState
===
CellRunState
.
Running
)
{
templateData
.
progressBar
?.
infinite
().
show
();
templateData
.
progressBar
?.
infinite
().
show
(
500
);
}
else
{
}
else
{
templateData
.
progressBar
?.
hide
();
templateData
.
progressBar
?.
hide
();
}
}
...
@@ -408,7 +344,10 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
...
@@ -408,7 +344,10 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
const
contextKeyService
=
this
.
contextKeyService
.
createScoped
(
templateData
.
container
);
const
contextKeyService
=
this
.
contextKeyService
.
createScoped
(
templateData
.
container
);
contextKeyService
.
createKey
(
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
'
code
'
);
contextKeyService
.
createKey
(
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
'
code
'
);
const
toolbarActions
=
this
.
getCellToolbarActions
(
element
);
contextKeyService
.
createKey
(
NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY
,
element
.
metadata
?.
editable
);
contextKeyService
.
createKey
(
NOTEBOOK_EDITABLE_CONTEXT_KEY
,
this
.
notebookEditor
.
viewModel
?.
metadata
?.
editable
);
const
toolbarActions
=
this
.
getCellToolbarActions
(
contextKeyService
);
templateData
.
toolbar
!
.
setActions
(
toolbarActions
)();
templateData
.
toolbar
!
.
setActions
(
toolbarActions
)();
templateData
.
toolbar
!
.
context
=
toolbarContext
;
templateData
.
toolbar
!
.
context
=
toolbarContext
;
templateData
.
runToolbar
!
.
context
=
toolbarContext
;
templateData
.
runToolbar
!
.
context
=
toolbarContext
;
...
@@ -422,39 +361,6 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
...
@@ -422,39 +361,6 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
}
}
}
}
getCellToolbarActions
(
element
:
CodeCellViewModel
):
IAction
[]
{
const
viewModel
=
this
.
notebookEditor
.
viewModel
;
if
(
!
viewModel
)
{
return
[];
}
const
menu
=
this
.
createMenu
().
getCellTitleActions
(
this
.
contextKeyService
);
const
actions
:
IAction
[]
=
[];
for
(
let
[,
actions
]
of
menu
.
getActions
({
shouldForwardArgs
:
true
}))
{
actions
.
push
(...
actions
);
}
const
metadata
=
viewModel
.
metadata
;
if
(
!
metadata
||
metadata
.
editable
)
{
actions
.
push
(
this
.
instantiationService
.
createInstance
(
MoveCellUpAction
),
this
.
instantiationService
.
createInstance
(
MoveCellDownAction
),
this
.
instantiationService
.
createInstance
(
InsertCodeCellBelowAction
),
this
.
instantiationService
.
createInstance
(
DeleteCellAction
)
);
}
return
actions
;
}
getAdditionalContextMenuActions
():
IAction
[]
{
return
[];
}
disposeTemplate
(
templateData
:
CellRenderTemplate
):
void
{
disposeTemplate
(
templateData
:
CellRenderTemplate
):
void
{
templateData
.
disposables
.
clear
();
templateData
.
disposables
.
clear
();
}
}
...
...
src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts
浏览文件 @
2b646152
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
*--------------------------------------------------------------------------------------------*/
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
ICell
,
IOutput
,
NotebookCellOutputsSplice
,
CellKind
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
ICell
,
IOutput
,
NotebookCellOutputsSplice
,
CellKind
,
NotebookCellMetadata
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
PieceTreeTextBufferFactory
,
PieceTreeTextBufferBuilder
}
from
'
vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder
'
;
import
{
PieceTreeTextBufferFactory
,
PieceTreeTextBufferBuilder
}
from
'
vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
...
@@ -38,7 +38,8 @@ export class NotebookCellTextModel implements ICell {
...
@@ -38,7 +38,8 @@ export class NotebookCellTextModel implements ICell {
private
_source
:
string
[],
private
_source
:
string
[],
public
language
:
string
,
public
language
:
string
,
public
cellKind
:
CellKind
,
public
cellKind
:
CellKind
,
outputs
:
IOutput
[]
outputs
:
IOutput
[],
public
readonly
metadata
:
NotebookCellMetadata
|
undefined
)
{
)
{
this
.
_outputs
=
outputs
;
this
.
_outputs
=
outputs
;
}
}
...
...
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
浏览文件 @
2b646152
...
@@ -72,7 +72,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
...
@@ -72,7 +72,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
splices
.
reverse
().
forEach
(
splice
=>
{
splices
.
reverse
().
forEach
(
splice
=>
{
let
cellDtos
=
splice
[
2
];
let
cellDtos
=
splice
[
2
];
let
newCells
=
cellDtos
.
map
(
cell
=>
{
let
newCells
=
cellDtos
.
map
(
cell
=>
{
let
mainCell
=
new
NotebookCellTextModel
(
URI
.
revive
(
cell
.
uri
),
cell
.
handle
,
cell
.
source
,
cell
.
language
,
cell
.
cellKind
,
cell
.
outputs
||
[]);
let
mainCell
=
new
NotebookCellTextModel
(
URI
.
revive
(
cell
.
uri
),
cell
.
handle
,
cell
.
source
,
cell
.
language
,
cell
.
cellKind
,
cell
.
outputs
||
[]
,
cell
.
metadata
);
this
.
_mapping
.
set
(
cell
.
handle
,
mainCell
);
this
.
_mapping
.
set
(
cell
.
handle
,
mainCell
);
let
dirtyStateListener
=
mainCell
.
onDidChangeContent
(()
=>
{
let
dirtyStateListener
=
mainCell
.
onDidChangeContent
(()
=>
{
this
.
_onDidChangeContent
.
fire
();
this
.
_onDidChangeContent
.
fire
();
...
...
src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts
浏览文件 @
2b646152
...
@@ -33,14 +33,16 @@ suite('NotebookViewModel', () => {
...
@@ -33,14 +33,16 @@ suite('NotebookViewModel', () => {
blukEditService
,
blukEditService
,
undoRedoService
,
undoRedoService
,
[
[
[[
'
var a = 1;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]],
[[
'
var a = 1;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]
,
{
editable
:
true
}
],
[[
'
var b = 2;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]]
[[
'
var b = 2;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]
,
{
editable
:
false
}
]
],
],
(
editor
,
viewModel
)
=>
{
(
editor
,
viewModel
)
=>
{
const
cell
=
viewModel
.
insertCell
(
1
,
new
TestCell
(
viewModel
.
viewType
,
0
,
[
'
var c = 3;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]),
true
);
const
cell
=
viewModel
.
insertCell
(
1
,
new
TestCell
(
viewModel
.
viewType
,
0
,
[
'
var c = 3;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]),
true
);
assert
.
equal
(
viewModel
.
viewCells
.
length
,
3
);
assert
.
equal
(
viewModel
.
viewCells
.
length
,
3
);
assert
.
equal
(
viewModel
.
notebookDocument
.
cells
.
length
,
3
);
assert
.
equal
(
viewModel
.
notebookDocument
.
cells
.
length
,
3
);
assert
.
equal
(
viewModel
.
getViewCellIndex
(
cell
),
1
);
assert
.
equal
(
viewModel
.
getViewCellIndex
(
cell
),
1
);
assert
.
equal
(
viewModel
.
viewCells
[
0
].
metadata
?.
editable
,
true
);
assert
.
equal
(
viewModel
.
viewCells
[
0
].
metadata
?.
editable
,
false
);
viewModel
.
deleteCell
(
1
,
true
);
viewModel
.
deleteCell
(
1
,
true
);
assert
.
equal
(
viewModel
.
viewCells
.
length
,
2
);
assert
.
equal
(
viewModel
.
viewCells
.
length
,
2
);
...
@@ -56,8 +58,8 @@ suite('NotebookViewModel', () => {
...
@@ -56,8 +58,8 @@ suite('NotebookViewModel', () => {
blukEditService
,
blukEditService
,
undoRedoService
,
undoRedoService
,
[
[
[[
'
var a = 1;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]],
[[
'
var a = 1;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]
,
{
editable
:
true
}
],
[[
'
var b = 2;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]]
[[
'
var b = 2;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]
,
{
editable
:
true
}
]
],
],
(
editor
,
viewModel
)
=>
{
(
editor
,
viewModel
)
=>
{
const
firstViewCell
=
viewModel
.
viewCells
[
0
];
const
firstViewCell
=
viewModel
.
viewCells
[
0
];
...
...
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
浏览文件 @
2b646152
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
PieceTreeTextBufferFactory
}
from
'
vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder
'
;
import
{
PieceTreeTextBufferFactory
}
from
'
vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder
'
;
import
{
CellKind
,
ICell
,
IOutput
,
NotebookCellOutputsSplice
,
CellUri
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellKind
,
ICell
,
IOutput
,
NotebookCellOutputsSplice
,
CellUri
,
NotebookCellMetadata
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
NotebookViewModel
,
IModelDecorationsChangeAccessor
,
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
NotebookViewModel
,
IModelDecorationsChangeAccessor
,
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
NotebookEditorModel
}
from
'
vs/workbench/contrib/notebook/browser/notebookEditorInput
'
;
import
{
NotebookEditorModel
}
from
'
vs/workbench/contrib/notebook/browser/notebookEditorInput
'
;
...
@@ -187,12 +187,12 @@ export class TestNotebookEditor implements INotebookEditor {
...
@@ -187,12 +187,12 @@ export class TestNotebookEditor implements INotebookEditor {
// return createCellViewModel(instantiationService, viewType, notebookHandle, mockCell);
// return createCellViewModel(instantiationService, viewType, notebookHandle, mockCell);
// }
// }
export
function
withTestNotebook
(
instantiationService
:
IInstantiationService
,
blukEditService
:
IBulkEditService
,
undoRedoService
:
IUndoRedoService
,
cells
:
[
string
[],
string
,
CellKind
,
IOutput
[]][],
callback
:
(
editor
:
TestNotebookEditor
,
viewModel
:
NotebookViewModel
)
=>
void
)
{
export
function
withTestNotebook
(
instantiationService
:
IInstantiationService
,
blukEditService
:
IBulkEditService
,
undoRedoService
:
IUndoRedoService
,
cells
:
[
string
[],
string
,
CellKind
,
IOutput
[]
,
NotebookCellMetadata
][],
callback
:
(
editor
:
TestNotebookEditor
,
viewModel
:
NotebookViewModel
)
=>
void
)
{
const
viewType
=
'
notebook
'
;
const
viewType
=
'
notebook
'
;
const
editor
=
new
TestNotebookEditor
();
const
editor
=
new
TestNotebookEditor
();
const
notebook
=
new
NotebookTextModel
(
0
,
viewType
,
URI
.
parse
(
'
test
'
));
const
notebook
=
new
NotebookTextModel
(
0
,
viewType
,
URI
.
parse
(
'
test
'
));
notebook
.
cells
=
cells
.
map
((
cell
,
index
)
=>
{
notebook
.
cells
=
cells
.
map
((
cell
,
index
)
=>
{
return
new
NotebookCellTextModel
(
notebook
.
uri
,
index
,
cell
[
0
],
cell
[
1
],
cell
[
2
],
cell
[
3
]);
return
new
NotebookCellTextModel
(
notebook
.
uri
,
index
,
cell
[
0
],
cell
[
1
],
cell
[
2
],
cell
[
3
]
,
cell
[
4
]
);
});
});
const
model
=
new
NotebookEditorModel
(
notebook
);
const
model
=
new
NotebookEditorModel
(
notebook
);
const
viewModel
=
new
NotebookViewModel
(
viewType
,
model
,
instantiationService
,
blukEditService
,
undoRedoService
);
const
viewModel
=
new
NotebookViewModel
(
viewType
,
model
,
instantiationService
,
blukEditService
,
undoRedoService
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录