Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
600528da
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,体验更适合开发者的 AI 搜索 >>
提交
600528da
编写于
4月 23, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #96007.
上级
582ced00
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
76 addition
and
21 deletion
+76
-21
extensions/vscode-notebook-tests/src/notebook.test.ts
extensions/vscode-notebook-tests/src/notebook.test.ts
+8
-9
src/vs/workbench/api/common/extHostNotebook.ts
src/vs/workbench/api/common/extHostNotebook.ts
+15
-5
src/vs/workbench/contrib/notebook/browser/notebookEditorInput.ts
...workbench/contrib/notebook/browser/notebookEditorInput.ts
+4
-0
src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts
...h/contrib/notebook/browser/viewModel/notebookViewModel.ts
+1
-3
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
...kbench/contrib/notebook/common/model/notebookTextModel.ts
+21
-2
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
+15
-1
src/vs/workbench/test/browser/api/extHostNotebookConcatDocument.test.ts
...ch/test/browser/api/extHostNotebookConcatDocument.test.ts
+12
-1
未找到文件。
extensions/vscode-notebook-tests/src/notebook.test.ts
浏览文件 @
600528da
...
...
@@ -100,16 +100,15 @@ suite('notebook workflow', () => {
// ---- move up and down ---- //
// await vscode.commands.executeCommand('workbench.notebook.cell.moveDown');
// await vscode.commands.executeCommand('workbench.notebook.cell.moveDown');
// activeCell = vscode.notebook.activeNotebookEditor!.selection;
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 2);
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[0].source, 'test');
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[1].source, '');
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[2].source, 'test');
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[3].source, '');
await
vscode
.
commands
.
executeCommand
(
'
workbench.notebook.cell.moveDown
'
);
await
vscode
.
commands
.
executeCommand
(
'
workbench.notebook.cell.moveDown
'
);
activeCell
=
vscode
.
notebook
.
activeNotebookEditor
!
.
selection
;
assert
.
equal
(
vscode
.
notebook
.
activeNotebookEditor
!
.
document
.
cells
.
indexOf
(
activeCell
!
),
2
);
assert
.
equal
(
vscode
.
notebook
.
activeNotebookEditor
!
.
document
.
cells
[
0
].
source
,
'
test
'
);
assert
.
equal
(
vscode
.
notebook
.
activeNotebookEditor
!
.
document
.
cells
[
1
].
source
,
''
);
assert
.
equal
(
vscode
.
notebook
.
activeNotebookEditor
!
.
document
.
cells
[
2
].
source
,
'
test
'
);
assert
.
equal
(
vscode
.
notebook
.
activeNotebookEditor
!
.
document
.
cells
[
3
].
source
,
''
);
// ---- ---- //
...
...
src/vs/workbench/api/common/extHostNotebook.ts
浏览文件 @
600528da
...
...
@@ -13,7 +13,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import
{
CellKind
,
CellOutputKind
,
ExtHostNotebookShape
,
IMainContext
,
MainContext
,
MainThreadNotebookShape
,
NotebookCellOutputsSplice
,
MainThreadDocumentsShape
,
INotebookEditorPropertiesChangeData
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
ExtHostCommands
}
from
'
vs/workbench/api/common/extHostCommands
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
CellEditType
,
CellUri
,
diff
,
ICellEditOperation
,
ICellInsertEdit
,
IErrorOutput
,
INotebookDisplayOrder
,
INotebookEditData
,
IOrderedMimeType
,
IStreamOutput
,
ITransformedDisplayOutputDto
,
mimeTypeSupportedByCore
,
NotebookCellsChangedEvent
,
NotebookCellsSplice2
,
sortMimeTypes
,
ICellDeleteEdit
,
notebookDocumentMetadataDefaults
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellEditType
,
CellUri
,
diff
,
ICellEditOperation
,
ICellInsertEdit
,
IErrorOutput
,
INotebookDisplayOrder
,
INotebookEditData
,
IOrderedMimeType
,
IStreamOutput
,
ITransformedDisplayOutputDto
,
mimeTypeSupportedByCore
,
NotebookCellsChangedEvent
,
NotebookCellsSplice2
,
sortMimeTypes
,
ICellDeleteEdit
,
notebookDocumentMetadataDefaults
,
NotebookCellsChangeType
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
Disposable
as
VSCodeDisposable
}
from
'
./extHostTypes
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
ExtHostDocumentData
}
from
'
vs/workbench/api/common/extHostDocumentData
'
;
...
...
@@ -247,7 +247,12 @@ export class ExtHostNotebookDocument extends Disposable implements vscode.Notebo
get
isDirty
()
{
return
false
;
}
accpetModelChanged
(
event
:
NotebookCellsChangedEvent
)
{
this
.
$spliceNotebookCells
(
event
.
changes
);
if
(
event
.
kind
===
NotebookCellsChangeType
.
ModelChange
)
{
this
.
$spliceNotebookCells
(
event
.
changes
);
}
else
if
(
event
.
kind
===
NotebookCellsChangeType
.
Move
)
{
this
.
$moveCell
(
event
.
index
,
event
.
newIdx
);
}
this
.
_versionId
=
event
.
versionId
;
}
...
...
@@ -289,6 +294,11 @@ export class ExtHostNotebookDocument extends Disposable implements vscode.Notebo
});
}
private
$moveCell
(
index
:
number
,
newIdx
:
number
)
{
const
cells
=
this
.
cells
.
splice
(
index
,
1
);
this
.
cells
.
splice
(
newIdx
,
0
,
...
cells
);
}
eventuallyUpdateCellOutputs
(
cell
:
ExtHostCell
,
diffs
:
ISplice
<
vscode
.
CellOutput
>
[])
{
let
renderers
=
new
Set
<
number
>
();
let
outputDtos
:
NotebookCellOutputsSplice
[]
=
diffs
.
map
(
diff
=>
{
...
...
@@ -600,8 +610,8 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
private
readonly
_editors
=
new
Map
<
string
,
{
editor
:
ExtHostNotebookEditor
,
onDidReceiveMessage
:
Emitter
<
any
>
}
>
();
private
readonly
_notebookOutputRenderers
=
new
Map
<
number
,
ExtHostNotebookOutputRenderer
>
();
private
readonly
_onDidChangeNotebookDocument
=
new
Emitter
<
{
document
:
ExtHostNotebookDocument
,
changes
:
NotebookCells
Splice2
[]
}
>
();
readonly
onDidChangeNotebookDocument
:
Event
<
{
document
:
ExtHostNotebookDocument
,
changes
:
NotebookCells
Splice2
[]
}
>
=
this
.
_onDidChangeNotebookDocument
.
event
;
private
readonly
_onDidChangeNotebookDocument
=
new
Emitter
<
{
document
:
ExtHostNotebookDocument
,
changes
:
NotebookCells
ChangedEvent
[]
}
>
();
readonly
onDidChangeNotebookDocument
:
Event
<
{
document
:
ExtHostNotebookDocument
,
changes
:
NotebookCells
ChangedEvent
[]
}
>
=
this
.
_onDidChangeNotebookDocument
.
event
;
private
_outputDisplayOrder
:
INotebookDisplayOrder
|
undefined
;
...
...
@@ -801,7 +811,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
editor
.
editor
.
document
.
accpetModelChanged
(
event
);
this
.
_onDidChangeNotebookDocument
.
fire
({
document
:
editor
.
editor
.
document
,
changes
:
event
.
changes
changes
:
[
event
]
});
}
...
...
src/vs/workbench/contrib/notebook/browser/notebookEditorInput.ts
浏览文件 @
600528da
...
...
@@ -69,6 +69,10 @@ export class NotebookEditorModel extends EditorModel {
}
}
moveCellToIdx
(
index
:
number
,
newIdx
:
number
)
{
this
.
notebook
.
moveCellToIdx
(
index
,
newIdx
);
}
async
save
():
Promise
<
boolean
>
{
if
(
this
.
_notebook
)
{
this
.
_dirty
=
false
;
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts
浏览文件 @
600528da
...
...
@@ -664,10 +664,8 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
}
this
.
viewCells
.
splice
(
index
,
1
);
this
.
_model
.
deleteCell
(
index
);
this
.
viewCells
!
.
splice
(
newIdx
,
0
,
viewCell
);
this
.
_model
.
insertCell
(
viewCell
.
model
,
newIdx
);
this
.
_model
.
moveCellToIdx
(
index
,
newIdx
);
if
(
pushedToUndoStack
)
{
this
.
undoService
.
pushElement
(
new
MoveCellEdit
(
this
.
uri
,
index
,
newIdx
,
{
...
...
src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts
浏览文件 @
600528da
...
...
@@ -7,7 +7,7 @@ import { Emitter, Event } from 'vs/base/common/event';
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
NotebookCellTextModel
}
from
'
vs/workbench/contrib/notebook/common/model/notebookCellTextModel
'
;
import
{
INotebookTextModel
,
NotebookCellOutputsSplice
,
NotebookCellTextModelSplice
,
NotebookDocumentMetadata
,
NotebookCellMetadata
,
ICellEditOperation
,
CellEditType
,
CellUri
,
ICellInsertEdit
,
NotebookCellsChangedEvent
,
CellKind
,
IOutput
,
notebookDocumentMetadataDefaults
,
diff
,
ICellDeleteEdit
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookTextModel
,
NotebookCellOutputsSplice
,
NotebookCellTextModelSplice
,
NotebookDocumentMetadata
,
NotebookCellMetadata
,
ICellEditOperation
,
CellEditType
,
CellUri
,
ICellInsertEdit
,
NotebookCellsChangedEvent
,
CellKind
,
IOutput
,
notebookDocumentMetadataDefaults
,
diff
,
ICellDeleteEdit
,
NotebookCellsChangeType
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
function
compareRangesUsingEnds
(
a
:
[
number
,
number
],
b
:
[
number
,
number
]):
number
{
if
(
a
[
1
]
===
b
[
1
])
{
...
...
@@ -192,6 +192,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this
.
_onDidChangeContent
.
fire
();
this
.
_onDidModelChangeProxy
.
fire
({
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
this
.
_versionId
,
changes
:
[
[
0
,
...
...
@@ -228,6 +229,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this
.
_onDidChangeContent
.
fire
();
this
.
_increaseVersionId
();
this
.
_onDidModelChangeProxy
.
fire
({
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
this
.
_versionId
,
changes
:
[
[
index
,
...
...
@@ -258,7 +260,24 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this
.
_onDidChangeContent
.
fire
();
this
.
_increaseVersionId
();
this
.
_onDidModelChangeProxy
.
fire
({
versionId
:
this
.
_versionId
,
changes
:
[[
index
,
1
,
[]]]
});
this
.
_onDidModelChangeProxy
.
fire
({
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
this
.
_versionId
,
changes
:
[[
index
,
1
,
[]]]
});
}
moveCellToIdx
(
index
:
number
,
newIdx
:
number
)
{
this
.
assertIndex
(
index
);
this
.
assertIndex
(
newIdx
);
const
cells
=
this
.
cells
.
splice
(
index
,
1
);
this
.
cells
.
splice
(
newIdx
,
0
,
...
cells
);
this
.
_increaseVersionId
();
this
.
_onDidModelChangeProxy
.
fire
({
kind
:
NotebookCellsChangeType
.
Move
,
versionId
:
this
.
_versionId
,
index
,
newIdx
});
}
assertIndex
(
index
:
number
)
{
if
(
index
<
0
||
index
>=
this
.
cells
.
length
)
{
throw
new
Error
(
`model index out of range
${
index
}
`
);
}
}
// TODO@rebornix should this trigger content change event?
...
...
src/vs/workbench/contrib/notebook/common/notebookCommon.ts
浏览文件 @
600528da
...
...
@@ -215,11 +215,25 @@ export type NotebookCellsSplice2 = [
IMainCellDto
[]
];
export
interface
NotebookCellsChangedEvent
{
export
enum
NotebookCellsChangeType
{
ModelChange
=
1
,
Move
=
2
}
export
interface
NotebookCellsModelChangedEvent
{
readonly
kind
:
NotebookCellsChangeType
.
ModelChange
;
readonly
changes
:
NotebookCellsSplice2
[];
readonly
versionId
:
number
;
}
export
interface
NotebookCellsModelMoveEvent
{
readonly
kind
:
NotebookCellsChangeType
.
Move
;
readonly
index
:
number
;
readonly
newIdx
:
number
;
readonly
versionId
:
number
;
}
export
type
NotebookCellsChangedEvent
=
NotebookCellsModelChangedEvent
|
NotebookCellsModelMoveEvent
;
export
enum
CellEditType
{
Insert
=
1
,
Delete
=
2
...
...
src/vs/workbench/test/browser/api/extHostNotebookConcatDocument.test.ts
浏览文件 @
600528da
...
...
@@ -11,7 +11,7 @@ import { NullLogService } from 'vs/platform/log/common/log';
import
{
ExtHostNotebookConcatDocument
}
from
'
vs/workbench/api/common/extHostNotebookConcatDocument
'
;
import
{
ExtHostNotebookDocument
,
ExtHostNotebookController
}
from
'
vs/workbench/api/common/extHostNotebook
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
CellKind
,
CellUri
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
CellKind
,
CellUri
,
NotebookCellsChangeType
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
Position
,
Location
,
Range
}
from
'
vs/workbench/api/common/extHostTypes
'
;
import
{
ExtHostCommands
}
from
'
vs/workbench/api/common/extHostCommands
'
;
import
{
nullExtensionDescription
}
from
'
vs/workbench/services/extensions/common/extensions
'
;
...
...
@@ -51,6 +51,7 @@ suite('NotebookConcatDocument', function () {
});
await
extHostNotebooks
.
$resolveNotebook
(
'
test
'
,
notebookUri
);
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
0
,
changes
:
[[
0
,
0
,
[{
handle
:
0
,
...
...
@@ -104,6 +105,7 @@ suite('NotebookConcatDocument', function () {
test
(
'
location, position mapping
'
,
function
()
{
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
0
,
0
,
[{
handle
:
1
,
...
...
@@ -142,6 +144,7 @@ suite('NotebookConcatDocument', function () {
// UPDATE 1
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
0
,
0
,
[{
handle
:
1
,
...
...
@@ -163,6 +166,7 @@ suite('NotebookConcatDocument', function () {
// UPDATE 2
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
1
,
0
,
[{
handle
:
2
,
...
...
@@ -185,6 +189,7 @@ suite('NotebookConcatDocument', function () {
// UPDATE 3 (remove cell #2 again)
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
1
,
1
,
[]]]
});
...
...
@@ -202,6 +207,7 @@ suite('NotebookConcatDocument', function () {
// UPDATE 1
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
0
,
0
,
[{
handle
:
1
,
...
...
@@ -264,6 +270,7 @@ suite('NotebookConcatDocument', function () {
test
(
'
selector
'
,
function
()
{
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
0
,
0
,
[{
handle
:
1
,
...
...
@@ -291,6 +298,7 @@ suite('NotebookConcatDocument', function () {
assertLines
(
barLangDoc
,
'
barLang-document
'
);
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
2
,
0
,
[{
handle
:
3
,
...
...
@@ -323,6 +331,7 @@ suite('NotebookConcatDocument', function () {
test
(
'
offsetAt(position) <-> positionAt(offset)
'
,
function
()
{
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
0
,
0
,
[{
handle
:
1
,
...
...
@@ -373,6 +382,7 @@ suite('NotebookConcatDocument', function () {
test
(
'
locationAt(position) <-> positionAt(location)
'
,
function
()
{
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
0
,
0
,
[{
handle
:
1
,
...
...
@@ -407,6 +417,7 @@ suite('NotebookConcatDocument', function () {
test
(
'
getText(range)
'
,
function
()
{
extHostNotebooks
.
$acceptModelChanged
(
notebookUri
,
{
kind
:
NotebookCellsChangeType
.
ModelChange
,
versionId
:
notebook
.
versionId
+
1
,
changes
:
[[
0
,
0
,
[{
handle
:
1
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录