-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Fix notebook outline symbol highlighting by using range instead of position #251149
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
…sition Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
@@ -741,7 +741,7 @@ export class NotebookCellOutline implements IOutline<OutlineEntry> { | |||
...options, | |||
override: this._editor.input?.editorId, | |||
cellRevealType: CellRevealType.NearTopIfOutsideViewport, | |||
selection: entry.position, | |||
selection: entry.range, |
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 range is not fully correct. Here is what happens right now with your change. Given the following code in a javascript cell:
// fn cell
const temp = "hello world"
console.log(temp);
function add(a, b) {
return a + b;
}
console.log(add(1, 2));
function sub(a, b) {
return a - b;
}
clicking the notebook outline entry for either add or sub should highlight the entire fn, and then clicking the entry for temp should highlight temp = "hello world"
. This makes me think we may not be storing entry ranges correctly.
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.
Thanks for the detailed feedback with the concrete example. I've updated the implementation to properly handle both range types from document symbols and support the select parameter for different click behaviors (577314d).
The changes now:
- Store both
symbol.range
(full symbol) andsymbol.selectionRange
(symbol name) from document symbols - Use full range for highlighting on double-click and collapsed range for cursor positioning on single-click
- Match the behavior pattern from the regular document symbols outline
However, if the ranges are still not correct for JavaScript functions, the issue might be that the JavaScript language service itself is not providing full function body ranges in symbol.range
. Could you help me understand: are you seeing this issue specifically with JavaScript cells, or does it affect other languages too? This would help determine if it's a language service limitation or something else in our range handling.
- Add selectionRange support to OutlineEntry for both full symbol range and selection range - Update reveal method to handle select parameter for double-click vs single-click behavior - Use full range for highlighting (double-click) and collapsed range for cursor positioning (single-click) - Add comprehensive tests for both highlighting and positioning behaviors Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
When clicking on a symbol in the notebook outline view, the editor would navigate to the cell but wouldn't highlight the line or select the symbol properly, unlike the behavior in regular text editors.
Root Cause
The notebook outline's
reveal
method was passingentry.position
(just the start position) instead ofentry.range
(the full range) for the selection parameter:Solution
Changed the
NotebookCellOutline.reveal
method to pass the full range instead of just the position. This matches how the document symbols outline works and provides the complete range information needed for proper symbol highlighting.Impact
IRange
is fully compatible withITextEditorSelection
The change is minimal (1 line) and maintains backward compatibility while fixing the highlighting issue.
Fixes #209161.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
electronjs.org
node-gyp
(dns block)If you need me to access, download, or install something from one of these locations, you can either: