-
Notifications
You must be signed in to change notification settings - Fork 121
Fix empty editor bug #9996
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
Open
nstrayer
wants to merge
6
commits into
main
Choose a base branch
from
positron-nb-blank-editor-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+554
−66
Open
Fix empty editor bug #9996
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b45d4b8
Fix empty editor bug
nstrayer 1ce05b9
Unskip test
nstrayer 1885c7a
Make sure to keep focus on the correct notebook and also to make sure…
nstrayer 897e1d5
Switch to grabbing instance from active editor rather than from the n…
nstrayer dbff586
Remove all uses of the notebook service active instance getter
nstrayer c24eed1
Replace the listInstances method with utility functions
nstrayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2025 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { URI } from '../../../../base/common/uri.js'; | ||
import { isEqual } from '../../../../base/common/resources.js'; | ||
import { IEditorService } from '../../../services/editor/common/editorService.js'; | ||
import { IPositronNotebookInstance } from './IPositronNotebookInstance.js'; | ||
import { PositronNotebookEditor } from './PositronNotebookEditor.js'; | ||
import { POSITRON_NOTEBOOK_EDITOR_ID } from '../common/positronNotebookCommon.js'; | ||
|
||
/** | ||
* Retrieves the active Positron notebook instance from the editor service. | ||
* | ||
* @param editorService The editor service | ||
* @returns The active notebook instance, or undefined if no Positron notebook is active | ||
*/ | ||
export function getActiveNotebook(editorService: IEditorService): IPositronNotebookInstance | undefined { | ||
const activeEditorPane = editorService.activeEditorPane; | ||
|
||
// Check if the active editor is a Positron Notebook Editor | ||
if (!activeEditorPane || activeEditorPane.getId() !== POSITRON_NOTEBOOK_EDITOR_ID) { | ||
return undefined; | ||
} | ||
|
||
// Extract the notebook instance from the editor | ||
const activeNotebook = (activeEditorPane as PositronNotebookEditor).notebookInstance; | ||
return activeNotebook; | ||
} | ||
|
||
/** | ||
* Checks if any notebook instance for a given URI is connected to an editor. | ||
* | ||
* @param editorService The editor service | ||
* @param uri The notebook URI to check | ||
* @returns True if any notebook instance for this URI is connected to an editor, false otherwise | ||
*/ | ||
export function hasConnectedNotebookForUri( | ||
editorService: IEditorService, | ||
uri: URI | ||
): boolean { | ||
for (const editorPane of editorService.visibleEditorPanes) { | ||
if (editorPane.getId() === POSITRON_NOTEBOOK_EDITOR_ID) { | ||
const notebookEditor = editorPane as PositronNotebookEditor; | ||
const instance = notebookEditor.notebookInstance; | ||
|
||
if (instance && isEqual(instance.uri, uri) && instance.connectedToEditor) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Retrieves all Positron notebook instances from visible editor panes. | ||
* | ||
* @param editorService The editor service | ||
* @param uri Optional URI to filter instances by | ||
* @returns Array of all notebook instances, optionally filtered by URI | ||
*/ | ||
export function getAllPositronNotebookInstances( | ||
editorService: IEditorService, | ||
uri?: URI | ||
): IPositronNotebookInstance[] { | ||
const instances: IPositronNotebookInstance[] = []; | ||
|
||
for (const editorPane of editorService.visibleEditorPanes) { | ||
if (editorPane.getId() === POSITRON_NOTEBOOK_EDITOR_ID) { | ||
const notebookEditor = editorPane as PositronNotebookEditor; | ||
const instance = notebookEditor.notebookInstance; | ||
|
||
if (instance) { | ||
if (!uri || isEqual(instance.uri, uri)) { | ||
instances.push(instance); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return instances; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.