Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix selection and improve active text editor behaviour #14480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/main/browser/main-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container
rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_RENDERERS_MAIN, new NotebookRenderersMainImpl(rpc, container));
const notebookEditorsMain = new NotebookEditorsMainImpl(rpc, container);
rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_EDITORS_MAIN, notebookEditorsMain);
rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_AND_EDITORS_MAIN, new NotebooksAndEditorsMain(rpc, container, notebookDocumentsMain, notebookEditorsMain));
rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_AND_EDITORS_MAIN, new NotebooksAndEditorsMain(rpc, container, tabsMain, notebookDocumentsMain, notebookEditorsMain));
rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_KERNELS_MAIN, new NotebookKernelsMainImpl(rpc, container));

const editorsMain = new TextEditorsMainImpl(editorsAndDocuments, documentsMain, rpc, container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { NotebookEditorsMainImpl } from './notebook-editors-main';
import { NotebookDocumentsMainImpl } from './notebook-documents-main';
import { diffMaps, diffSets } from '../../../common/collections';
import { Mutex } from 'async-mutex';
import { TabsMainImpl } from '../tabs/tabs-main';

interface NotebookAndEditorDelta {
removedDocuments: UriComponents[];
Expand Down Expand Up @@ -96,6 +97,7 @@ export class NotebooksAndEditorsMain implements NotebookDocumentsAndEditorsMain
constructor(
rpc: RPCProtocol,
container: interfaces.Container,
tabsMain: TabsMainImpl,
protected readonly notebookDocumentsMain: NotebookDocumentsMainImpl,
protected readonly notebookEditorsMain: NotebookEditorsMainImpl
) {
Expand All @@ -113,7 +115,12 @@ export class NotebooksAndEditorsMain implements NotebookDocumentsAndEditorsMain
// this.WidgetManager.onActiveEditorChanged(() => this.updateState(), this, this.disposables);
this.notebookEditorService.onDidAddNotebookEditor(async editor => this.handleEditorAdd(editor), this, this.disposables);
this.notebookEditorService.onDidRemoveNotebookEditor(async editor => this.handleEditorRemove(editor), this, this.disposables);
this.notebookEditorService.onDidChangeCurrentEditor(async editor => this.updateState(editor), this, this.disposables);
this.notebookEditorService.onDidChangeCurrentEditor(async editor => {
if (editor) {
await tabsMain.waitForWidget(editor);
}
this.updateState(editor);
}, this, this.disposables);
}

dispose(): void {
Expand Down
15 changes: 10 additions & 5 deletions packages/plugin-ext/src/main/browser/text-editor-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,16 @@ export class TextEditorPropertiesMain {
if (editor && editor instanceof MonacoEditor) {
result = editor.getControl().getSelections() || undefined;
} else if (editor && editor instanceof SimpleMonacoEditor) {
result = editor.getControl().getSelections()?.map(selection => new monaco.Selection(
selection.startLineNumber,
selection.startColumn,
selection.positionLineNumber,
selection.positionColumn));
result = editor.getControl().getSelections()?.map(selection => {
const monacoSelection = new monaco.Selection(
selection.selectionStartLineNumber,
selection.selectionStartColumn,
selection.positionLineNumber,
selection.positionColumn);
monacoSelection.setStartPosition(selection.startLineNumber, selection.startColumn);
monacoSelection.setEndPosition(selection.endLineNumber, selection.endColumn);
return monacoSelection;
});
}

if (!result && prevProperties) {
Expand Down
14 changes: 8 additions & 6 deletions packages/plugin-ext/src/plugin/notebook/notebooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import { CancellationToken, Disposable, DisposableCollection, Emitter, Event, URI } from '@theia/core';
import { URI as TheiaURI } from '../types-impl';
import * as theia from '@theia/plugin';
import type * as theia from '@theia/plugin';
import {
NotebookCellStatusBarListDto, NotebookDataDto,
NotebookDocumentsAndEditorsDelta, NotebookDocumentShowOptions, NotebookDocumentsMain, NotebookEditorAddData, NotebookEditorsMain, NotebooksExt, NotebooksMain, Plugin,
Expand Down Expand Up @@ -337,12 +337,14 @@ export class NotebooksExtImpl implements NotebooksExt {
console.error(`FAILED to find active notebook editor ${delta.newActiveEditor}`);
}
this.activeNotebookEditor = this.editors.get(delta.newActiveEditor);
if (this.textDocumentsAndEditors.activeEditor()?.document.uri.path !== this.activeNotebookEditor?.notebookData.uri.path) {
this.textDocumentsAndEditors.acceptEditorsAndDocumentsDelta({
newActiveEditor: null
});
}
this.onDidChangeActiveNotebookEditorEmitter.fire(this.activeNotebookEditor?.apiEditor);

const newActiveCell = this.activeApiNotebookEditor?.notebook.cellAt(this.activeApiNotebookEditor.selection.start);
this.textDocumentsAndEditors.acceptEditorsAndDocumentsDelta({
newActiveEditor: newActiveCell?.kind === 2 /* code cell */ ?
this.textDocumentsAndEditors.allEditors().find(editor => editor.document.uri.toString() === newActiveCell.document.uri.toString())?.id ?? null :
null
});
}
}

Expand Down
Loading