feat: Scroll to search block location - #509
Conversation
There was a problem hiding this comment.
PR Summary
This PR implements a scroll-to-content feature for search results and similar entries, allowing users to navigate directly to relevant content when opening files.
- Added sophisticated content matching in
FileContext.tsxwith multiple fallback strategies (exact match, partial match, word-by-word search) to handle various text scenarios - Implemented text extraction logic in
DBResultPreview.tsxandSimilarEntriesComponent.tsxto identify meaningful content snippets for scrolling - Added
contentToScrollToparameter propagation through context providers and components to support the scroll feature - Potential timing issue in
FileContext.tsxwith 800ms setTimeout that could be unreliable for very large documents - Security consideration: Content extraction uses
removeMdfor sanitization, but should validate input lengths and content types
💡 (5/5) You can turn off certain types of comments like style here!
6 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile
| const firstFewLines = lines.slice(0, 5) | ||
| const titleLine = firstFewLines.find((line) => { | ||
| const trimmed = line.trim() | ||
| return trimmed && trimmed.length > 3 && trimmed.length < 100 |
There was a problem hiding this comment.
style: length > 3 may miss valid single-word titles
| content = ( | ||
| <div className="size-full"> | ||
| {similarEntries | ||
| .filter((dbResult) => dbResult) |
There was a problem hiding this comment.
style: filter(dbResult => dbResult) won't catch empty content - should be more specific
| onSelect={(path, content) => { | ||
| openTabContent(path, undefined, false, content) | ||
| posthog.capture('open_file_from_related_notes') |
There was a problem hiding this comment.
style: The undefined parameter passed to openTabContent could be removed since it's not being used meaningfully
| const getFileName = (path: string) => { | ||
| if (!path) return null | ||
| const parts = path.split('/') | ||
| return parts[parts.length - 1] | ||
| } |
There was a problem hiding this comment.
logic: getFileName now returns null for invalid paths but this isn't handled in the UI rendering - could cause runtime errors
| const getFileName = (path: string) => { | |
| if (!path) return null | |
| const parts = path.split('/') | |
| return parts[parts.length - 1] | |
| } | |
| {fileName ? <span className="text-xs text-gray-400">{fileName} </span> : null} | Similarity:{' '} |
| // @ts-ignore - HTMLElement does have scrollIntoView | ||
| bestMatchElement.scrollIntoView({ behavior: 'smooth', block: 'center' }) |
There was a problem hiding this comment.
style: Remove @ts-ignore and properly type HTMLElement. scrollIntoView is a standard method that shouldn't need ignoring
| // @ts-ignore - HTMLElement does have scrollIntoView | |
| bestMatchElement.scrollIntoView({ behavior: 'smooth', block: 'center' }) | |
| bestMatchElement.scrollIntoView({ behavior: 'smooth', block: 'center' }) |
Screen.Recording.2025-03-24.at.11.41.05.mov