mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Merge pull request #1682 from Stijnus/origin/ACT_BoltDYI_BUGFIX_SEARCH
fix: invalid line number error in search functionality
This commit is contained in:
commit
5c9d413344
@ -169,12 +169,25 @@ export const CodeMirrorEditor = memo(
|
|||||||
if (typeof doc.scroll?.line === 'number') {
|
if (typeof doc.scroll?.line === 'number') {
|
||||||
const line = doc.scroll.line;
|
const line = doc.scroll.line;
|
||||||
const column = doc.scroll.column ?? 0;
|
const column = doc.scroll.column ?? 0;
|
||||||
const linePos = viewRef.current.state.doc.line(line + 1).from + column;
|
|
||||||
viewRef.current.dispatch({
|
try {
|
||||||
selection: { anchor: linePos },
|
// Check if the line number is valid for the current document
|
||||||
scrollIntoView: true,
|
const totalLines = viewRef.current.state.doc.lines;
|
||||||
});
|
|
||||||
viewRef.current.focus();
|
// Only proceed if the line number is within the document's range
|
||||||
|
if (line < totalLines) {
|
||||||
|
const linePos = viewRef.current.state.doc.line(line + 1).from + column;
|
||||||
|
viewRef.current.dispatch({
|
||||||
|
selection: { anchor: linePos },
|
||||||
|
scrollIntoView: true,
|
||||||
|
});
|
||||||
|
viewRef.current.focus();
|
||||||
|
} else {
|
||||||
|
logger.warn(`Invalid line number ${line + 1} in ${totalLines}-line document`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error scrolling to line:', error);
|
||||||
|
}
|
||||||
} else if (typeof doc.scroll?.top === 'number' || typeof doc.scroll?.left === 'number') {
|
} else if (typeof doc.scroll?.top === 'number' || typeof doc.scroll?.left === 'number') {
|
||||||
viewRef.current.scrollDOM.scrollTo(doc.scroll.left ?? 0, doc.scroll.top ?? 0);
|
viewRef.current.scrollDOM.scrollTo(doc.scroll.left ?? 0, doc.scroll.top ?? 0);
|
||||||
}
|
}
|
||||||
@ -441,12 +454,25 @@ function setEditorDocument(
|
|||||||
if (typeof doc.scroll?.line === 'number') {
|
if (typeof doc.scroll?.line === 'number') {
|
||||||
const line = doc.scroll.line;
|
const line = doc.scroll.line;
|
||||||
const column = doc.scroll.column ?? 0;
|
const column = doc.scroll.column ?? 0;
|
||||||
const linePos = view.state.doc.line(line + 1).from + column;
|
|
||||||
view.dispatch({
|
try {
|
||||||
selection: { anchor: linePos },
|
// Check if the line number is valid for the current document
|
||||||
scrollIntoView: true,
|
const totalLines = view.state.doc.lines;
|
||||||
});
|
|
||||||
view.focus();
|
// Only proceed if the line number is within the document's range
|
||||||
|
if (line < totalLines) {
|
||||||
|
const linePos = view.state.doc.line(line + 1).from + column;
|
||||||
|
view.dispatch({
|
||||||
|
selection: { anchor: linePos },
|
||||||
|
scrollIntoView: true,
|
||||||
|
});
|
||||||
|
view.focus();
|
||||||
|
} else {
|
||||||
|
logger.warn(`Invalid line number ${line + 1} in ${totalLines}-line document`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error scrolling to line:', error);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,14 @@ export function Search() {
|
|||||||
|
|
||||||
const handleResultClick = (filePath: string, line?: number) => {
|
const handleResultClick = (filePath: string, line?: number) => {
|
||||||
workbenchStore.setSelectedFile(filePath);
|
workbenchStore.setSelectedFile(filePath);
|
||||||
workbenchStore.setCurrentDocumentScrollPosition({ line, column: 0 });
|
|
||||||
|
/*
|
||||||
|
* Adjust line number to be 0-based if it's defined
|
||||||
|
* The search results use 1-based line numbers, but CodeMirrorEditor expects 0-based
|
||||||
|
*/
|
||||||
|
const adjustedLine = typeof line === 'number' ? Math.max(0, line - 1) : undefined;
|
||||||
|
|
||||||
|
workbenchStore.setCurrentDocumentScrollPosition({ line: adjustedLine, column: 0 });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user