Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 committed Feb 3, 2025
1 parent 0876551 commit e758f7a
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions app/components/EditorComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Button from "./ui/Button";
interface Props {
currentQuery: string
historyQueries: string[]
setHistoryQueries: (queries: string[]) => void
setCurrentQuery: (query: string) => void
maximize: boolean
runQuery: (query: string) => void
Expand Down Expand Up @@ -199,7 +200,7 @@ const LINE_HEIGHT = 38

const PLACEHOLDER = "Type your query here to start"

export default function EditorComponent({ currentQuery, historyQueries, setCurrentQuery, maximize, runQuery, graph, data }: Props) {
export default function EditorComponent({ currentQuery, historyQueries, setHistoryQueries, setCurrentQuery, maximize, runQuery, graph, data }: Props) {

const [query, setQuery] = useState(currentQuery)
const placeholderRef = useRef<HTMLDivElement>(null)
Expand All @@ -214,7 +215,7 @@ export default function EditorComponent({ currentQuery, historyQueries, setCurre
const historyRef = useRef({
historyQueries,
currentQuery,
historyCounter: historyQueries.length
historyCounter: 0
})

useEffect(() => {
Expand Down Expand Up @@ -498,9 +499,9 @@ export default function EditorComponent({ currentQuery, historyQueries, setCurre
contextMenuOrder: 1.5,
run: async () => {
if (historyRef.current.historyQueries.length === 0) return
const counter = historyRef.current.historyCounter ? historyRef.current.historyCounter - 1 : historyRef.current.historyQueries.length;
historyRef.current.historyCounter = counter;
setQuery(counter ? historyRef.current.historyQueries[counter - 1] : historyRef.current.currentQuery);
const counter = (historyRef.current.historyCounter + 1) % (historyRef.current.historyQueries.length + 1)
historyRef.current.historyCounter = counter
setQuery(counter ? historyRef.current.historyQueries[counter - 1] : historyRef.current.currentQuery)
},
precondition: 'isFirstLine && !suggestWidgetVisible',
});
Expand All @@ -512,14 +513,24 @@ export default function EditorComponent({ currentQuery, historyQueries, setCurre
contextMenuOrder: 1.5,
run: async () => {
if (historyRef.current.historyQueries.length === 0) return
const counter = (historyRef.current.historyCounter + 1) % (historyRef.current.historyQueries.length + 1)
historyRef.current.historyCounter = counter
setQuery(counter ? historyRef.current.historyQueries[counter - 1] : historyRef.current.currentQuery)
const counter = historyRef.current.historyCounter ? historyRef.current.historyCounter - 1 : historyRef.current.historyQueries.length;
historyRef.current.historyCounter = counter;
setQuery(counter ? historyRef.current.historyQueries[counter - 1] : historyRef.current.currentQuery);
},
precondition: 'isFirstLine && !suggestWidgetVisible',
});
}

const handleSetHistoryQuery = (val: string) => {
setQuery(val)
historyRef.current.historyQueries[historyRef.current.historyCounter - 1] = val
setHistoryQueries(historyRef.current.historyQueries)
}

useEffect(() => {
setLineNumber(query.split("\n").length)
}, [query])

return (
<div>
{
Expand All @@ -544,14 +555,7 @@ export default function EditorComponent({ currentQuery, historyQueries, setCurre
lineNumbers: lineNumber > 1 ? "on" : "off",
}}
value={(blur ? query.replace(/\s+/g, ' ').trim() : query)}
onChange={(val) => {
if (historyRef.current.historyCounter) {
setQuery(val || "");
} else {
setCurrentQuery(val || "");
}
setLineNumber(val?.split("\n").length || 1);
}}
onChange={(val) => historyRef.current.historyCounter ? handleSetHistoryQuery(val || "") : setCurrentQuery(val || "")}
theme="custom-theme"
beforeMount={handleEditorWillMount}
onMount={handleEditorDidMount}
Expand Down

0 comments on commit e758f7a

Please sign in to comment.