-
Notifications
You must be signed in to change notification settings - Fork 121
Fix Positron notebook markdown cell focus bugs #9949
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
base: main
Are you sure you want to change the base?
Conversation
E2E Tests 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes two focus-related bugs with markdown cells in Positron notebooks: double-clicking to edit markdown cells losing focus (#9877) and ellipsis button clicks causing focus jumps (#9909). The fixes address race conditions in event propagation and editor initialization.
Key changes:
- Enhanced the selection state machine with better focus management and race condition prevention
- Fixed ellipsis button event propagation to prevent unwanted cell deselection
- Improved markdown cell editor initialization to ensure proper focus timing
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
test/e2e/tests/notebook/notebook-focus-and-selection.test.ts | Unskipped a test that was previously failing due to the focus bugs |
src/vs/workbench/contrib/positronNotebook/browser/selectionMachine.ts | Enhanced selection state machine with improved focus management and race condition prevention |
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/actionBar/NotebookCellMoreActionsMenu.tsx | Added event propagation prevention to ellipsis button click handler |
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/NotebookMarkdownCell.tsx | Removed double-click handler from markdown cell rendering |
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/CellEditorMonacoWidget.tsx | Added selection state validation to prevent stale focus requests |
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookInstance.ts | Simplified cell creation logic to use the enhanced selection state machine |
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookMarkdownCell.ts | Enhanced editor initialization with proper async handling and text model loading |
src/vs/workbench/contrib/positronNotebook/browser/IPositronNotebookInstance.ts | Removed obsolete setEditingCell method from interface |
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/NotebookMarkdownCell.tsx
Outdated
Show resolved
Hide resolved
b6feb92
to
6445435
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
await extensionService.whenInstalledExtensionsRegistered(); | ||
|
||
const languageId = languageService.getLanguageIdByLanguageName(lang) | ||
?? languageService.getLanguageIdByLanguageName(lang.split(/\s+|:|,|(?!^)\{|\?]/, 1)[0]); |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regular expression has an unmatched closing bracket ]
without a corresponding opening bracket. This will cause a syntax error. The regex should be /\s+|:|,|(?!^)\{|\?/
(remove the ]
).
?? languageService.getLanguageIdByLanguageName(lang.split(/\s+|:|,|(?!^)\{|\?]/, 1)[0]); | |
?? languageService.getLanguageIdByLanguageName(lang.split(/\s+|:|,|(?!^)\{|\?/, 1)[0]); |
Copilot uses AI. Check for mistakes.
* NOTE: This code is duplicated from markdownDocumentRenderer.ts (MarkedHighlight namespace) | ||
* which itself copied it from https://github.com/markedjs/marked-highlight. | ||
* | ||
* We duplicate it here rather than modifying upstream code to avoid merge conflicts. | ||
* The MarkedHighlight namespace is private in upstream, so we can't import it. | ||
* | ||
* If VSCode upstream exports this utility in the future, we should use that instead. |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicated code creates maintainability concerns. Consider extracting the shared functionality into a common utility module that both files can import, rather than duplicating the implementation.
Copilot uses AI. Check for mistakes.
* In <pre> elements, whitespace must be preserved per HTML spec. | ||
* | ||
* This is an O(n) operation, where n is the depth of the node in the tree which | ||
* is not super ideal and could be optimized with additional state tracking if | ||
* needed but until we see performance issues the encapsulation provided by | ||
* this implementation is worth it. |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The O(n) tree traversal for every text node could impact performance with deeply nested HTML structures. Consider tracking pre-element state during parsing to avoid repeated traversals.
Copilot uses AI. Check for mistakes.
6445435
to
51fc434
Compare
Humble request where there are UI changes can you pls include a video for me to review. This may also help QA. My code reviews won't be great :) Thanks |
… editor needed to be instantiated first causing selection to jump to first cell
…election behavior.
… to marked.js. Fixes styles etc..
51fc434
to
6a07722
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look great! I remember we spoke a long time ago about focus being a real pain point across notebook UIs, so this is very important
* We duplicate it here rather than modifying upstream code to avoid merge conflicts. | ||
* The MarkedHighlight namespace is private in upstream, so we can't import it. | ||
* | ||
* If VSCode upstream exports this utility in the future, we should use that instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't expect to change their implementation, it shouldn't cause bad conflicts to add an export
to the upstream code. But if we don't really need to stay in sync with any upstream changes, copy pasting is fine too
// Watch for editor focus requests from the cell | ||
React.useLayoutEffect(() => { | ||
// Subscribe to focus request signal - triggers whenever requestEditorFocus() is called | ||
const disposable = autorun(reader => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently realized that autorun
also has an initial run on definition. Where we don't want that we might prefer something like runOnChange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! ty for the screenshots
Addresses #9877, #9909, and #9849.
Summary
This is a general bug-bash pr for markdown rendering in positron notebooks. It addresses two focus-related bugs and improves markdown syntax highlighting in Positron notebooks.
Double-clicking to edit markdown cells loses focus (Creating a new markdown cell does not default to edit mode #9877): When double-clicking a collapsed markdown cell to enter edit mode, focus would jump to the top of the notebook instead of entering the editor. This was caused by a race condition where the Monaco editor's model wasn't fully loaded before attempting to focus.
Ellipsis button click causes focus jump (Clicking on the ellipses for a collapsed markdown cell brings you to the top of the notebook #9909): Clicking the ellipsis (more actions) button on a collapsed markdown cell would cause focus to jump to the top of the notebook. This occurred because the button's click event wasn't stopped from propagating to the cell wrapper, which triggered cell deselection logic.
*Markdown syntax highlighting: Markdown code blocks in notebook cells now use VSCode's tokenization system with
.mtk*
classes that automatically match the current theme etc.. This avoids needing to call to an async command and speeds up rendering/ makes it more debugable.Old
New look
Release Notes
New Features
Bug Fixes
QA Notes
@:positron-notebooks
Markdown cell focus behavior:
Markdown cell action buttons:
Markdown syntax highlighting: