Skip to content

Commit bf92ee2

Browse files
committed
fix: section markers changing when scrolling list.
1 parent 1c105ce commit bf92ee2

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Website/components/datamodelview/DatamodelView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function DatamodelViewContent() {
212212
currentIndex={currentSearchIndex}
213213
totalResults={totalResults}
214214
/>
215-
<List />
215+
<List setCurrentIndex={setCurrentSearchIndex} />
216216
</div>
217217
</div>
218218
);

Website/components/datamodelview/List.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useSnackbar } from "@/contexts/SnackbarContext";
1111
import { debounce, Tooltip } from '@mui/material';
1212

1313
interface IListProps {
14+
setCurrentIndex: (index: number) => void;
1415
}
1516

1617
// Helper to highlight search matches
@@ -21,7 +22,7 @@ export function highlightMatch(text: string, search: string) {
2122
return <>{text.slice(0, idx)}<mark className="bg-yellow-200 text-black px-0.5 rounded">{text.slice(idx, idx + search.length)}</mark>{text.slice(idx + search.length)}</>;
2223
}
2324

24-
export const List = ({ }: IListProps) => {
25+
export const List = ({ setCurrentIndex }: IListProps) => {
2526
const dispatch = useDatamodelViewDispatch();
2627
const { currentSection, loading } = useDatamodelView();
2728
const { groups, filtered, search } = useDatamodelData();
@@ -124,12 +125,15 @@ export const List = ({ }: IListProps) => {
124125
let mostVisibleEntity: {
125126
entity: EntityType;
126127
group: GroupType;
128+
index: number;
127129
visibleArea: number;
128130
} | null = null;
129131

132+
let actualIndex = 0;
130133
for (const vi of virtualItems) {
131134
const item = flatItems[vi.index];
132135
if (!item || item.type !== 'entity') continue;
136+
actualIndex++;
133137

134138
const itemTop = vi.start;
135139
const itemBottom = vi.end;
@@ -148,6 +152,7 @@ export const List = ({ }: IListProps) => {
148152
mostVisibleEntity = {
149153
entity: item.entity,
150154
group: item.group,
155+
index: actualIndex,
151156
visibleArea
152157
};
153158
}
@@ -158,6 +163,7 @@ export const List = ({ }: IListProps) => {
158163
updateURL({ query: { group: mostVisibleEntity.group.Name, section: mostVisibleEntity.entity.SchemaName } });
159164
dispatch({ type: "SET_CURRENT_GROUP", payload: mostVisibleEntity.group.Name });
160165
dispatch({ type: "SET_CURRENT_SECTION", payload: mostVisibleEntity.entity.SchemaName });
166+
setCurrentIndex(mostVisibleEntity.index);
161167
}
162168
}, 100);
163169

0 commit comments

Comments
 (0)