mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-27 08:48:46 +00:00
Implement undo and redo
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import type { DocAndNode } from '@spyglassmc/core'
|
||||
import { JsonFileNode } from '@spyglassmc/json'
|
||||
import { useErrorBoundary } from 'preact/hooks'
|
||||
import { useLocale } from '../../contexts/index.js'
|
||||
import { useDocAndNode } from '../../contexts/Spyglass.jsx'
|
||||
import { useCallback, useErrorBoundary } from 'preact/hooks'
|
||||
import { useLocale, useVersion } from '../../contexts/index.js'
|
||||
import { useDocAndNode, useSpyglass } from '../../contexts/Spyglass.jsx'
|
||||
import type { Edit } from '../../services/Spyglass.js'
|
||||
import { McdocRoot } from './McdocRenderer.jsx'
|
||||
|
||||
type TreePanelProps = {
|
||||
@@ -11,6 +12,9 @@ type TreePanelProps = {
|
||||
}
|
||||
export function Tree({ docAndNode, onError }: TreePanelProps) {
|
||||
const { lang } = useLocale()
|
||||
const { version } = useVersion()
|
||||
const { spyglass } = useSpyglass()
|
||||
|
||||
if (lang === 'none') return <></>
|
||||
|
||||
const fileChild = useDocAndNode(docAndNode).node.children[0]
|
||||
@@ -24,7 +28,11 @@ export function Tree({ docAndNode, onError }: TreePanelProps) {
|
||||
})
|
||||
if (error) return <></>
|
||||
|
||||
const makeEdits = useCallback((edits: Edit[]) => {
|
||||
spyglass.applyEdits(version, docAndNode.doc.uri, edits)
|
||||
}, [spyglass, version, docAndNode])
|
||||
|
||||
return <div class="tree node-root" data-cy="tree">
|
||||
<McdocRoot node={fileChild.children[0]} />
|
||||
<McdocRoot node={fileChild.children[0]} makeEdits={makeEdits} />
|
||||
</div>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user