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,38 +27,46 @@ 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) {
return editor.viewModel.undo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markup && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
cell.updateEditState(CellEditState.Editing, 'undo');
}
});
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane) as NotebookEditorWidget | undefined;
if (editor?.hasModel()) {
const activeCodeEditor = editor.activeCodeEditor;
editor?.setOptions({ cellOptions: { resource: cellResources[0] }, preserveFocus: true });
}
});
if (activeCodeEditor && activeCodeEditor.hasTextFocus()) {
return editor.viewModel.undo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markup && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
cell.updateEditState(CellEditState.Editing, 'undo');
}
});
editor?.setOptions({ cellOptions: { resource: cellResources[0] }, preserveFocus: true });
}
});
}
}
return false;
}));
this._register(RedoCommand.addImplementation(10000 + 5, 'notebook-undo-redo', () => {
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
if (editor?.viewModel) {
return editor.viewModel.redo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markup && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
cell.updateEditState(CellEditState.Editing, 'redo');
}
});
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane) as NotebookEditorWidget | undefined;
if (editor?.hasModel()) {
const activeCodeEditor = editor.activeCodeEditor;
editor?.setOptions({ cellOptions: { resource: cellResources[0] }, preserveFocus: true });
}
});
if (activeCodeEditor && activeCodeEditor.hasTextFocus()) {
return editor.viewModel.redo().then(cellResources => {
if (cellResources?.length) {
editor?.viewModel?.viewCells.forEach(cell => {
if (cell.cellKind === CellKind.Markup && cellResources.find(resource => resource.fragment === cell.model.uri.fragment)) {
cell.updateEditState(CellEditState.Editing, 'redo');
}
});
editor?.setOptions({ cellOptions: { resource: cellResources[0] }, preserveFocus: true });
}
});
}
}
return false;