Skip to content

Commit

Permalink
refactor(frontend): smoother search panel resizing
Browse files Browse the repository at this point in the history
Install the resize detector to the whole editor are so that the search panel
knows its weight as soon as it is installed.
  • Loading branch information
kris7t committed Nov 23, 2024
1 parent 78f0407 commit c99595e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions subprojects/frontend/src/editor/EditorPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Stack from '@mui/material/Stack';
import Toolbar from '@mui/material/Toolbar';
import { observer } from 'mobx-react-lite';
import { useState } from 'react';
import { useResizeDetector } from 'react-resize-detector';

import { useRootStore } from '../RootStoreProvider';

Expand Down Expand Up @@ -38,9 +39,10 @@ function EditorLoading(): JSX.Element {

export default observer(function EditorPane(): JSX.Element {
const { editorStore } = useRootStore();
const { width, ref } = useResizeDetector();

return (
<Stack direction="column" height="100%" overflow="auto">
<Stack direction="column" height="100%" overflow="auto" ref={ref}>
<Toolbar
variant="dense"
sx={{
Expand All @@ -62,7 +64,7 @@ export default observer(function EditorPane(): JSX.Element {
<>
<AnalysisErrorNotification editorStore={editorStore} />
<ConnectionStatusNotification editorStore={editorStore} />
<SearchPanelPortal editorStore={editorStore} />
<SearchPanelPortal editorStore={editorStore} width={width} />
<EditorArea editorStore={editorStore} />
</>
)}
Expand Down
4 changes: 3 additions & 1 deletion subprojects/frontend/src/editor/SearchPanelPortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import SearchToolbar from './SearchToolbar';

export default observer(function SearchPanelPortal({
editorStore: { searchPanel: searchPanelStore },
width,
}: {
editorStore: EditorStore;
width: number | undefined;
}): JSX.Element | null {
const { element: searchPanelContainer } = searchPanelStore;

Expand All @@ -22,7 +24,7 @@ export default observer(function SearchPanelPortal({
}
return (
<Portal container={searchPanelContainer}>
<SearchToolbar searchPanelStore={searchPanelStore} />
<SearchToolbar searchPanelStore={searchPanelStore} width={width} />
</Portal>
);
});
5 changes: 2 additions & 3 deletions subprojects/frontend/src/editor/SearchToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Toolbar from '@mui/material/Toolbar';
import { styled } from '@mui/material/styles';
import { observer } from 'mobx-react-lite';
import { useCallback, useState } from 'react';
import { useResizeDetector } from 'react-resize-detector';

import Tooltip from '../Tooltip';

Expand All @@ -36,15 +35,16 @@ const DimLabel = styled(FormControlLabel)(({ theme }) => ({

export default observer(function SearchToolbar({
searchPanelStore,
width,
}: {
searchPanelStore: SearchPanelStore;
width: number | undefined;
}): JSX.Element {
const {
id: panelId,
query: { search, valid, caseSensitive, literal, regexp, replace },
invalidRegexp,
} = searchPanelStore;
const { width, ref } = useResizeDetector();
const split = width !== undefined && width <= 1200;
const [showRepalceState, setShowReplaceState] = useState(false);

Expand All @@ -68,7 +68,6 @@ export default observer(function SearchToolbar({
alignItems: 'center',
minHeight: 'auto',
}}
ref={ref}
>
<Stack
direction={split ? 'column' : 'row'}
Expand Down

0 comments on commit c99595e

Please sign in to comment.