Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6f880b0f
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,发现更多精彩内容 >>
提交
6f880b0f
编写于
3月 24, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tempalte Cell if the document is empty
上级
906729f1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
79 addition
and
2 deletion
+79
-2
src/vs/workbench/api/browser/mainThreadNotebook.ts
src/vs/workbench/api/browser/mainThreadNotebook.ts
+8
-0
src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts
...bench/contrib/notebook/browser/view/renderers/codeCell.ts
+8
-1
src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts
...h/contrib/notebook/browser/viewModel/baseCellViewModel.ts
+6
-0
src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts
...h/contrib/notebook/browser/viewModel/codeCellViewModel.ts
+6
-0
src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts
...ch/contrib/notebook/common/model/notebookCellTextModel.ts
+13
-1
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
...kbench/contrib/notebook/common/model/notebookTextModel.ts
+34
-0
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
+1
-0
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
+3
-0
未找到文件。
src/vs/workbench/api/browser/mainThreadNotebook.ts
浏览文件 @
6f880b0f
...
...
@@ -199,6 +199,14 @@ export class MainThreadNotebookController implements IMainNotebookController {
let
notebookHandle
=
await
this
.
_mainThreadNotebook
.
resolveNotebook
(
viewType
,
uri
);
if
(
notebookHandle
!==
undefined
)
{
mainthreadNotebook
=
this
.
_mapping
.
get
(
URI
.
from
(
uri
).
toString
());
if
(
mainthreadNotebook
&&
mainthreadNotebook
.
textModel
.
cells
.
length
===
0
)
{
// it's empty, we should create an empty template one
const
templateCell
=
await
this
.
_proxy
.
$createEmptyCell
(
this
.
_viewType
,
uri
,
0
,
mainthreadNotebook
.
textModel
.
languages
.
length
?
mainthreadNotebook
.
textModel
.
languages
[
0
]
:
''
,
CellKind
.
Code
);
if
(
templateCell
)
{
let
mainCell
=
new
NotebookCellTextModel
(
URI
.
revive
(
templateCell
.
uri
),
templateCell
.
handle
,
templateCell
.
source
,
templateCell
.
language
,
templateCell
.
cellKind
,
templateCell
.
outputs
,
templateCell
.
metadata
);
mainthreadNotebook
.
textModel
.
insertTemplateCell
(
mainCell
);
}
}
return
mainthreadNotebook
?.
textModel
;
}
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts
浏览文件 @
6f880b0f
...
...
@@ -15,6 +15,7 @@ import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/commo
import
{
INotebookService
}
from
'
vs/workbench/contrib/notebook/browser/notebookService
'
;
import
{
CodeCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel
'
;
import
{
EDITOR_TOP_PADDING
,
EDITOR_BOTTOM_PADDING
}
from
'
vs/workbench/contrib/notebook/browser/constants
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
interface
IMimeTypeRenderer
extends
IQuickPickItem
{
index
:
number
;
...
...
@@ -28,7 +29,8 @@ export class CodeCell extends Disposable {
private
viewCell
:
CodeCellViewModel
,
private
templateData
:
CellRenderTemplate
,
@
INotebookService
private
notebookService
:
INotebookService
,
@
IQuickInputService
private
readonly
quickInputService
:
IQuickInputService
@
IQuickInputService
private
readonly
quickInputService
:
IQuickInputService
,
@
IModeService
private
readonly
_modeService
:
IModeService
)
{
super
();
...
...
@@ -85,6 +87,11 @@ export class CodeCell extends Disposable {
templateData
.
editor
?.
updateOptions
({
readOnly
:
!
(
viewCell
.
getEvaluatedMetadata
(
notebookEditor
.
viewModel
?.
metadata
).
editable
)
});
}));
this
.
_register
(
viewCell
.
onDidChangeLanguage
((
e
)
=>
{
const
mode
=
this
.
_modeService
.
create
(
e
);
templateData
.
editor
?.
getModel
()?.
setMode
(
mode
.
languageIdentifier
);
}));
let
cellWidthResizeObserver
=
getResizesObserver
(
templateData
.
editorContainer
!
,
{
width
:
width
,
height
:
totalHeight
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts
浏览文件 @
6f880b0f
...
...
@@ -34,6 +34,8 @@ export abstract class BaseCellViewModel extends Disposable {
public
readonly
onDidChangeCursorSelection
:
Event
<
void
>
=
this
.
_onDidChangeCursorSelection
.
event
;
protected
readonly
_onDidChangeMetadata
:
Emitter
<
NotebookCellMetadata
|
undefined
>
=
this
.
_register
(
new
Emitter
<
NotebookCellMetadata
|
undefined
>
());
public
readonly
onDidChangeMetadata
:
Event
<
NotebookCellMetadata
|
undefined
>
=
this
.
_onDidChangeMetadata
.
event
;
protected
readonly
_onDidChangeLanguage
:
Emitter
<
string
>
=
this
.
_register
(
new
Emitter
<
string
>
());
public
readonly
onDidChangeLanguage
:
Event
<
string
>
=
this
.
_onDidChangeLanguage
.
event
;
get
handle
()
{
return
this
.
cell
.
handle
;
}
...
...
@@ -100,6 +102,10 @@ export abstract class BaseCellViewModel extends Disposable {
constructor
(
readonly
viewType
:
string
,
readonly
notebookHandle
:
number
,
readonly
cell
:
ICell
,
public
id
:
string
)
{
super
();
this
.
_register
(
cell
.
onDidChangeLanguage
((
e
)
=>
{
this
.
_onDidChangeLanguage
.
fire
(
e
);
}));
this
.
_register
(
cell
.
onDidChangeMetadata
((
e
)
=>
{
this
.
_onDidChangeMetadata
.
fire
(
e
);
}));
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts
浏览文件 @
6f880b0f
...
...
@@ -89,6 +89,12 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
this
.
layoutChange
({
outerWidth
:
e
.
value
.
width
,
font
:
e
.
value
.
fontInfo
});
}
}));
this
.
_register
(
this
.
onDidChangeLanguage
((
e
)
=>
{
if
(
this
.
_textModel
&&
!
this
.
_textModel
.
isDisposed
())
{
}
}));
}
layoutChange
(
state
:
CodeCellLayoutChangeEvent
)
{
...
...
src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts
浏览文件 @
6f880b0f
...
...
@@ -18,6 +18,9 @@ export class NotebookCellTextModel implements ICell {
private
_onDidChangeMetadata
=
new
Emitter
<
NotebookCellMetadata
|
undefined
>
();
onDidChangeMetadata
:
Event
<
NotebookCellMetadata
|
undefined
>
=
this
.
_onDidChangeMetadata
.
event
;
private
_onDidChangeLanguage
=
new
Emitter
<
string
>
();
onDidChangeLanguage
:
Event
<
string
>
=
this
.
_onDidChangeLanguage
.
event
;
private
_outputs
:
IOutput
[];
get
outputs
():
IOutput
[]
{
...
...
@@ -44,13 +47,22 @@ export class NotebookCellTextModel implements ICell {
this
.
_onDidChangeMetadata
.
fire
(
this
.
_metadata
);
}
get
language
()
{
return
this
.
_language
;
}
set
language
(
newLanguage
:
string
)
{
this
.
_language
=
newLanguage
;
this
.
_onDidChangeLanguage
.
fire
(
newLanguage
);
}
private
_buffer
:
PieceTreeTextBufferFactory
|
null
=
null
;
constructor
(
readonly
uri
:
URI
,
public
handle
:
number
,
private
_source
:
string
[],
p
ublic
language
:
string
,
p
rivate
_
language
:
string
,
public
cellKind
:
CellKind
,
outputs
:
IOutput
[],
metadata
:
NotebookCellMetadata
|
undefined
...
...
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
浏览文件 @
6f880b0f
...
...
@@ -24,6 +24,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
languages
:
string
[]
=
[];
metadata
:
NotebookDocumentMetadata
|
undefined
=
{
editable
:
true
};
renderers
=
new
Set
<
number
>
();
private
_isUntitled
:
boolean
|
undefined
=
undefined
;
constructor
(
public
handle
:
number
,
...
...
@@ -36,6 +37,11 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
updateLanguages
(
languages
:
string
[])
{
this
.
languages
=
languages
;
// TODO@rebornix metadata: default language for cell
if
(
this
.
_isUntitled
&&
languages
.
length
&&
this
.
cells
.
length
)
{
this
.
cells
[
0
].
language
=
languages
[
0
];
}
}
updateNotebookMetadata
(
metadata
:
NotebookDocumentMetadata
)
{
...
...
@@ -57,7 +63,27 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
});
}
insertTemplateCell
(
cell
:
NotebookCellTextModel
)
{
if
(
this
.
cells
.
length
>
0
||
this
.
_isUntitled
!==
undefined
)
{
return
;
}
this
.
_isUntitled
=
true
;
this
.
cells
=
[
cell
];
let
dirtyStateListener
=
cell
.
onDidChangeContent
(()
=>
{
this
.
_isUntitled
=
false
;
this
.
_onDidChangeContent
.
fire
();
});
this
.
_cellListeners
.
set
(
cell
.
handle
,
dirtyStateListener
);
this
.
_onDidChangeContent
.
fire
();
return
;
}
insertNewCell
(
index
:
number
,
cell
:
NotebookCellTextModel
):
void
{
this
.
_isUntitled
=
false
;
this
.
_mapping
.
set
(
cell
.
handle
,
cell
);
this
.
cells
.
splice
(
index
,
0
,
cell
);
let
dirtyStateListener
=
cell
.
onDidChangeContent
(()
=>
{
...
...
@@ -70,6 +96,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
}
removeCell
(
index
:
number
)
{
this
.
_isUntitled
=
false
;
let
cell
=
this
.
cells
[
index
];
this
.
_cellListeners
.
get
(
cell
.
handle
)?.
dispose
();
this
.
_cellListeners
.
delete
(
cell
.
handle
);
...
...
@@ -80,6 +108,12 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
// TODO@rebornix should this trigger content change event?
$spliceNotebookCells
(
splices
:
NotebookCellsSplice
[]):
void
{
if
(
!
splices
.
length
)
{
return
;
}
this
.
_isUntitled
=
false
;
splices
.
reverse
().
forEach
(
splice
=>
{
let
cellDtos
=
splice
[
2
];
let
newCells
=
cellDtos
.
map
(
cell
=>
{
...
...
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
浏览文件 @
6f880b0f
...
...
@@ -136,6 +136,7 @@ export interface ICell {
metadata
?:
NotebookCellMetadata
;
onDidChangeOutputs
?:
Event
<
NotebookCellOutputsSplice
[]
>
;
onDidChangeMetadata
:
Event
<
NotebookCellMetadata
|
undefined
>
;
onDidChangeLanguage
:
Event
<
string
>
;
resolveTextBufferFactory
():
PieceTreeTextBufferFactory
;
// TODO@rebornix it should be later on replaced by moving textmodel resolution into CellTextModel
contentChange
():
void
;
...
...
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
浏览文件 @
6f880b0f
...
...
@@ -27,6 +27,9 @@ export class TestCell implements ICell {
onDidChangeOutputs
:
Event
<
NotebookCellOutputsSplice
[]
>
=
this
.
_onDidChangeOutputs
.
event
;
private
_onDidChangeMetadata
=
new
Emitter
<
NotebookCellMetadata
>
();
onDidChangeMetadata
:
Event
<
NotebookCellMetadata
>
=
this
.
_onDidChangeMetadata
.
event
;
private
_onDidChangeLanguage
=
new
Emitter
<
string
>
();
onDidChangeLanguage
:
Event
<
string
>
=
this
.
_onDidChangeLanguage
.
event
;
private
_isDirty
:
boolean
=
false
;
private
_outputs
:
IOutput
[];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录