|
@@ -99,13 +99,13 @@ export function Code(props: Props) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const onSelectionChange = () => {
|
|
|
|
|
|
|
+ const onSelectionChange = async () => {
|
|
|
if (!container) return
|
|
if (!container) return
|
|
|
if (isProgrammaticSelection) return
|
|
if (isProgrammaticSelection) return
|
|
|
// if (ctx.file.active()?.path !== local.path) return
|
|
// if (ctx.file.active()?.path !== local.path) return
|
|
|
const d = getSelectionInContainer(container)
|
|
const d = getSelectionInContainer(container)
|
|
|
if (!d) return
|
|
if (!d) return
|
|
|
- const p = ctx.file.node(local.path)?.selection
|
|
|
|
|
|
|
+ const p = (await ctx.file.node(local.path))?.selection
|
|
|
if (p && p.startLine === d.sl && p.endLine === d.el && p.startChar === d.sch && p.endChar === d.ech) return
|
|
if (p && p.startLine === d.sl && p.endLine === d.el && p.startChar === d.sch && p.endChar === d.ech) return
|
|
|
ctx.file.select(local.path, { startLine: d.sl, startChar: d.sch, endLine: d.el, endChar: d.ech })
|
|
ctx.file.select(local.path, { startLine: d.sl, startChar: d.sch, endLine: d.el, endChar: d.ech })
|
|
|
}
|
|
}
|
|
@@ -144,21 +144,21 @@ export function Code(props: Props) {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// Restore scroll position from store when content is ready
|
|
// Restore scroll position from store when content is ready
|
|
|
- createEffect(() => {
|
|
|
|
|
|
|
+ createEffect(async () => {
|
|
|
const content = html()
|
|
const content = html()
|
|
|
if (!container || !content) return
|
|
if (!container || !content) return
|
|
|
- const top = ctx.file.node(local.path)?.scrollTop
|
|
|
|
|
|
|
+ const top = (await ctx.file.node(local.path))?.scrollTop
|
|
|
if (top !== undefined && container.scrollTop !== top) container.scrollTop = top
|
|
if (top !== undefined && container.scrollTop !== top) container.scrollTop = top
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// Sync selection from store -> DOM
|
|
// Sync selection from store -> DOM
|
|
|
- createEffect(() => {
|
|
|
|
|
|
|
+ createEffect(async () => {
|
|
|
const content = html()
|
|
const content = html()
|
|
|
if (!container || !content) return
|
|
if (!container || !content) return
|
|
|
// if (ctx.file.active()?.path !== local.path) return
|
|
// if (ctx.file.active()?.path !== local.path) return
|
|
|
const codeEl = container.querySelector("code") as HTMLElement | undefined
|
|
const codeEl = container.querySelector("code") as HTMLElement | undefined
|
|
|
if (!codeEl) return
|
|
if (!codeEl) return
|
|
|
- const target = ctx.file.node(local.path)?.selection
|
|
|
|
|
|
|
+ const target = (await ctx.file.node(local.path))?.selection
|
|
|
const current = getSelectionInContainer(container)
|
|
const current = getSelectionInContainer(container)
|
|
|
const sel = window.getSelection()
|
|
const sel = window.getSelection()
|
|
|
if (!sel) return
|
|
if (!sel) return
|