Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f3be0dcd
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,发现更多精彩内容 >>
提交
f3be0dcd
编写于
4月 17, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reduce event emitters on notebook baseviewmodel
上级
9c40c351
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
86 addition
and
52 deletion
+86
-52
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
+9
-0
src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts
...rkbench/contrib/notebook/browser/view/notebookCellList.ts
+8
-4
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
...h/contrib/notebook/browser/view/renderers/cellRenderer.ts
+18
-6
src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts
...bench/contrib/notebook/browser/view/renderers/codeCell.ts
+15
-5
src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts
...h/contrib/notebook/browser/view/renderers/markdownCell.ts
+10
-4
src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts
...h/contrib/notebook/browser/viewModel/baseCellViewModel.ts
+21
-28
src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts
...h/contrib/notebook/browser/viewModel/codeCellViewModel.ts
+5
-5
未找到文件。
src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
浏览文件 @
f3be0dcd
...
...
@@ -421,6 +421,15 @@ export enum CursorAtBoundary {
Both
}
export
interface
CellViewModelStateChangeEvent
{
metadataChanged
?:
boolean
;
selectionChanged
?:
boolean
;
focusModeChanged
?:
boolean
;
runStateChanged
?:
boolean
;
editStateChanged
?:
boolean
;
languageChanged
?:
boolean
;
}
/**
* [start, start + length - 1]
*/
...
...
src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts
浏览文件 @
f3be0dcd
...
...
@@ -98,8 +98,10 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
// we only validate the first focused element
const
focusedElement
=
e
.
elements
[
0
];
cursorSelectionListener
=
focusedElement
.
onDidChangeCursorSelection
(()
=>
{
cursorSelectionListener
=
focusedElement
.
onDidChangeState
((
e
)
=>
{
if
(
e
.
selectionChanged
)
{
recomputeContext
(
focusedElement
);
}
});
textEditorAttachListener
=
focusedElement
.
onDidChangeEditorAttachState
(()
=>
{
...
...
@@ -478,7 +480,9 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
}
const
editorAttachedPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
element
.
onDidChangeEditorAttachState
(
state
=>
state
?
resolve
()
:
reject
());
element
.
onDidChangeEditorAttachState
(()
=>
{
element
.
editorAttached
?
resolve
()
:
reject
();
});
});
editorAttachedPromise
.
then
(()
=>
{
...
...
@@ -750,7 +754,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
function
getEditorAttachedPromise
(
element
:
CellViewModel
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
Event
.
once
(
element
.
onDidChangeEditorAttachState
)(
state
=>
state
?
resolve
()
:
reject
());
Event
.
once
(
element
.
onDidChangeEditorAttachState
)(
()
=>
element
.
editorAttached
?
resolve
()
:
reject
());
});
}
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
浏览文件 @
f3be0dcd
...
...
@@ -327,13 +327,17 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
};
updateForMetadata
();
elementDisposable
.
add
(
element
.
onDidChangeMetadata
(()
=>
{
elementDisposable
.
add
(
element
.
onDidChangeState
((
e
)
=>
{
if
(
e
.
metadataChanged
)
{
updateForMetadata
();
}
}));
const
editModeKey
=
contextKeyService
.
createKey
(
NOTEBOOK_CELL_MARKDOWN_EDIT_MODE_CONTEXT_KEY
,
element
.
editState
===
CellEditState
.
Editing
);
elementDisposable
.
add
(
element
.
onDidChangeCellEditState
(()
=>
{
elementDisposable
.
add
(
element
.
onDidChangeState
((
e
)
=>
{
if
(
e
.
editStateChanged
)
{
editModeKey
.
set
(
element
.
editState
===
CellEditState
.
Editing
);
}
}));
this
.
setupCellToolbarActions
(
contextKeyService
,
templateData
,
elementDisposable
);
...
...
@@ -517,13 +521,21 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
const
runStateKey
=
contextKeyService
.
createKey
(
NOTEBOOK_CELL_RUN_STATE_CONTEXT_KEY
,
CellRunState
[
element
.
runState
]);
this
.
updateForRunState
(
element
,
templateData
,
runStateKey
);
elementDisposable
.
add
(
element
.
onDidChangeCellRunState
(()
=>
this
.
updateForRunState
(
element
,
templateData
,
runStateKey
)));
elementDisposable
.
add
(
element
.
onDidChangeState
((
e
)
=>
{
if
(
e
.
runStateChanged
)
{
this
.
updateForRunState
(
element
,
templateData
,
runStateKey
);
}
}));
contextKeyService
.
createKey
(
NOTEBOOK_CELL_TYPE_CONTEXT_KEY
,
'
code
'
);
contextKeyService
.
createKey
(
NOTEBOOK_VIEW_TYPE
,
element
.
viewType
);
const
cellEditableKey
=
contextKeyService
.
createKey
(
NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY
,
!!
(
element
.
metadata
?.
editable
));
this
.
updateForMetadata
(
element
,
templateData
,
cellEditableKey
);
elementDisposable
.
add
(
element
.
onDidChangeMetadata
(()
=>
this
.
updateForMetadata
(
element
,
templateData
,
cellEditableKey
)));
elementDisposable
.
add
(
element
.
onDidChangeState
((
e
)
=>
{
if
(
e
.
metadataChanged
)
{
this
.
updateForMetadata
(
element
,
templateData
,
cellEditableKey
);
}
}));
this
.
setupCellToolbarActions
(
contextKeyService
,
templateData
,
elementDisposable
);
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts
浏览文件 @
f3be0dcd
...
...
@@ -69,19 +69,29 @@ export class CodeCell extends Disposable {
}
});
this
.
_register
(
viewCell
.
onDidChangeFocusMode
(()
=>
{
this
.
_register
(
viewCell
.
onDidChangeState
((
e
)
=>
{
if
(
!
e
.
focusModeChanged
)
{
return
;
}
if
(
viewCell
.
focusMode
===
CellFocusMode
.
Editor
)
{
templateData
.
editor
?.
focus
();
}
}));
templateData
.
editor
?.
updateOptions
({
readOnly
:
!
(
viewCell
.
getEvaluatedMetadata
(
notebookEditor
.
viewModel
?.
metadata
).
editable
)
});
this
.
_register
(
viewCell
.
onDidChangeMetadata
(()
=>
{
this
.
_register
(
viewCell
.
onDidChangeState
((
e
)
=>
{
if
(
e
.
metadataChanged
)
{
templateData
.
editor
?.
updateOptions
({
readOnly
:
!
(
viewCell
.
getEvaluatedMetadata
(
notebookEditor
.
viewModel
?.
metadata
).
editable
)
});
}
}));
this
.
_register
(
viewCell
.
onDidChangeLanguage
((
e
)
=>
{
const
mode
=
this
.
_modeService
.
create
(
e
);
this
.
_register
(
viewCell
.
onDidChangeState
((
e
)
=>
{
if
(
!
e
.
languageChanged
)
{
return
;
}
const
mode
=
this
.
_modeService
.
create
(
viewCell
.
language
);
templateData
.
editor
?.
getModel
()?.
setMode
(
mode
.
languageIdentifier
);
}));
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts
浏览文件 @
f3be0dcd
...
...
@@ -142,12 +142,18 @@ export class StatefullMarkdownCell extends Disposable {
}
};
this
.
_register
(
viewCell
.
onDidChangeCellEditState
(()
=>
{
this
.
_register
(
viewCell
.
onDidChangeState
((
e
)
=>
{
if
(
e
.
editStateChanged
)
{
this
.
localDisposables
.
clear
();
viewUpdate
();
}
}));
this
.
_register
(
viewCell
.
onDidChangeFocusMode
(()
=>
{
this
.
_register
(
viewCell
.
onDidChangeState
((
e
)
=>
{
if
(
!
e
.
focusModeChanged
)
{
return
;
}
if
(
viewCell
.
focusMode
===
CellFocusMode
.
Editor
)
{
this
.
editor
?.
focus
();
}
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts
浏览文件 @
f3be0dcd
...
...
@@ -12,7 +12,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import
*
as
model
from
'
vs/editor/common/model
'
;
import
{
SearchParams
}
from
'
vs/editor/common/model/textModelSearch
'
;
import
{
EDITOR_TOOLBAR_HEIGHT
,
EDITOR_TOP_MARGIN
}
from
'
vs/workbench/contrib/notebook/browser/constants
'
;
import
{
CellEditState
,
CellFocusMode
,
CellRunState
,
CursorAtBoundary
,
ICellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
CellEditState
,
CellFocusMode
,
CellRunState
,
CursorAtBoundary
,
ICellViewModel
,
CellViewModelStateChangeEvent
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
CellKind
,
NotebookCellMetadata
,
NotebookDocumentMetadata
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
NotebookCellTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookCellTextModel
'
;
...
...
@@ -22,22 +22,12 @@ export const NotebookCellMetadataDefaults = {
};
export
abstract
class
BaseCellViewModel
extends
Disposable
implements
ICellViewModel
{
protected
readonly
_onDidDispose
=
new
Emitter
<
void
>
();
readonly
onDidDispose
=
this
.
_onDidDispose
.
event
;
protected
readonly
_onDidChangeCellEditState
=
new
Emitter
<
void
>
();
readonly
onDidChangeCellEditState
=
this
.
_onDidChangeCellEditState
.
event
;
protected
readonly
_onDidChangeCellRunState
=
new
Emitter
<
void
>
();
readonly
onDidChangeCellRunState
=
this
.
_onDidChangeCellRunState
.
event
;
protected
readonly
_onDidChangeFocusMode
=
new
Emitter
<
void
>
();
readonly
onDidChangeFocusMode
=
this
.
_onDidChangeFocusMode
.
event
;
protected
readonly
_onDidChangeEditorAttachState
=
new
Emitter
<
boolean
>
();
protected
readonly
_onDidChangeEditorAttachState
=
new
Emitter
<
void
>
();
// Do not merge this event with `onDidChangeState` as we are using `Event.once(onDidChangeEditorAttachState)` elsewhere.
readonly
onDidChangeEditorAttachState
=
this
.
_onDidChangeEditorAttachState
.
event
;
protected
readonly
_onDidChangeCursorSelection
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
public
readonly
onDidChangeCursorSelection
:
Event
<
void
>
=
this
.
_onDidChangeCursorSelection
.
event
;
protected
readonly
_onDidChangeMetadata
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
public
readonly
onDidChangeMetadata
:
Event
<
void
>
=
this
.
_onDidChangeMetadata
.
event
;
protected
readonly
_onDidChangeLanguage
:
Emitter
<
string
>
=
this
.
_register
(
new
Emitter
<
string
>
());
public
readonly
onDidChangeLanguage
:
Event
<
string
>
=
this
.
_onDidChangeLanguage
.
event
;
protected
readonly
_onDidChangeState
:
Emitter
<
CellViewModelStateChangeEvent
>
=
this
.
_register
(
new
Emitter
<
CellViewModelStateChangeEvent
>
());
public
readonly
onDidChangeState
:
Event
<
CellViewModelStateChangeEvent
>
=
this
.
_onDidChangeState
.
event
;
get
handle
()
{
return
this
.
model
.
handle
;
}
...
...
@@ -50,6 +40,9 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
get
metadata
()
{
return
this
.
model
.
metadata
;
}
get
language
()
{
return
this
.
model
.
language
;
}
abstract
cellKind
:
CellKind
;
...
...
@@ -65,14 +58,14 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
}
this
.
_editState
=
newState
;
this
.
_onDidChange
CellEditState
.
fire
(
);
this
.
_onDidChange
State
.
fire
({
editStateChanged
:
true
}
);
}
// TODO - move any "run"/"status" concept to Code-specific places
private
_currentTokenSource
:
CancellationTokenSource
|
undefined
;
public
set
currentTokenSource
(
v
:
CancellationTokenSource
|
undefined
)
{
this
.
_currentTokenSource
=
v
;
this
.
_onDidChange
CellRunState
.
fire
(
);
this
.
_onDidChange
State
.
fire
({
runStateChanged
:
true
}
);
}
public
get
currentTokenSource
():
CancellationTokenSource
|
undefined
{
...
...
@@ -89,7 +82,7 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
}
set
focusMode
(
newMode
:
CellFocusMode
)
{
this
.
_focusMode
=
newMode
;
this
.
_onDidChange
FocusMode
.
fire
(
);
this
.
_onDidChange
State
.
fire
({
focusModeChanged
:
true
}
);
}
protected
_textEditor
?:
ICodeEditor
;
...
...
@@ -108,12 +101,12 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
constructor
(
readonly
viewType
:
string
,
readonly
notebookHandle
:
number
,
readonly
model
:
NotebookCellTextModel
,
public
id
:
string
)
{
super
();
this
.
_register
(
model
.
onDidChangeLanguage
((
e
)
=>
{
this
.
_onDidChange
Language
.
fire
(
e
);
this
.
_register
(
model
.
onDidChangeLanguage
(()
=>
{
this
.
_onDidChange
State
.
fire
({
languageChanged
:
true
}
);
}));
this
.
_register
(
model
.
onDidChangeMetadata
(()
=>
{
this
.
_onDidChange
Metadata
.
fire
(
);
this
.
_onDidChange
State
.
fire
({
metadataChanged
:
true
}
);
}));
}
...
...
@@ -136,8 +129,8 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
if
(
this
.
_textEditor
===
editor
)
{
if
(
this
.
_cursorChangeListener
===
null
)
{
this
.
_cursorChangeListener
=
this
.
_textEditor
.
onDidChangeCursorSelection
(()
=>
this
.
_onDidChangeCursorSelection
.
fire
()
);
this
.
_onDidChange
CursorSelection
.
fire
(
);
this
.
_cursorChangeListener
=
this
.
_textEditor
.
onDidChangeCursorSelection
(()
=>
{
this
.
_onDidChangeState
.
fire
({
selectionChanged
:
true
});
}
);
this
.
_onDidChange
State
.
fire
({
selectionChanged
:
true
}
);
}
return
;
}
...
...
@@ -160,9 +153,9 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
}
});
this
.
_cursorChangeListener
=
this
.
_textEditor
.
onDidChangeCursorSelection
(()
=>
this
.
_onDidChangeCursorSelection
.
fire
()
);
this
.
_onDidChange
CursorSelection
.
fire
(
);
this
.
_onDidChangeEditorAttachState
.
fire
(
true
);
this
.
_cursorChangeListener
=
this
.
_textEditor
.
onDidChangeCursorSelection
(()
=>
{
this
.
_onDidChangeState
.
fire
({
selectionChanged
:
true
});
}
);
this
.
_onDidChange
State
.
fire
({
selectionChanged
:
true
}
);
this
.
_onDidChangeEditorAttachState
.
fire
();
}
detachTextEditor
()
{
...
...
@@ -179,7 +172,7 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
this
.
_textEditor
=
undefined
;
this
.
_cursorChangeListener
?.
dispose
();
this
.
_cursorChangeListener
=
null
;
this
.
_onDidChangeEditorAttachState
.
fire
(
false
);
this
.
_onDidChangeEditorAttachState
.
fire
();
}
getText
():
string
{
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts
浏览文件 @
f3be0dcd
...
...
@@ -73,10 +73,6 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
this
.
_onDidChangeOutputs
.
fire
(
splices
);
}));
this
.
_register
(
this
.
model
.
onDidChangeMetadata
(()
=>
{
this
.
_onDidChangeMetadata
.
fire
();
}));
this
.
_outputCollection
=
new
Array
(
this
.
model
.
outputs
.
length
);
this
.
_buffer
=
null
;
...
...
@@ -97,7 +93,11 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
}
}));
this
.
_register
(
this
.
onDidChangeLanguage
((
e
)
=>
{
this
.
_register
(
this
.
onDidChangeState
((
e
)
=>
{
if
(
!
e
.
languageChanged
)
{
return
;
}
if
(
this
.
_textModel
&&
!
this
.
_textModel
.
isDisposed
())
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录