Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
846aec81
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,发现更多精彩内容 >>
提交
846aec81
编写于
5月 04, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - Format Cell instead of Format Document, also add Format Notebook
上级
ab675cf7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
75 addition
and
13 deletion
+75
-13
src/vs/editor/common/editorContextKeys.ts
src/vs/editor/common/editorContextKeys.ts
+7
-0
src/vs/editor/contrib/format/formatActions.ts
src/vs/editor/contrib/format/formatActions.ts
+1
-1
src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.ts
...nch/contrib/notebook/browser/contrib/format/formatting.ts
+44
-6
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
+1
-1
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
...h/contrib/notebook/browser/view/renderers/cellRenderer.ts
+10
-3
src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts
...h/contrib/notebook/browser/view/renderers/markdownCell.ts
+12
-2
未找到文件。
src/vs/editor/common/editorContextKeys.ts
浏览文件 @
846aec81
...
...
@@ -36,6 +36,13 @@ export namespace EditorContextKeys {
export
const
canUndo
=
new
RawContextKey
<
boolean
>
(
'
canUndo
'
,
false
);
export
const
canRedo
=
new
RawContextKey
<
boolean
>
(
'
canRedo
'
,
false
);
/**
* A context key that is set when an editor is part of a larger editor, like notebooks or
* (future) a diff editor
*/
export
const
inCompositeEditor
=
new
RawContextKey
<
boolean
>
(
'
inCompositeEditor
'
,
undefined
);
export
const
notInCompositeEditor
=
inCompositeEditor
.
toNegated
();
// -- mode context keys
export
const
languageId
=
new
RawContextKey
<
string
>
(
'
editorLangId
'
,
''
);
export
const
hasCompletionItemProvider
=
new
RawContextKey
<
boolean
>
(
'
editorHasCompletionItemProvider
'
,
false
);
...
...
src/vs/editor/contrib/format/formatActions.ts
浏览文件 @
846aec81
...
...
@@ -213,7 +213,7 @@ class FormatDocumentAction extends EditorAction {
id
:
'
editor.action.formatDocument
'
,
label
:
nls
.
localize
(
'
formatDocument.label
'
,
"
Format Document
"
),
alias
:
'
Format Document
'
,
precondition
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
writable
,
EditorContextKeys
.
hasDocumentFormattingProvider
),
precondition
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
notInCompositeEditor
,
EditorContextKeys
.
writable
,
EditorContextKeys
.
hasDocumentFormattingProvider
),
kbOpts
:
{
kbExpr
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
editorTextFocus
,
EditorContextKeys
.
hasDocumentFormattingProvider
),
primary
:
KeyMod
.
Shift
|
KeyMod
.
Alt
|
KeyCode
.
KEY_F
,
...
...
src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.ts
浏览文件 @
846aec81
...
...
@@ -3,38 +3,48 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
registerAction2
,
Action2
}
from
'
vs/platform/actions/common/actions
'
;
import
{
registerAction2
,
Action2
,
MenuId
}
from
'
vs/platform/actions/common/actions
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
NOTEBOOK_IS_ACTIVE_EDITOR
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
NOTEBOOK_IS_ACTIVE_EDITOR
,
NOTEBOOK_EDITOR_EDITABLE
}
from
'
vs/workbench/contrib/notebook/browser/notebookBrowser
'
;
import
{
KeybindingWeight
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ServicesAccessor
,
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
getActiveNotebookEditor
,
NOTEBOOK_ACTIONS_CATEGORY
}
from
'
vs/workbench/contrib/notebook/browser/contrib/coreActions
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ITextModelService
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
getDocumentFormattingEditsUntilResult
}
from
'
vs/editor/contrib/format/format
'
;
import
{
getDocumentFormattingEditsUntilResult
,
formatDocumentWithSelectedProvider
,
FormattingMode
}
from
'
vs/editor/contrib/format/format
'
;
import
{
IEditorWorkerService
}
from
'
vs/editor/common/services/editorWorkerService
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
IBulkEditService
}
from
'
vs/editor/browser/services/bulkEditService
'
;
import
{
WorkspaceTextEdit
}
from
'
vs/editor/common/modes
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
import
{
registerEditorAction
,
EditorAction
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
Progress
}
from
'
vs/platform/progress/common/progress
'
;
// format notebook
registerAction2
(
class
extends
Action2
{
constructor
()
{
super
({
id
:
'
notebook.format
'
,
title
:
localize
(
'
format.title
'
,
'
Format Notebook
'
),
category
:
NOTEBOOK_ACTIONS_CATEGORY
,
precondition
:
ContextKeyExpr
.
and
(
NOTEBOOK_IS_ACTIVE_EDITOR
),
precondition
:
ContextKeyExpr
.
and
(
NOTEBOOK_IS_ACTIVE_EDITOR
,
NOTEBOOK_EDITOR_EDITABLE
),
keybinding
:
{
when
:
EditorContextKeys
.
editorTextFocus
.
toNegated
(),
primary
:
KeyMod
.
Shift
|
KeyMod
.
Alt
|
KeyCode
.
KEY_F
,
linux
:
{
primary
:
KeyMod
.
CtrlCmd
|
KeyMod
.
Shift
|
KeyCode
.
KEY_I
},
weight
:
KeybindingWeight
.
WorkbenchContrib
},
f1
:
true
f1
:
true
,
menu
:
{
id
:
MenuId
.
EditorContext
,
when
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
inCompositeEditor
,
EditorContextKeys
.
hasDocumentFormattingProvider
),
group
:
'
1_modification
'
,
order
:
1.3
}
});
}
...
...
@@ -84,6 +94,34 @@ registerAction2(class extends Action2 {
}
finally
{
dispoables
.
dispose
();
}
}
});
// format cell
registerEditorAction
(
class
FormatCellAction
extends
EditorAction
{
constructor
()
{
super
({
id
:
'
notebook.formatCell
'
,
label
:
localize
(
'
formatCell.label
'
,
"
Format Cell
"
),
alias
:
'
Format Cell
'
,
precondition
:
ContextKeyExpr
.
and
(
NOTEBOOK_IS_ACTIVE_EDITOR
,
NOTEBOOK_EDITOR_EDITABLE
,
EditorContextKeys
.
inCompositeEditor
,
EditorContextKeys
.
writable
,
EditorContextKeys
.
hasDocumentFormattingProvider
),
kbOpts
:
{
kbExpr
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
editorTextFocus
),
primary
:
KeyMod
.
Shift
|
KeyMod
.
Alt
|
KeyCode
.
KEY_F
,
linux
:
{
primary
:
KeyMod
.
CtrlCmd
|
KeyMod
.
Shift
|
KeyCode
.
KEY_I
},
weight
:
KeybindingWeight
.
EditorContrib
},
contextMenuOpts
:
{
group
:
'
1_modification
'
,
order
:
1.301
}
});
}
async
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
if
(
editor
.
hasModel
())
{
const
instaService
=
accessor
.
get
(
IInstantiationService
);
await
instaService
.
invokeFunction
(
formatDocumentWithSelectedProvider
,
editor
,
FormattingMode
.
Explicit
,
Progress
.
None
,
CancellationToken
.
None
);
}
}
});
src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
浏览文件 @
846aec81
...
...
@@ -254,7 +254,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
const
dndController
=
new
CellDragAndDropController
(
this
);
const
renders
=
[
this
.
instantiationService
.
createInstance
(
CodeCellRenderer
,
this
,
this
.
contextKeyService
,
this
.
renderedEditors
,
dndController
),
this
.
instantiationService
.
createInstance
(
CodeCellRenderer
,
this
,
this
.
renderedEditors
,
dndController
),
this
.
instantiationService
.
createInstance
(
MarkdownCellRenderer
,
this
.
contextKeyService
,
this
,
dndController
,
this
.
renderedEditors
),
];
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts
浏览文件 @
846aec81
...
...
@@ -50,6 +50,8 @@ import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewMod
import
{
MarkdownCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel
'
;
import
{
CellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel
'
;
import
{
CellKind
,
NotebookCellRunState
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
const
$
=
DOM
.
$
;
...
...
@@ -416,7 +418,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
this
.
setupBetweenCellToolbarActions
(
element
,
templateData
,
elementDisposables
,
toolbarContext
);
const
markdownCell
=
new
StatefullMarkdownCell
(
this
.
notebookEditor
,
element
,
templateData
,
this
.
editorOptions
.
value
,
this
.
renderedEditors
,
this
.
instantiationService
);
const
markdownCell
=
this
.
instantiationService
.
createInstance
(
StatefullMarkdownCell
,
this
.
notebookEditor
,
element
,
templateData
,
this
.
editorOptions
.
value
,
this
.
renderedEditors
);
elementDisposables
.
add
(
this
.
editorOptions
.
onDidChange
(
newValue
=>
markdownCell
.
updateEditorOptions
(
newValue
)));
elementDisposables
.
add
(
markdownCell
);
...
...
@@ -703,9 +705,9 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
constructor
(
protected
notebookEditor
:
INotebookEditor
,
protected
contextKeyService
:
IContextKeyService
,
private
renderedEditors
:
Map
<
ICellViewModel
,
ICodeEditor
|
undefined
>
,
dndController
:
CellDragAndDropController
,
@
IContextKeyService
protected
contextKeyService
:
IContextKeyService
,
@
IContextMenuService
contextMenuService
:
IContextMenuService
,
@
IConfigurationService
configurationService
:
IConfigurationService
,
@
IInstantiationService
instantiationService
:
IInstantiationService
,
...
...
@@ -734,9 +736,14 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
const
executionOrderLabel
=
DOM
.
append
(
runButtonContainer
,
$
(
'
div.execution-count-label
'
));
// create a special context key service that set the inCompositeEditor-contextkey
const
editorContextKeyService
=
this
.
contextKeyService
.
createScoped
();
const
editorInstaService
=
this
.
instantiationService
.
createChild
(
new
ServiceCollection
([
IContextKeyService
,
editorContextKeyService
]));
EditorContextKeys
.
inCompositeEditor
.
bindTo
(
editorContextKeyService
).
set
(
true
);
const
editorPart
=
DOM
.
append
(
cellContainer
,
$
(
'
.cell-editor-part
'
));
const
editorContainer
=
DOM
.
append
(
editorPart
,
$
(
'
.cell-editor-container
'
));
const
editor
=
this
.
instantiation
Service
.
createInstance
(
CodeEditorWidget
,
editorContainer
,
{
const
editor
=
editorInsta
Service
.
createInstance
(
CodeEditorWidget
,
editorContainer
,
{
...
this
.
editorOptions
.
value
,
dimension
:
{
width
:
0
,
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts
浏览文件 @
846aec81
...
...
@@ -18,6 +18,9 @@ import { getResizesObserver } from 'vs/workbench/contrib/notebook/browser/view/r
import
{
CellFoldingState
}
from
'
vs/workbench/contrib/notebook/browser/contrib/fold/foldingModel
'
;
import
{
MarkdownCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
export
class
StatefullMarkdownCell
extends
Disposable
{
...
...
@@ -35,7 +38,8 @@ export class StatefullMarkdownCell extends Disposable {
private
templateData
:
MarkdownCellRenderTemplate
,
editorOptions
:
IEditorOptions
,
renderedEditors
:
Map
<
ICellViewModel
,
ICodeEditor
|
undefined
>
,
instantiationService
:
IInstantiationService
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
IInstantiationService
instantiationService
:
IInstantiationService
,
)
{
super
();
...
...
@@ -70,7 +74,13 @@ export class StatefullMarkdownCell extends Disposable {
editorHeight
=
Math
.
max
(
lineNum
,
1
)
*
lineHeight
+
EDITOR_TOP_PADDING
+
EDITOR_BOTTOM_PADDING
;
this
.
templateData
.
editorContainer
.
innerHTML
=
''
;
this
.
editor
=
instantiationService
.
createInstance
(
CodeEditorWidget
,
this
.
templateData
.
editorContainer
,
{
// create a special context key service that set the inCompositeEditor-contextkey
const
editorContextKeyService
=
contextKeyService
.
createScoped
();
const
editorInstaService
=
instantiationService
.
createChild
(
new
ServiceCollection
([
IContextKeyService
,
editorContextKeyService
]));
EditorContextKeys
.
inCompositeEditor
.
bindTo
(
editorContextKeyService
).
set
(
true
);
this
.
editor
=
editorInstaService
.
createInstance
(
CodeEditorWidget
,
this
.
templateData
.
editorContainer
,
{
...
this
.
editorOptions
,
dimension
:
{
width
:
width
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录