MCPcopy
hub / github.com/loggerhead/json4u / setTree

Method setTree

src/lib/editor/editor.ts:128–158  ·  view source on GitHub ↗
({ treeObject }: ParsedTree, resetCursor: boolean = true)

Source from the content-addressed store, hash-verified

126 }
127
128 setTree({ treeObject }: ParsedTree, resetCursor: boolean = true) {
129 const tree = Tree.fromObject(treeObject);
130 tree.needReset = resetCursor;
131 getEditorState().resetHighlight();
132
133 this.tree = tree;
134 getTreeState().setTree(tree, this.kind);
135
136 // replace editor text to the new tree text
137 this.editor.executeEdits(null, [
138 {
139 text: tree.text,
140 range: this.model()?.getFullModelRange() ?? {
141 startLineNumber: 1,
142 startColumn: 1,
143 endLineNumber: Infinity,
144 endColumn: Infinity,
145 },
146 },
147 ]);
148 // Indicates the above edit is a complete undo/redo change.
149 this.editor.pushUndoStop();
150
151 if (resetCursor) {
152 this.revealPosition(1, 1);
153 getStatusState().setRevealPosition(newRevealPosition(tree.version ?? 0));
154 }
155
156 console.l("set tree:", tree);
157 return tree;
158 }
159
160 /**
161 * Applies a batch of structured tree edits, typically originating from UI components like the graph view,

Callers 5

parseAndSetMethod · 0.95
parseAndFormatFunction · 0.80
useOnFileFunction · 0.80
onClickPreviewFunction · 0.80
jsonpath.test.tsFile · 0.80

Calls 7

modelMethod · 0.95
revealPositionMethod · 0.95
getEditorStateFunction · 0.90
getTreeStateFunction · 0.90
getStatusStateFunction · 0.90
newRevealPositionFunction · 0.90
fromObjectMethod · 0.80

Tested by

no test coverage detected