re #128173. Only handle monaco editor textarea.

This commit is contained in:
rebornix 2021-08-06 11:55:33 -07:00
parent a0696fb236
commit 3d9899db8e

View file

@ -11,6 +11,7 @@ import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { CellEditState, getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { RedoCommand, UndoCommand } from 'vs/editor/browser/editorExtensions';
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
class NotebookUndoRedoContribution extends Disposable {
@ -26,8 +27,11 @@ class NotebookUndoRedoContribution extends Disposable {
* We now make the notebook undo/redo impl the highest priority so we don't skip the "invalid" undo/redo element in the same notebook document
*/
this._register(UndoCommand.addImplementation(10000 + 5, 'notebook-undo-redo', () => {
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
if (editor?.viewModel) {
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane) as NotebookEditorWidget | undefined;
if (editor?.hasModel()) {
const activeCodeEditor = editor.activeCodeEditor;
if (activeCodeEditor && activeCodeEditor.hasTextFocus()) {
return editor.viewModel.undo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
@ -40,13 +44,17 @@ class NotebookUndoRedoContribution extends Disposable {
}
});
}
}
return false;
}));
this._register(RedoCommand.addImplementation(10000 + 5, 'notebook-undo-redo', () => {
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
if (editor?.viewModel) {
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane) as NotebookEditorWidget | undefined;
if (editor?.hasModel()) {
const activeCodeEditor = editor.activeCodeEditor;
if (activeCodeEditor && activeCodeEditor.hasTextFocus()) {
return editor.viewModel.redo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
@ -59,6 +67,7 @@ class NotebookUndoRedoContribution extends Disposable {
}
});
}
}
return false;
}));