Skip to content

Commit 755aad7

Browse files
committed
fix: update cursor after rendering
close #58
1 parent 6e04245 commit 755aad7

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default defineConfig([
4141
plugins: definePlugins({
4242
replaceValues,
4343
}),
44-
external: ['markmap-common', 'markmap-toolbar', 'markmap-view'],
44+
external: ['markmap-toolbar', 'markmap-view'],
4545
output: {
4646
format: 'iife',
4747
dir: 'dist',

src/app.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { INode } from 'markmap-common';
1+
import { IDeferred, defer, type INode } from 'markmap-common';
22
import { Toolbar } from 'markmap-toolbar';
33
import {
44
defaultOptions,
@@ -22,6 +22,7 @@ let active:
2222
const activeNodeOptions: {
2323
placement?: 'center' | 'visible';
2424
} = {};
25+
let loading: IDeferred<void> | undefined;
2526

2627
const handlers = {
2728
async setData(data: {
@@ -32,17 +33,20 @@ const handlers = {
3233
};
3334
};
3435
}) {
36+
loading = defer();
3537
await mm.setData((root = data.root), {
3638
...defaultOptions,
3739
...deriveOptions(data.jsonOptions),
3840
});
3941
activeNodeOptions.placement = data.jsonOptions?.activeNode?.placement;
4042
if (firstTime) {
41-
mm.fit();
43+
await mm.fit();
4244
firstTime = false;
4345
}
46+
loading.resolve();
4447
},
4548
async setCursor(options: { line: number; autoExpand?: boolean }) {
49+
await loading?.promise;
4650
const result = root && findActiveNode(options);
4751
if (!result) return;
4852
const { node, needRerender } = result;

0 commit comments

Comments
 (0)