-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: center active search match in CodeMirror viewport #7918
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
DevRajah
wants to merge
1
commit into
usebruno:main
Choose a base branch
from
DevRajah:fix-json-search-result-position
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.
+25
−1
Open
Changes from all commits
Commits
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
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.
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.
🧩 Analysis chain
🌐 Web query:
In CodeMirror 5, what is the difference betweenheightAtLine(line, 'local')andcharCoords(pos, 'local'), and which API reflects the actual vertical position of a match inside a wrapped line?💡 Result:
In CodeMirror 5,
heightAtLine(line, "local")andcharCoords(pos, "local")both accept"local"as the coordinate reference mode, but they answer different geometry questions: 1)heightAtLine(line, "local")- Returns the y position (height from the top of the editor viewport) of the top of the given logical line. - It’s line-level and based on CodeMirror’s internal measurement model for line heights (which can be approximated when the line has not actually been rendered due to viewport/lazy rendering) [1]. - For wrapped lines, this is about the logical line’s top (not a specific visual wrap “sub-line”), so it does not directly tell you where a particular wrapped segment starts/ends. 2)charCoords(pos, "local")- Returns the rectangle for a specific character position in the document, includingtop/bottomin the chosen coordinate system (here,"local") [2][3]. - Because it’s character-based, it reflects the actual layout of the visual line wrapping for that position (including which wrapped segment the character is on). Which API reflects the actual vertical position of a match inside a wrapped line? - UsecharCoords(pos, "local")for match rendering/positioning. Since matches are character ranges (positions) and wrapping is visual/segment-based, the character rectangle returned bycharCoordsis the API that corresponds to the actual on-screen vertical placement of the match within wrapped lines [2][3]. Important nuance about"local"- There have been historical issues wherecharCoords(..., "local")could be inconsistent/off by padding (and related fixes landed) [4]. So if you’re comparing to other local measurements (or doing pixel-perfect positioning), you should validate againstgetScrollInfo()/wrapper padding in your exact setup—but the character-based nature ofcharCoordsremains what makes it the correct choice for “vertical position of a match inside a wrapped line.” [4][2]Citations:
Use
charCoords()to reflect the actual position of wrapped matches.heightAtLine()returns only the logical line's top, which doesn't account for the actual vertical position of a match within a wrapped line.charCoords()is character-position aware and reflects the true on-screen placement.🔧 Suggested change
🤖 Prompt for AI Agents