Skip to content

Commit

Permalink
added update context
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderPho committed Sep 6, 2024
1 parent 7ab7910 commit 8e42c29
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ import { register as registerCellTagsView } from './cellTagsTreeDataProvider';
export function activate(context: vscode.ExtensionContext) {
registerCellTags(context);
registerCellTagsView(context);

// Update context when the active editor or selection changes
vscode.window.onDidChangeActiveNotebookEditor(updateContext);
vscode.window.onDidChangeNotebookEditorSelection(updateContext);

// Initialize the status bar
updateContext();
}

function updateContext() {
const editor = vscode.window.activeNotebookEditor;
if (!editor) {
vscode.commands.executeCommand('setContext', 'jupyter-cell-tags.singleCellSelected', false);
vscode.commands.executeCommand('setContext', 'jupyter-cell-tags.multipleCellsSelected', false);
console.log('No active notebook editor');
debugSelectedCellsStatusBarItem.hide();
return;
}

const selectionCount = editor.selections.length;
vscode.commands.executeCommand('setContext', 'jupyter-cell-tags.singleCellSelected', selectionCount === 1);
vscode.commands.executeCommand('setContext', 'jupyter-cell-tags.multipleCellsSelected', selectionCount > 1);

console.log(`Selection count: ${selectionCount}`);
console.log(`Single cell selected: ${selectionCount === 1}`);
console.log(`Multiple cells selected: ${selectionCount > 1}`);

debugSelectedCellsStatusBarItem.text = `$(notebook) ${selectionCount} Cell(s) Selected`;
debugSelectedCellsStatusBarItem.show();
}


export function deactivate() {}

0 comments on commit 8e42c29

Please sign in to comment.