improve generate hint
This commit is contained in:
parent
2b9576c3fe
commit
dc6e5e4cbe
@ -97,4 +97,13 @@
|
|||||||
|
|
||||||
.gradient-project-card-bg > div:hover {
|
.gradient-project-card-bg > div:hover {
|
||||||
background: radial-gradient(circle at bottom right, #312e81 -75%, hsl(0 0% 3.9%) 60%); /* violet 900 -> bg */
|
background: radial-gradient(circle at bottom right, #312e81 -75%, hsl(0 0% 3.9%) 60%); /* violet 900 -> bg */
|
||||||
|
}
|
||||||
|
|
||||||
|
.inline-decoration::after {
|
||||||
|
content: 'Generate ⌘G';
|
||||||
|
color: #525252;
|
||||||
|
border: 1px solid #525252;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-left: 56px;
|
||||||
}
|
}
|
@ -44,10 +44,13 @@ export default function CodeEditor({
|
|||||||
const [activeFile, setActiveFile] = useState<string | null>(null)
|
const [activeFile, setActiveFile] = useState<string | null>(null)
|
||||||
const [tabs, setTabs] = useState<TTab[]>([])
|
const [tabs, setTabs] = useState<TTab[]>([])
|
||||||
const [activeId, setActiveId] = useState<string | null>(null)
|
const [activeId, setActiveId] = useState<string | null>(null)
|
||||||
const [terminals, setTerminals] = useState<string[]>([])
|
|
||||||
const [showGenerate, setShowGenerate] = useState(false)
|
|
||||||
const [generateId, setGenerateId] = useState<string>("")
|
|
||||||
const [cursorLine, setCursorLine] = useState(0)
|
const [cursorLine, setCursorLine] = useState(0)
|
||||||
|
const [generate, setGenerate] = useState({ show: false, id: "" })
|
||||||
|
const [decorations, setDecorations] = useState<{
|
||||||
|
options: monaco.editor.IModelDeltaDecoration[]
|
||||||
|
instance: monaco.editor.IEditorDecorationsCollection | undefined
|
||||||
|
}>({ options: [], instance: undefined })
|
||||||
|
const [terminals, setTerminals] = useState<string[]>([])
|
||||||
|
|
||||||
const clerk = useClerk()
|
const clerk = useClerk()
|
||||||
|
|
||||||
@ -70,7 +73,31 @@ export default function CodeEditor({
|
|||||||
monacoRef.current = monaco
|
monacoRef.current = monaco
|
||||||
|
|
||||||
editor.onDidChangeCursorPosition((e) => {
|
editor.onDidChangeCursorPosition((e) => {
|
||||||
setCursorLine(e.position.lineNumber)
|
const { column, lineNumber } = e.position
|
||||||
|
if (lineNumber === cursorLine) return
|
||||||
|
setCursorLine(lineNumber)
|
||||||
|
|
||||||
|
const model = editor.getModel()
|
||||||
|
const endColumn = model?.getLineContent(lineNumber).length || 0
|
||||||
|
|
||||||
|
setDecorations((prev) => {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
range: new monaco.Range(
|
||||||
|
lineNumber,
|
||||||
|
column,
|
||||||
|
lineNumber,
|
||||||
|
endColumn
|
||||||
|
),
|
||||||
|
options: {
|
||||||
|
afterContentClassName: "inline-decoration",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
editor.addAction({
|
editor.addAction({
|
||||||
@ -79,12 +106,16 @@ export default function CodeEditor({
|
|||||||
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyG],
|
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyG],
|
||||||
precondition:
|
precondition:
|
||||||
"editorTextFocus && !suggestWidgetVisible && !renameInputVisible && !inSnippetMode && !quickFixWidgetVisible",
|
"editorTextFocus && !suggestWidgetVisible && !renameInputVisible && !inSnippetMode && !quickFixWidgetVisible",
|
||||||
run: () => setShowGenerate((prev) => !prev),
|
run: () => {
|
||||||
|
setGenerate((prev) => {
|
||||||
|
return { ...prev, show: !prev.show }
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (showGenerate) {
|
if (generate.show) {
|
||||||
editorRef.current?.changeViewZones(function (changeAccessor) {
|
editorRef.current?.changeViewZones(function (changeAccessor) {
|
||||||
if (!generateRef.current) return
|
if (!generateRef.current) return
|
||||||
const id = changeAccessor.addZone({
|
const id = changeAccessor.addZone({
|
||||||
@ -92,16 +123,41 @@ export default function CodeEditor({
|
|||||||
heightInLines: 3,
|
heightInLines: 3,
|
||||||
domNode: generateRef.current,
|
domNode: generateRef.current,
|
||||||
})
|
})
|
||||||
setGenerateId(id)
|
setGenerate((prev) => {
|
||||||
|
return { ...prev, id }
|
||||||
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
editorRef.current?.changeViewZones(function (changeAccessor) {
|
editorRef.current?.changeViewZones(function (changeAccessor) {
|
||||||
if (!generateRef.current) return
|
if (!generateRef.current) return
|
||||||
changeAccessor.removeZone(generateId)
|
changeAccessor.removeZone(generate.id)
|
||||||
setGenerateId("")
|
setGenerate((prev) => {
|
||||||
|
return { ...prev, id: "" }
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [showGenerate])
|
}, [generate.show])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (decorations.options.length === 0) return
|
||||||
|
|
||||||
|
if (decorations.instance) {
|
||||||
|
console.log("setting decorations")
|
||||||
|
// decorations.instance.clear()
|
||||||
|
decorations.instance.set(decorations.options)
|
||||||
|
} else {
|
||||||
|
console.log("creating decorations")
|
||||||
|
const instance = editorRef.current?.createDecorationsCollection()
|
||||||
|
instance?.set(decorations.options)
|
||||||
|
|
||||||
|
setDecorations((prev) => {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
instance,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [decorations.options])
|
||||||
|
|
||||||
const socket = io(
|
const socket = io(
|
||||||
`http://localhost:4000?userId=${userData.id}&sandboxId=${sandboxId}`
|
`http://localhost:4000?userId=${userData.id}&sandboxId=${sandboxId}`
|
||||||
@ -241,7 +297,7 @@ export default function CodeEditor({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="bg-blue-500" ref={generateRef}>
|
<div className="bg-blue-500" ref={generateRef}>
|
||||||
{showGenerate ? "HELLO" : null}
|
{generate.show ? "HELLO" : null}
|
||||||
</div>
|
</div>
|
||||||
<Sidebar
|
<Sidebar
|
||||||
files={files}
|
files={files}
|
||||||
@ -296,7 +352,6 @@ export default function CodeEditor({
|
|||||||
) : clerk.loaded ? (
|
) : clerk.loaded ? (
|
||||||
<Editor
|
<Editor
|
||||||
height="100%"
|
height="100%"
|
||||||
// defaultLanguage="typescript"
|
|
||||||
language={editorLanguage}
|
language={editorLanguage}
|
||||||
beforeMount={handleEditorWillMount}
|
beforeMount={handleEditorWillMount}
|
||||||
onMount={handleEditorMount}
|
onMount={handleEditorMount}
|
||||||
@ -317,6 +372,7 @@ export default function CodeEditor({
|
|||||||
},
|
},
|
||||||
scrollBeyondLastLine: false,
|
scrollBeyondLastLine: false,
|
||||||
fixedOverflowWidgets: true,
|
fixedOverflowWidgets: true,
|
||||||
|
fontFamily: "var(--font-geist-mono)",
|
||||||
}}
|
}}
|
||||||
theme="vs-dark"
|
theme="vs-dark"
|
||||||
value={activeFile ?? ""}
|
value={activeFile ?? ""}
|
||||||
|
@ -20,6 +20,8 @@ export default function EditorTerminal({ socket }: { socket: Socket }) {
|
|||||||
theme: {
|
theme: {
|
||||||
background: "#262626",
|
background: "#262626",
|
||||||
},
|
},
|
||||||
|
fontFamily: "var(--font-geist-mono)",
|
||||||
|
fontSize: 14,
|
||||||
})
|
})
|
||||||
|
|
||||||
setTerm(terminal)
|
setTerm(terminal)
|
||||||
@ -71,10 +73,7 @@ export default function EditorTerminal({ socket }: { socket: Socket }) {
|
|||||||
}, [term, terminalRef.current])
|
}, [term, terminalRef.current])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div ref={terminalRef} className="w-full h-full text-left">
|
||||||
ref={terminalRef}
|
|
||||||
className="w-full font-mono text-sm h-full text-left"
|
|
||||||
>
|
|
||||||
{term === null ? (
|
{term === null ? (
|
||||||
<div className="flex items-center text-muted-foreground p-2">
|
<div className="flex items-center text-muted-foreground p-2">
|
||||||
<Loader2 className="animate-spin mr-2 h-4 w-4" />
|
<Loader2 className="animate-spin mr-2 h-4 w-4" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user