Only re-parse the ast when value changes.
This commit is contained in:
parent
8627181480
commit
cc48040f11
@ -1,4 +1,4 @@
|
||||
import React, { ReactNode, useState } from "react";
|
||||
import React, { ReactNode, useMemo, useState } from "react";
|
||||
import "./Editor.css";
|
||||
import { Highlight } from "./highlight";
|
||||
import { buildShadow } from "./shadow";
|
||||
@ -31,6 +31,12 @@ function Editor({ defaultValue = default_org_source }) {
|
||||
|
||||
const [highlights, setHighlights] = useState<Array<Highlight>>([]);
|
||||
|
||||
const astTree = useMemo(() => {
|
||||
const astTree = parse_org(value);
|
||||
console.log(JSON.stringify(astTree));
|
||||
return astTree;
|
||||
}, [value]);
|
||||
|
||||
function setHighlight(nodes: OrgNodeReference[]) {
|
||||
let new_highlights = nodes.map((node: OrgNodeReference) => {
|
||||
return new Highlight(node.start - 1, node.end - 1);
|
||||
@ -57,9 +63,6 @@ function Editor({ defaultValue = default_org_source }) {
|
||||
setHighlights([]);
|
||||
}
|
||||
|
||||
const astTree = parse_org(value);
|
||||
console.log(JSON.stringify(astTree));
|
||||
|
||||
return (
|
||||
<div className="Editor">
|
||||
<div className="Editor-textwrapper">
|
||||
|
Loading…
Reference in New Issue
Block a user