Skip to content

Commit ab81d1b

Browse files
silinchenJackLian
authored andcommitted
fix(plugin-code-editor): add function out of class
1 parent 52244df commit ab81d1b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • packages/plugin-code-editor/src/components/JSEditor

packages/plugin-code-editor/src/components/JSEditor/JsEditor.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ export class JsEditor extends PureComponent<JsEditorProps, JsEditorState> {
178178
if (!monacoEditor || !monaco) {
179179
return;
180180
}
181-
const count = monacoEditor.getModel()?.getLineCount() ?? 0;
182-
const range = new monaco.Range(count, 1, count, 1);
181+
182+
// 找到最后一个 },在他前面插入新的 function 字符串
183+
const matches = monacoEditor.getModel()?.findMatches('}');
184+
let range = {}
185+
if(matches && matches.length > 0) {
186+
const { startLineNumber, startColumn } = matches[matches.length - 1]?.range || {}
187+
range = new monaco.Range(startLineNumber, startColumn, startLineNumber, startColumn);
188+
}
183189

184190
const functionCode = params.template ?
185191
params.template :

0 commit comments

Comments
 (0)