Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
e66dc83a
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e66dc83a
编写于
3月 16, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Undo/Redo for cell manipulation
上级
cdfd6eca
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
240 addition
and
60 deletion
+240
-60
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
...bench/contrib/notebook/browser/contrib/notebookActions.ts
+31
-2
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
+16
-22
src/vs/workbench/contrib/notebook/browser/viewModel/cellEdit.ts
.../workbench/contrib/notebook/browser/viewModel/cellEdit.ts
+114
-0
src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts
...h/contrib/notebook/browser/viewModel/notebookViewModel.ts
+74
-31
src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts
...workbench/contrib/notebook/test/notebookViewModel.test.ts
+5
-5
未找到文件。
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
浏览文件 @
e66dc83a
...
...
@@ -885,9 +885,38 @@ registerAction2(class extends Action2 {
return
;
}
if
(
viewModel
.
canUndo
())
{
viewModel
.
undo
();
viewModel
.
undo
();
}
});
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
workbench.action.notebook.redo
'
,
title
:
'
Notebook Redo
'
,
keybinding
:
{
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
ContextKeyExpr
.
not
(
InputFocusedContextKey
)),
primary
:
KeyMod
.
CtrlCmd
|
KeyMod
.
Shift
|
KeyCode
.
KEY_Z
,
weight
:
KeybindingWeight
.
WorkbenchContrib
}
});
}
async
run
(
accessor
:
ServicesAccessor
):
Promise
<
void
>
{
const
editorService
=
accessor
.
get
(
IEditorService
);
const
editor
=
getActiveNotebookEditor
(
editorService
);
if
(
!
editor
)
{
return
;
}
const
viewModel
=
editor
.
viewModel
;
if
(
!
viewModel
)
{
return
;
}
viewModel
.
redo
();
}
});
...
...
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
浏览文件 @
e66dc83a
...
...
@@ -27,7 +27,7 @@ import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebook
import
{
OutputRenderer
}
from
'
vs/workbench/contrib/notebook/browser/view/output/outputRenderer
'
;
import
{
BackLayerWebView
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView
'
;
import
{
CodeCellRenderer
,
MarkdownCellRenderer
,
NotebookCellListDelegate
}
from
'
vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer
'
;
import
{
NotebookCellsSplice
,
IOutput
,
CellKind
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
IOutput
,
CellKind
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
IWebviewService
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
getExtraColor
}
from
'
vs/workbench/contrib/welcome/walkThrough/common/walkThroughUtils
'
;
import
{
IEditorGroup
,
IEditorGroupsService
}
from
'
vs/workbench/services/editor/common/editorGroupsService
'
;
...
...
@@ -329,8 +329,18 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
const
viewState
=
this
.
loadTextEditorViewState
(
input
);
this
.
notebookViewModel
.
restoreEditorViewState
(
viewState
);
this
.
localStore
.
add
(
this
.
notebookViewModel
.
onDidChangeCells
((
e
)
=>
{
this
.
updateViewCells
(
e
);
this
.
localStore
.
add
(
this
.
notebookViewModel
.
onDidChangeViewCells
((
e
)
=>
{
if
(
e
.
synchronous
)
{
e
.
splices
.
reverse
().
forEach
((
diff
)
=>
{
this
.
list
?.
splice
(
diff
[
0
],
diff
[
1
],
diff
[
2
]);
});
}
else
{
DOM
.
scheduleAtNextAnimationFrame
(()
=>
{
e
.
splices
.
reverse
().
forEach
((
diff
)
=>
{
this
.
list
?.
splice
(
diff
[
0
],
diff
[
1
],
diff
[
2
]);
});
});
}
}));
this
.
webview
?.
updateRendererPreloads
(
this
.
notebookViewModel
.
renderers
);
...
...
@@ -533,16 +543,6 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
});
}
updateViewCells
(
splices
:
NotebookCellsSplice
[])
{
DOM
.
scheduleAtNextAnimationFrame
(()
=>
{
splices
.
reverse
().
forEach
((
diff
)
=>
{
this
.
list
?.
splice
(
diff
[
0
],
diff
[
1
],
diff
[
2
].
map
(
cell
=>
{
return
this
.
instantiationService
.
createInstance
(
CellViewModel
,
this
.
notebookViewModel
!
.
viewType
,
this
.
notebookViewModel
!
.
handle
,
cell
);
}));
});
});
}
async
insertNotebookCell
(
cell
:
ICellViewModel
,
type
:
CellKind
,
direction
:
'
above
'
|
'
below
'
,
initialText
:
string
=
''
):
Promise
<
void
>
{
const
newLanguages
=
this
.
notebookViewModel
!
.
languages
;
const
language
=
newLanguages
&&
newLanguages
.
length
?
newLanguages
[
0
]
:
'
markdown
'
;
...
...
@@ -550,9 +550,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
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
]);
const
newCell
=
this
.
notebookViewModel
!
.
insertCell
(
insertIndex
,
newModeCell
!
,
true
);
this
.
list
?.
setFocus
([
insertIndex
]);
if
(
type
===
CellKind
.
Markdown
)
{
...
...
@@ -567,8 +565,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
async
deleteNotebookCell
(
cell
:
ICellViewModel
):
Promise
<
void
>
{
const
index
=
this
.
notebookViewModel
!
.
getViewCellIndex
(
cell
);
await
this
.
notebookService
.
deleteNotebookCell
(
this
.
notebookViewModel
!
.
viewType
,
this
.
notebookViewModel
!
.
uri
,
index
);
this
.
notebookViewModel
!
.
deleteCell
(
index
);
this
.
list
?.
splice
(
index
,
1
);
this
.
notebookViewModel
!
.
deleteCell
(
index
,
true
);
}
moveCellDown
(
cell
:
ICellViewModel
):
void
{
...
...
@@ -584,13 +581,10 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
}
private
moveCellToIndex
(
cell
:
ICellViewModel
,
index
:
number
,
newIdx
:
number
):
void
{
if
(
!
this
.
notebookViewModel
!
.
moveCellToIdx
(
index
,
newIdx
))
{
if
(
!
this
.
notebookViewModel
!
.
moveCellToIdx
(
index
,
newIdx
,
true
))
{
return
;
}
this
.
list
?.
splice
(
index
,
1
);
this
.
list
!
.
splice
(
newIdx
,
0
,
[
cell
as
CellViewModel
]);
DOM
.
scheduleAtNextAnimationFrame
(()
=>
{
this
.
list
?.
revealInCenterIfOutsideViewport
(
index
+
1
);
});
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/cellEdit.ts
0 → 100644
浏览文件 @
e66dc83a
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
ICell
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
IResourceUndoRedoElement
,
UndoRedoElementType
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
NotebookViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
/**
* It should not modify Undo/Redo stack
*/
export
interface
ICellEditingDelegate
{
insertCell
?(
index
:
number
,
viewCell
:
CellViewModel
):
void
;
deleteCell
?(
index
:
number
,
cell
:
ICell
):
void
;
moveCell
?(
fromIndex
:
number
,
toIndex
:
number
):
void
;
}
export
class
InsertCellEdit
implements
IResourceUndoRedoElement
{
type
:
UndoRedoElementType
.
Resource
=
UndoRedoElementType
.
Resource
;
label
:
string
=
'
Insert Cell
'
;
constructor
(
public
resource
:
URI
,
private
insertIndex
:
number
,
private
cell
:
CellViewModel
,
private
editingDelegate
:
ICellEditingDelegate
)
{
}
undo
():
void
|
Promise
<
void
>
{
if
(
!
this
.
editingDelegate
.
deleteCell
)
{
throw
new
Error
(
'
Notebook Delete Cell not implemented for Undo/Redo
'
);
}
this
.
editingDelegate
.
deleteCell
(
this
.
insertIndex
,
this
.
cell
.
cell
);
}
redo
():
void
|
Promise
<
void
>
{
if
(
!
this
.
editingDelegate
.
insertCell
)
{
throw
new
Error
(
'
Notebook Insert Cell not implemented for Undo/Redo
'
);
}
this
.
editingDelegate
.
insertCell
(
this
.
insertIndex
,
this
.
cell
);
}
}
export
class
DeleteCellEdit
implements
IResourceUndoRedoElement
{
type
:
UndoRedoElementType
.
Resource
=
UndoRedoElementType
.
Resource
;
label
:
string
=
'
Delete Cell
'
;
private
_rawCell
:
ICell
;
constructor
(
public
resource
:
URI
,
private
insertIndex
:
number
,
cell
:
CellViewModel
,
private
editingDelegate
:
ICellEditingDelegate
,
private
instantiationService
:
IInstantiationService
,
private
notebookViewModel
:
NotebookViewModel
)
{
this
.
_rawCell
=
cell
.
cell
;
// save inmem text to `ICell`
this
.
_rawCell
.
source
=
[
cell
.
getText
()];
}
undo
():
void
|
Promise
<
void
>
{
if
(
!
this
.
editingDelegate
.
insertCell
)
{
throw
new
Error
(
'
Notebook Insert Cell not implemented for Undo/Redo
'
);
}
const
cell
=
this
.
instantiationService
.
createInstance
(
CellViewModel
,
this
.
notebookViewModel
.
viewType
,
this
.
notebookViewModel
.
handle
,
this
.
_rawCell
);
this
.
editingDelegate
.
insertCell
(
this
.
insertIndex
,
cell
);
}
redo
():
void
|
Promise
<
void
>
{
if
(
!
this
.
editingDelegate
.
deleteCell
)
{
throw
new
Error
(
'
Notebook Delete Cell not implemented for Undo/Redo
'
);
}
this
.
editingDelegate
.
deleteCell
(
this
.
insertIndex
,
this
.
_rawCell
);
}
}
export
class
MoveCellEdit
implements
IResourceUndoRedoElement
{
type
:
UndoRedoElementType
.
Resource
=
UndoRedoElementType
.
Resource
;
label
:
string
=
'
Delete Cell
'
;
constructor
(
public
resource
:
URI
,
private
fromIndex
:
number
,
private
toIndex
:
number
,
private
editingDelegate
:
ICellEditingDelegate
)
{
}
undo
():
void
|
Promise
<
void
>
{
if
(
!
this
.
editingDelegate
.
moveCell
)
{
throw
new
Error
(
'
Notebook Move Cell not implemented for Undo/Redo
'
);
}
this
.
editingDelegate
.
moveCell
(
this
.
toIndex
,
this
.
fromIndex
);
}
redo
():
void
|
Promise
<
void
>
{
if
(
!
this
.
editingDelegate
.
moveCell
)
{
throw
new
Error
(
'
Notebook Move Cell not implemented for Undo/Redo
'
);
}
this
.
editingDelegate
.
moveCell
(
this
.
fromIndex
,
this
.
toIndex
);
}
}
src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts
浏览文件 @
e66dc83a
...
...
@@ -9,7 +9,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
NotebookEditorModel
}
from
'
vs/workbench/contrib/notebook/browser/notebookEditorInput
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel
'
;
import
{
NotebookCellsSplice
,
ICell
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
ICell
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
IModelDeltaDecoration
}
from
'
vs/editor/common/model
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
CellFindMatch
,
CellState
,
ICellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
...
...
@@ -18,6 +18,7 @@ import { Range } from 'vs/editor/common/core/range';
import
{
WorkspaceTextEdit
}
from
'
vs/editor/common/modes
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
IUndoRedoService
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
import
{
InsertCellEdit
,
DeleteCellEdit
,
MoveCellEdit
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/cellEdit
'
;
export
interface
INotebookEditorViewState
{
editingCells
:
{
[
key
:
number
]:
boolean
};
...
...
@@ -41,6 +42,17 @@ export interface IModelDecorationsChangeAccessor {
const
invalidFunc
=
()
=>
{
throw
new
Error
(
`Invalid change accessor`
);
};
export
type
NotebookViewCellsSplice
=
[
number
/* start */
,
number
/* delete count */
,
CellViewModel
[]
];
export
interface
INotebookViewCellsUpdateEvent
{
synchronous
:
boolean
;
splices
:
NotebookViewCellsSplice
[];
}
export
class
NotebookViewModel
extends
Disposable
{
private
_localStore
:
DisposableStore
=
this
.
_register
(
new
DisposableStore
());
private
_viewCells
:
CellViewModel
[]
=
[];
...
...
@@ -69,8 +81,8 @@ export class NotebookViewModel extends Disposable {
return
this
.
_model
.
notebook
.
uri
;
}
private
readonly
_onDidChange
Cells
=
new
Emitter
<
NotebookCellsSplice
[]
>
();
get
onDidChange
Cells
():
Event
<
NotebookCellsSplice
[]
>
{
return
this
.
_onDidChange
Cells
.
event
;
}
private
readonly
_onDidChange
ViewCells
=
new
Emitter
<
INotebookViewCellsUpdateEvent
>
();
get
onDidChange
ViewCells
():
Event
<
INotebookViewCellsUpdateEvent
>
{
return
this
.
_onDidChangeView
Cells
.
event
;
}
private
_lastNotebookEditResource
:
URI
[]
=
[];
...
...
@@ -90,7 +102,15 @@ export class NotebookViewModel extends Disposable {
)
{
super
();
this
.
_register
(
this
.
_model
.
onDidChangeCells
(
e
=>
this
.
_onDidChangeCells
.
fire
(
e
)));
this
.
_register
(
this
.
_model
.
onDidChangeCells
(
e
=>
{
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
true
,
splices
:
e
.
map
(
splice
=>
{
return
[
splice
[
0
],
splice
[
1
],
splice
[
2
].
map
(
cell
=>
this
.
instantiationService
.
createInstance
(
CellViewModel
,
this
.
viewType
,
this
.
handle
,
cell
))];
})
});
}));
this
.
_viewCells
=
this
.
_model
!
.
notebook
!
.
cells
.
map
(
cell
=>
{
const
viewCell
=
this
.
instantiationService
.
createInstance
(
CellViewModel
,
this
.
viewType
,
this
.
_model
!
.
notebook
!
.
handle
,
cell
);
this
.
_localStore
.
add
(
viewCell
);
...
...
@@ -114,22 +134,53 @@ export class NotebookViewModel extends Disposable {
return
this
.
_viewCells
.
indexOf
(
cell
as
CellViewModel
);
}
insertCell
(
index
:
number
,
cell
:
ICell
):
CellViewModel
{
insertCell
(
index
:
number
,
cell
:
ICell
,
synchronous
:
boolean
):
CellViewModel
{
const
newCell
=
this
.
instantiationService
.
createInstance
(
CellViewModel
,
this
.
viewType
,
this
.
handle
,
cell
);
this
.
_viewCells
!
.
splice
(
index
,
0
,
newCell
);
this
.
_model
.
insertCell
(
newCell
.
cell
,
index
);
this
.
_localStore
.
add
(
newCell
);
this
.
undoService
.
pushElement
(
new
InsertCellEdit
(
this
.
uri
,
index
,
newCell
,
{
insertCell
:
(
insertIndex
:
number
,
viewCell
:
CellViewModel
)
=>
{
this
.
_viewCells
!
.
splice
(
insertIndex
,
0
,
viewCell
);
this
.
_model
.
insertCell
(
viewCell
.
cell
,
insertIndex
);
this
.
_localStore
.
add
(
viewCell
);
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
true
,
splices
:
[[
insertIndex
,
0
,
[
viewCell
]]]
});
},
deleteCell
:
(
deleteIndex
:
number
,
cell
:
ICell
)
=>
{
this
.
_viewCells
.
splice
(
deleteIndex
,
1
);
this
.
_model
.
deleteCell
(
cell
);
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
true
,
splices
:
[[
deleteIndex
,
1
,
[]]]
});
}
}));
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
synchronous
,
splices
:
[[
index
,
0
,
[
newCell
]]]
});
return
newCell
;
}
deleteCell
(
index
:
number
)
{
deleteCell
(
index
:
number
,
synchronous
:
boolean
)
{
let
viewCell
=
this
.
_viewCells
[
index
];
this
.
_viewCells
.
splice
(
index
,
1
);
this
.
_model
.
deleteCell
(
viewCell
.
cell
);
this
.
undoService
.
pushElement
(
new
DeleteCellEdit
(
this
.
uri
,
index
,
viewCell
,
{
insertCell
:
(
insertIndex
:
number
,
viewCell
:
CellViewModel
)
=>
{
this
.
_viewCells
!
.
splice
(
insertIndex
,
0
,
viewCell
);
this
.
_model
.
insertCell
(
viewCell
.
cell
,
insertIndex
);
this
.
_localStore
.
add
(
viewCell
);
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
true
,
splices
:
[[
insertIndex
,
0
,
[
viewCell
]]]
});
},
deleteCell
:
(
deleteIndex
:
number
,
cell
:
ICell
)
=>
{
this
.
_viewCells
.
splice
(
deleteIndex
,
1
);
this
.
_model
.
deleteCell
(
cell
);
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
true
,
splices
:
[[
deleteIndex
,
1
,
[]]]
});
}
},
this
.
instantiationService
,
this
));
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
synchronous
,
splices
:
[[
index
,
1
,
[]]]
});
viewCell
.
dispose
();
}
moveCellToIdx
(
index
:
number
,
newIdx
:
number
):
boolean
{
moveCellToIdx
(
index
:
number
,
newIdx
:
number
,
synchronous
:
boolean
,
pushedToUndoStack
:
boolean
=
true
):
boolean
{
const
viewCell
=
this
.
viewCells
[
index
]
as
CellViewModel
;
if
(
!
viewCell
)
{
return
false
;
...
...
@@ -141,6 +192,17 @@ export class NotebookViewModel extends Disposable {
this
.
viewCells
!
.
splice
(
newIdx
,
0
,
viewCell
);
this
.
_model
.
insertCell
(
viewCell
.
cell
,
newIdx
);
if
(
pushedToUndoStack
)
{
this
.
undoService
.
pushElement
(
new
MoveCellEdit
(
this
.
uri
,
index
,
newIdx
,
{
moveCell
:
(
fromIndex
:
number
,
toIndex
:
number
)
=>
{
this
.
moveCellToIdx
(
fromIndex
,
toIndex
,
true
,
false
);
}
}));
}
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
synchronous
,
splices
:
[[
index
,
1
,
[]]]
});
this
.
_onDidChangeViewCells
.
fire
({
synchronous
:
synchronous
,
splices
:
[[
newIdx
,
0
,
[
viewCell
]]]
});
return
true
;
}
...
...
@@ -296,34 +358,15 @@ export class NotebookViewModel extends Disposable {
}
canUndo
():
boolean
{
const
lastResource
=
this
.
lastNotebookEditResource
;
if
(
!
lastResource
)
{
return
false
;
}
const
lastElement
=
this
.
undoService
.
getLastElement
(
lastResource
);
if
(
lastElement
?.
label
===
'
Notebook Replace
'
||
lastElement
?.
label
===
'
Notebook Replace All
'
)
{
return
true
;
}
return
false
;
return
this
.
undoService
.
canUndo
(
this
.
uri
);
}
undo
()
{
const
lastResource
=
this
.
lastNotebookEditResource
;
if
(
!
lastResource
)
{
return
;
}
const
lastElement
=
this
.
undoService
.
getLastElement
(
lastResource
);
this
.
undoService
.
undo
(
this
.
uri
);
}
if
(
lastElement
?.
label
===
'
Notebook Replace
'
||
lastElement
?.
label
===
'
Notebook Replace All
'
)
{
this
.
undoService
.
undo
(
lastResource
);
this
.
_lastNotebookEditResource
.
pop
();
}
redo
()
{
this
.
undoService
.
redo
(
this
.
uri
);
}
equal
(
model
:
NotebookEditorModel
)
{
...
...
src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts
浏览文件 @
e66dc83a
...
...
@@ -35,12 +35,12 @@ suite('NotebookViewModel', () => {
[[
'
var b = 2;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]]
],
(
editor
,
viewModel
)
=>
{
const
cell
=
viewModel
.
insertCell
(
1
,
new
TestCell
(
viewModel
.
viewType
,
0
,
[
'
var c = 3;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]));
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
.
notebookDocument
.
cells
.
length
,
3
);
assert
.
equal
(
viewModel
.
getViewCellIndex
(
cell
),
1
);
viewModel
.
deleteCell
(
1
);
viewModel
.
deleteCell
(
1
,
true
);
assert
.
equal
(
viewModel
.
viewCells
.
length
,
2
);
assert
.
equal
(
viewModel
.
notebookDocument
.
cells
.
length
,
2
);
assert
.
equal
(
viewModel
.
getViewCellIndex
(
cell
),
-
1
);
...
...
@@ -62,13 +62,13 @@ suite('NotebookViewModel', () => {
const
lastViewCell
=
viewModel
.
viewCells
[
viewModel
.
viewCells
.
length
-
1
];
const
insertIndex
=
viewModel
.
getViewCellIndex
(
firstViewCell
)
+
1
;
const
cell
=
viewModel
.
insertCell
(
insertIndex
,
new
TestCell
(
viewModel
.
viewType
,
3
,
[
'
var c = 3;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]));
const
cell
=
viewModel
.
insertCell
(
insertIndex
,
new
TestCell
(
viewModel
.
viewType
,
3
,
[
'
var c = 3;
'
],
'
javascript
'
,
CellKind
.
Code
,
[])
,
true
);
const
addedCellIndex
=
viewModel
.
getViewCellIndex
(
cell
);
viewModel
.
deleteCell
(
addedCellIndex
);
viewModel
.
deleteCell
(
addedCellIndex
,
true
);
const
secondInsertIndex
=
viewModel
.
getViewCellIndex
(
lastViewCell
)
+
1
;
const
cell2
=
viewModel
.
insertCell
(
secondInsertIndex
,
new
TestCell
(
viewModel
.
viewType
,
4
,
[
'
var d = 4;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]));
const
cell2
=
viewModel
.
insertCell
(
secondInsertIndex
,
new
TestCell
(
viewModel
.
viewType
,
4
,
[
'
var d = 4;
'
],
'
javascript
'
,
CellKind
.
Code
,
[])
,
true
);
assert
.
equal
(
viewModel
.
viewCells
.
length
,
3
);
assert
.
equal
(
viewModel
.
notebookDocument
.
cells
.
length
,
3
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录