Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d256d562
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,发现更多精彩内容 >>
提交
d256d562
编写于
3月 16, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace first cut
上级
c41d6313
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
184 addition
and
21 deletion
+184
-21
src/vs/workbench/contrib/codeEditor/browser/find/simpleFindReplaceWidget.ts
...ontrib/codeEditor/browser/find/simpleFindReplaceWidget.ts
+8
-2
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
...bench/contrib/notebook/browser/contrib/notebookActions.ts
+33
-0
src/vs/workbench/contrib/notebook/browser/contrib/notebookFindWidget.ts
...ch/contrib/notebook/browser/contrib/notebookFindWidget.ts
+21
-0
src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts
...h/contrib/notebook/browser/view/renderers/markdownCell.ts
+8
-0
src/vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel.ts
...ntrib/notebook/browser/viewModel/notebookCellViewModel.ts
+4
-0
src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts
...h/contrib/notebook/browser/viewModel/notebookViewModel.ts
+97
-16
src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts
...workbench/contrib/notebook/test/notebookViewModel.test.ts
+9
-1
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
+4
-2
未找到文件。
src/vs/workbench/contrib/codeEditor/browser/find/simpleFindReplaceWidget.ts
浏览文件 @
d256d562
...
...
@@ -212,7 +212,7 @@ export abstract class SimpleFindReplaceWidget extends Widget {
label
:
NLS_REPLACE_BTN_LABEL
,
className
:
'
codicon codicon-replace
'
,
onTrigger
:
()
=>
{
// this._controller.replac
e();
this
.
replaceOn
e
();
}
}));
...
...
@@ -221,7 +221,7 @@ export abstract class SimpleFindReplaceWidget extends Widget {
label
:
NLS_REPLACE_ALL_BTN_LABEL
,
className
:
'
codicon codicon-replace-all
'
,
onTrigger
:
()
=>
{
// this._controller
.replaceAll();
this
.
replaceAll
();
}
}));
...
...
@@ -234,6 +234,8 @@ export abstract class SimpleFindReplaceWidget extends Widget {
protected
abstract
onInputChanged
():
boolean
;
protected
abstract
find
(
previous
:
boolean
):
void
;
protected
abstract
findFirst
():
void
;
protected
abstract
replaceOne
():
void
;
protected
abstract
replaceAll
():
void
;
protected
abstract
onFocusTrackerFocus
():
void
;
protected
abstract
onFocusTrackerBlur
():
void
;
protected
abstract
onFindInputFocusTrackerFocus
():
void
;
...
...
@@ -245,6 +247,10 @@ export abstract class SimpleFindReplaceWidget extends Widget {
return
this
.
_findInput
.
getValue
();
}
protected
get
replaceValue
()
{
return
this
.
_replaceInput
.
getValue
();
}
public
get
focusTracker
():
dom
.
IFocusTracker
{
return
this
.
_focusTracker
;
}
...
...
src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts
浏览文件 @
d256d562
...
...
@@ -858,6 +858,39 @@ registerAction2(class extends Action2 {
}
});
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
workbench.action.notebook.undo
'
,
title
:
'
Notebook Undo
'
,
keybinding
:
{
when
:
ContextKeyExpr
.
and
(
NOTEBOOK_EDITOR_FOCUSED
,
ContextKeyExpr
.
not
(
InputFocusedContextKey
)),
primary
:
KeyMod
.
CtrlCmd
|
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
;
}
if
(
viewModel
.
canUndo
())
{
viewModel
.
undo
();
}
}
});
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
...
...
src/vs/workbench/contrib/notebook/browser/contrib/notebookFindWidget.ts
浏览文件 @
d256d562
...
...
@@ -82,6 +82,27 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget {
this
.
revealCellRange
(
nextIndex
.
index
,
nextIndex
.
remainder
);
}
protected
replaceOne
()
{
if
(
!
this
.
_findMatches
.
length
)
{
return
;
}
if
(
!
this
.
_findMatchesStarts
)
{
this
.
set
(
this
.
_findMatches
);
}
const
nextIndex
=
this
.
_findMatchesStarts
!
.
getIndexOf
(
this
.
_currentMatch
);
const
cell
=
this
.
_findMatches
[
nextIndex
.
index
].
cell
;
const
match
=
this
.
_findMatches
[
nextIndex
.
index
].
matches
[
nextIndex
.
remainder
];
return
this
.
_notebookEditor
.
viewModel
!
.
replaceOne
(
cell
,
match
.
range
,
this
.
replaceValue
);
}
protected
replaceAll
()
{
return
this
.
_notebookEditor
.
viewModel
!
.
replaceAll
(
this
.
_findMatches
,
this
.
replaceValue
);
}
private
revealCellRange
(
cellIndex
:
number
,
matchIndex
:
number
)
{
this
.
_findMatches
[
cellIndex
].
cell
.
state
=
CellState
.
Editing
;
this
.
_notebookEditor
.
selectElement
(
this
.
_findMatches
[
cellIndex
].
cell
);
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts
浏览文件 @
d256d562
...
...
@@ -185,6 +185,14 @@ export class StatefullMarkdownCell extends Disposable {
const
clientHeight
=
this
.
cellContainer
.
clientHeight
;
notebookEditor
.
layoutNotebookCell
(
viewCell
,
clientHeight
);
}));
this
.
localDisposables
.
add
(
viewCell
.
onDidChangeContent
(()
=>
{
this
.
cellContainer
.
innerHTML
=
''
;
let
renderedHTML
=
viewCell
.
getHTML
();
if
(
renderedHTML
)
{
this
.
cellContainer
.
appendChild
(
renderedHTML
);
}
}));
}
}
};
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel.ts
浏览文件 @
d256d562
...
...
@@ -110,6 +110,8 @@ export class CellViewModel extends Disposable implements ICellViewModel {
private
_editorViewStates
:
editorCommon
.
ICodeEditorViewState
|
null
;
private
_lastDecorationId
:
number
=
0
;
private
_resolvedDecorations
=
new
Map
<
string
,
{
id
?:
string
,
options
:
model
.
IModelDeltaDecoration
}
>
();
private
readonly
_onDidChangeContent
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
public
readonly
onDidChangeContent
:
Event
<
void
>
=
this
.
_onDidChangeContent
.
event
;
private
readonly
_onDidChangeCursorSelection
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
public
readonly
onDidChangeCursorSelection
:
Event
<
void
>
=
this
.
_onDidChangeCursorSelection
.
event
;
...
...
@@ -275,6 +277,8 @@ export class CellViewModel extends Disposable implements ICellViewModel {
this
.
_register
(
ref
);
this
.
_register
(
this
.
_textModel
.
onDidChangeContent
(()
=>
{
this
.
cell
.
isDirty
=
true
;
this
.
_html
=
null
;
this
.
_onDidChangeContent
.
fire
();
}));
}
return
this
.
_textModel
;
...
...
src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts
浏览文件 @
d256d562
...
...
@@ -13,6 +13,11 @@ import { NotebookCellsSplice, ICell } from 'vs/workbench/contrib/notebook/common
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
'
;
import
{
IBulkEditService
}
from
'
vs/editor/browser/services/bulkEditService
'
;
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
'
;
export
interface
INotebookEditorViewState
{
editingCells
:
{
[
key
:
number
]:
boolean
};
...
...
@@ -67,10 +72,21 @@ export class NotebookViewModel extends Disposable {
private
readonly
_onDidChangeCells
=
new
Emitter
<
NotebookCellsSplice
[]
>
();
get
onDidChangeCells
():
Event
<
NotebookCellsSplice
[]
>
{
return
this
.
_onDidChangeCells
.
event
;
}
private
_lastNotebookEditResource
:
URI
[]
=
[];
get
lastNotebookEditResource
():
URI
|
null
{
if
(
this
.
_lastNotebookEditResource
.
length
)
{
return
this
.
_lastNotebookEditResource
[
this
.
_lastNotebookEditResource
.
length
-
1
];
}
return
null
;
}
constructor
(
public
viewType
:
string
,
private
_model
:
NotebookEditorModel
,
@
IInstantiationService
private
readonly
instantiationService
:
IInstantiationService
,
@
IBulkEditService
private
readonly
bulkEditService
:
IBulkEditService
,
@
IUndoRedoService
private
readonly
undoService
:
IUndoRedoService
)
{
super
();
...
...
@@ -98,22 +114,6 @@ export class NotebookViewModel extends Disposable {
return
this
.
_viewCells
.
indexOf
(
cell
as
CellViewModel
);
}
/**
* Search in notebook text model
* @param value
*/
find
(
value
:
string
):
CellFindMatch
[]
{
const
matches
:
CellFindMatch
[]
=
[];
this
.
_viewCells
.
forEach
(
cell
=>
{
const
cellMatches
=
cell
.
startFind
(
value
);
if
(
cellMatches
)
{
matches
.
push
(
cellMatches
);
}
});
return
matches
;
}
insertCell
(
index
:
number
,
cell
:
ICell
):
CellViewModel
{
const
newCell
=
this
.
instantiationService
.
createInstance
(
CellViewModel
,
this
.
viewType
,
this
.
handle
,
cell
);
this
.
_viewCells
!
.
splice
(
index
,
0
,
newCell
);
...
...
@@ -245,6 +245,87 @@ export class NotebookViewModel extends Disposable {
return
ret
;
}
/**
* Search in notebook text model
* @param value
*/
find
(
value
:
string
):
CellFindMatch
[]
{
const
matches
:
CellFindMatch
[]
=
[];
this
.
_viewCells
.
forEach
(
cell
=>
{
const
cellMatches
=
cell
.
startFind
(
value
);
if
(
cellMatches
)
{
matches
.
push
(
cellMatches
);
}
});
return
matches
;
}
replaceOne
(
cell
:
ICellViewModel
,
range
:
Range
,
text
:
string
):
Promise
<
void
>
{
const
viewCell
=
cell
as
CellViewModel
;
this
.
_lastNotebookEditResource
.
push
(
viewCell
.
uri
);
return
viewCell
.
resolveTextModel
().
then
(()
=>
{
this
.
bulkEditService
.
apply
({
edits
:
[{
edit
:
{
range
:
range
,
text
:
text
},
resource
:
cell
.
uri
}]
},
{
quotableLabel
:
'
Notebook Replace
'
});
});
}
async
replaceAll
(
matches
:
CellFindMatch
[],
text
:
string
):
Promise
<
void
>
{
if
(
!
matches
.
length
)
{
return
;
}
let
textEdits
:
WorkspaceTextEdit
[]
=
[];
this
.
_lastNotebookEditResource
.
push
(
matches
[
0
].
cell
.
uri
);
matches
.
forEach
(
match
=>
{
match
.
matches
.
forEach
(
singleMatch
=>
{
textEdits
.
push
({
edit
:
{
range
:
singleMatch
.
range
,
text
:
text
},
resource
:
match
.
cell
.
uri
});
});
});
return
Promise
.
all
(
matches
.
map
(
match
=>
{
return
match
.
cell
.
resolveTextModel
();
})).
then
(
async
()
=>
{
this
.
bulkEditService
.
apply
({
edits
:
textEdits
},
{
quotableLabel
:
'
Notebook Replace All
'
});
return
;
});
}
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
;
}
undo
()
{
const
lastResource
=
this
.
lastNotebookEditResource
;
if
(
!
lastResource
)
{
return
;
}
const
lastElement
=
this
.
undoService
.
getLastElement
(
lastResource
);
if
(
lastElement
?.
label
===
'
Notebook Replace
'
||
lastElement
?.
label
===
'
Notebook Replace All
'
)
{
this
.
undoService
.
undo
(
lastResource
);
this
.
_lastNotebookEditResource
.
pop
();
}
}
equal
(
model
:
NotebookEditorModel
)
{
return
this
.
_model
===
model
;
}
...
...
src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts
浏览文件 @
d256d562
...
...
@@ -10,20 +10,26 @@ import { NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/noteb
import
{
NotebookViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
CellKind
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
TestNotebook
,
withTestNotebook
,
TestCell
}
from
'
vs/workbench/contrib/notebook/test/testNotebookEditor
'
;
import
{
IBulkEditService
}
from
'
vs/editor/browser/services/bulkEditService
'
;
import
{
IUndoRedoService
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
suite
(
'
NotebookViewModel
'
,
()
=>
{
const
instantiationService
=
new
TestInstantiationService
();
const
blukEditService
=
instantiationService
.
get
(
IBulkEditService
);
const
undoRedoService
=
instantiationService
.
get
(
IUndoRedoService
);
test
(
'
ctor
'
,
function
()
{
const
notebook
=
new
TestNotebook
(
0
,
'
notebook
'
,
URI
.
parse
(
'
test
'
));
const
model
=
new
NotebookEditorModel
(
notebook
);
const
viewModel
=
new
NotebookViewModel
(
'
notebook
'
,
model
,
instantiationService
);
const
viewModel
=
new
NotebookViewModel
(
'
notebook
'
,
model
,
instantiationService
,
blukEditService
,
undoRedoService
);
assert
.
equal
(
viewModel
.
viewType
,
'
notebook
'
);
});
test
(
'
insert/delete
'
,
function
()
{
withTestNotebook
(
instantiationService
,
blukEditService
,
undoRedoService
,
[
[[
'
var a = 1;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]],
[[
'
var b = 2;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]]
...
...
@@ -45,6 +51,8 @@ suite('NotebookViewModel', () => {
test
(
'
index
'
,
function
()
{
withTestNotebook
(
instantiationService
,
blukEditService
,
undoRedoService
,
[
[[
'
var a = 1;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]],
[[
'
var b = 2;
'
],
'
javascript
'
,
CellKind
.
Code
,
[]]
...
...
src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
浏览文件 @
d256d562
...
...
@@ -17,6 +17,8 @@ import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import
{
OutputRenderer
}
from
'
vs/workbench/contrib/notebook/browser/view/output/outputRenderer
'
;
import
{
BareFontInfo
}
from
'
vs/editor/common/config/fontInfo
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IBulkEditService
}
from
'
vs/editor/browser/services/bulkEditService
'
;
import
{
IUndoRedoService
}
from
'
vs/platform/undoRedo/common/undoRedo
'
;
export
class
TestCell
implements
ICell
{
uri
:
URI
;
...
...
@@ -200,7 +202,7 @@ export function createTestCellViewModel(instantiationService: IInstantiationServ
return
instantiationService
.
createInstance
(
CellViewModel
,
viewType
,
notebookHandle
,
mockCell
);
}
export
function
withTestNotebook
(
instantiationService
:
IInstantiationService
,
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
[]][],
callback
:
(
editor
:
TestNotebookEditor
,
viewModel
:
NotebookViewModel
)
=>
void
)
{
const
viewType
=
'
notebook
'
;
const
editor
=
new
TestNotebookEditor
();
const
notebook
=
new
TestNotebook
(
0
,
viewType
,
URI
.
parse
(
'
test
'
));
...
...
@@ -208,7 +210,7 @@ export function withTestNotebook(instantiationService: IInstantiationService, ce
return
new
TestCell
(
viewType
,
index
,
cell
[
0
],
cell
[
1
],
cell
[
2
],
cell
[
3
]);
});
const
model
=
new
NotebookEditorModel
(
notebook
);
const
viewModel
=
new
NotebookViewModel
(
viewType
,
model
,
instantiationService
);
const
viewModel
=
new
NotebookViewModel
(
viewType
,
model
,
instantiationService
,
blukEditService
,
undoRedoService
);
callback
(
editor
,
viewModel
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录