Skip to content

Commit 5224dea

Browse files
authored
Merge pull request #1676 from xKevIsDev/improvements
feat: implement a search functionality to search codebase
2 parents 9d5c66c + d6a4aff commit 5224dea

File tree

6 files changed

+349
-25
lines changed

6 files changed

+349
-25
lines changed

.github/workflows/electron.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
strategy:
2323
matrix:
24-
os: [ubuntu-latest, windows-latest] # TODO: add back macos-latest when notarize is figured out
24+
os: [ubuntu-latest, windows-latest, macos-latest] # Use unsigned macOS builds for now
2525
node-version: [18.18.0]
2626
fail-fast: false
2727

app/components/editor/codemirror/CodeMirrorEditor.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ type TextEditorDocument = EditorDocument & {
4747
};
4848

4949
export interface ScrollPosition {
50-
top: number;
51-
left: number;
50+
top?: number;
51+
left?: number;
52+
line?: number;
53+
column?: number;
5254
}
5355

5456
export interface EditorUpdate {
@@ -159,6 +161,25 @@ export const CodeMirrorEditor = memo(
159161
themeRef.current = theme;
160162
});
161163

164+
useEffect(() => {
165+
if (!viewRef.current || !doc || doc.isBinary) {
166+
return;
167+
}
168+
169+
if (typeof doc.scroll?.line === 'number') {
170+
const line = doc.scroll.line;
171+
const column = doc.scroll.column ?? 0;
172+
const linePos = viewRef.current.state.doc.line(line + 1).from + column;
173+
viewRef.current.dispatch({
174+
selection: { anchor: linePos },
175+
scrollIntoView: true,
176+
});
177+
viewRef.current.focus();
178+
} else if (typeof doc.scroll?.top === 'number' || typeof doc.scroll?.left === 'number') {
179+
viewRef.current.scrollDOM.scrollTo(doc.scroll.left ?? 0, doc.scroll.top ?? 0);
180+
}
181+
}, [doc?.scroll?.line, doc?.scroll?.column, doc?.scroll?.top, doc?.scroll?.left]);
182+
162183
useEffect(() => {
163184
const onUpdate = debounce((update: EditorUpdate) => {
164185
onChangeRef.current?.(update);
@@ -417,11 +438,23 @@ function setEditorDocument(
417438
const newLeft = doc.scroll?.left ?? 0;
418439
const newTop = doc.scroll?.top ?? 0;
419440

441+
if (typeof doc.scroll?.line === 'number') {
442+
const line = doc.scroll.line;
443+
const column = doc.scroll.column ?? 0;
444+
const linePos = view.state.doc.line(line + 1).from + column;
445+
view.dispatch({
446+
selection: { anchor: linePos },
447+
scrollIntoView: true,
448+
});
449+
view.focus();
450+
451+
return;
452+
}
453+
420454
const needsScrolling = currentLeft !== newLeft || currentTop !== newTop;
421455

422456
if (autoFocus && editable) {
423457
if (needsScrolling) {
424-
// we have to wait until the scroll position was changed before we can set the focus
425458
view.scrollDOM.addEventListener(
426459
'scroll',
427460
() => {
@@ -430,7 +463,6 @@ function setEditorDocument(
430463
{ once: true },
431464
);
432465
} else {
433-
// if the scroll position is still the same we can focus immediately
434466
view.focus();
435467
}
436468
}

app/components/workbench/EditorPanel.tsx

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useStore } from '@nanostores/react';
22
import { memo, useMemo } from 'react';
33
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
4+
import * as Tabs from '@radix-ui/react-tabs'; // <-- Import Radix UI Tabs
45
import {
56
CodeMirrorEditor,
67
type EditorDocument,
@@ -21,6 +22,8 @@ import { FileBreadcrumb } from './FileBreadcrumb';
2122
import { FileTree } from './FileTree';
2223
import { DEFAULT_TERMINAL_SIZE, TerminalTabs } from './terminal/TerminalTabs';
2324
import { workbenchStore } from '~/lib/stores/workbench';
25+
import { Search } from './Search'; // <-- Ensure Search is imported
26+
import { classNames } from '~/utils/classNames'; // <-- Import classNames if not already present
2427

2528
interface EditorPanelProps {
2629
files?: FileMap;
@@ -75,24 +78,48 @@ export const EditorPanel = memo(
7578
<PanelGroup direction="vertical">
7679
<Panel defaultSize={showTerminal ? DEFAULT_EDITOR_SIZE : 100} minSize={20}>
7780
<PanelGroup direction="horizontal">
78-
<Panel defaultSize={20} minSize={10} collapsible>
79-
<div className="flex flex-col border-r border-bolt-elements-borderColor h-full">
80-
<PanelHeader>
81-
<div className="i-ph:tree-structure-duotone shrink-0" />
82-
Files
81+
<Panel defaultSize={20} minSize={15} collapsible className="border-r border-bolt-elements-borderColor">
82+
<Tabs.Root defaultValue="files" className="flex flex-col h-full">
83+
<PanelHeader className="w-full text-sm font-medium text-bolt-elements-textSecondary px-1">
84+
<Tabs.List className="h-full flex-shrink-0 flex items-center">
85+
<Tabs.Trigger
86+
value="files"
87+
className={classNames(
88+
'h-full bg-transparent hover:bg-bolt-elements-background-depth-3 py-0.5 px-2 rounded-lg text-sm font-medium text-bolt-elements-textTertiary hover:text-bolt-elements-textPrimary data-[state=active]:text-bolt-elements-textPrimary',
89+
)}
90+
>
91+
Files
92+
</Tabs.Trigger>
93+
<Tabs.Trigger
94+
value="search"
95+
className={classNames(
96+
'h-full bg-transparent hover:bg-bolt-elements-background-depth-3 py-0.5 px-2 rounded-lg text-sm font-medium text-bolt-elements-textTertiary hover:text-bolt-elements-textPrimary data-[state=active]:text-bolt-elements-textPrimary',
97+
)}
98+
>
99+
Search
100+
</Tabs.Trigger>
101+
</Tabs.List>
83102
</PanelHeader>
84-
<FileTree
85-
className="h-full"
86-
files={files}
87-
hideRoot
88-
unsavedFiles={unsavedFiles}
89-
fileHistory={fileHistory}
90-
rootFolder={WORK_DIR}
91-
selectedFile={selectedFile}
92-
onFileSelect={onFileSelect}
93-
/>
94-
</div>
103+
104+
<Tabs.Content value="files" className="flex-grow overflow-auto focus-visible:outline-none">
105+
<FileTree
106+
className="h-full"
107+
files={files}
108+
hideRoot
109+
unsavedFiles={unsavedFiles}
110+
fileHistory={fileHistory}
111+
rootFolder={WORK_DIR}
112+
selectedFile={selectedFile}
113+
onFileSelect={onFileSelect}
114+
/>
115+
</Tabs.Content>
116+
117+
<Tabs.Content value="search" className="flex-grow overflow-auto focus-visible:outline-none">
118+
<Search />
119+
</Tabs.Content>
120+
</Tabs.Root>
95121
</Panel>
122+
96123
<PanelResizeHandle />
97124
<Panel className="flex flex-col" defaultSize={80} minSize={20}>
98125
<PanelHeader className="overflow-x-auto">

0 commit comments

Comments
 (0)