st-comp 0.0.185 → 0.0.186

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.185",
4
+ "version": "0.0.186",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -94,7 +94,7 @@ const handleSubmit = async () => {
94
94
  // 自定义函数: 插入
95
95
  const handleInsert = () => {
96
96
  if (!customFunctionName.value) return ElMessage.error("请先选择自定义函数后, 再执行插入");
97
- emit("insert", ` ${customFunctionName.value}`);
97
+ emit("insert", customFunctionName.value);
98
98
  };
99
99
 
100
100
  // 变量选择器: 打开
@@ -70,13 +70,32 @@ const handleInsetVarContent = (configList) => {
70
70
 
71
71
  const currentValue = editorRef.value.getValue();
72
72
  const lines = currentValue.split("\n");
73
+
73
74
  // 如果光标位置有效
74
75
  if (position.lineNumber <= lines.length) {
75
76
  const lineIndex = position.lineNumber - 1;
76
77
  const line = lines[lineIndex];
78
+ const columnIndex = position.column - 1;
79
+
80
+ // 获取光标前后的字符
81
+ const prevChar = columnIndex > 0 ? line[columnIndex - 1] : "";
82
+ const nextChar = columnIndex < line.length ? line[columnIndex] : "";
83
+
84
+ // 检测是否需要添加空格
85
+ let contentToInsert = content;
86
+
87
+ // 如果前面有内容且不是空格或行首,在前面添加空格
88
+ if (prevChar && prevChar !== " " && !/[\s({[ ]/.test(prevChar)) {
89
+ contentToInsert = " " + contentToInsert;
90
+ }
91
+
92
+ // 如果后面有内容且不是空格或行尾,在后面添加空格
93
+ if (nextChar && nextChar !== " " && !/[\s)}\]]/.test(nextChar)) {
94
+ contentToInsert = contentToInsert + " ";
95
+ }
77
96
 
78
97
  // 在光标位置插入内容
79
- const newLine = line.substring(0, position.column - 1) + content + line.substring(position.column - 1);
98
+ const newLine = line.substring(0, columnIndex) + contentToInsert + line.substring(columnIndex);
80
99
  lines[lineIndex] = newLine;
81
100
 
82
101
  // 更新编辑器内容
@@ -84,7 +103,7 @@ const handleInsetVarContent = (configList) => {
84
103
  editorRef.value.setValue(newValue);
85
104
 
86
105
  // 将光标移动到插入内容之后
87
- const newColumn = position.column + content.length;
106
+ const newColumn = position.column + contentToInsert.length;
88
107
  editorIns.setPosition({
89
108
  lineNumber: position.lineNumber,
90
109
  column: newColumn,
@@ -248,18 +248,38 @@ const open = () => {
248
248
  // 插入自定义函数
249
249
  const handleInsertCustomFunction = (value) => {
250
250
  if (!monacoEditorRef.value) return ElMessage.error("未检测到编辑器实例");
251
+
251
252
  const content = value;
252
253
  const editorIns = monacoEditorRef.value.getInstance();
253
254
  const position = editorIns.getPosition();
254
255
  const currentValue = monacoEditorRef.value.getValue();
255
256
  const lines = currentValue.split("\n");
257
+
256
258
  // 如果光标位置有效
257
259
  if (position.lineNumber <= lines.length) {
258
260
  const lineIndex = position.lineNumber - 1;
259
261
  const line = lines[lineIndex];
262
+ const columnIndex = position.column - 1;
263
+
264
+ // 获取光标前后的字符
265
+ const prevChar = columnIndex > 0 ? line[columnIndex - 1] : "";
266
+ const nextChar = columnIndex < line.length ? line[columnIndex] : "";
267
+
268
+ // 检测是否需要添加空格
269
+ let contentToInsert = content;
270
+
271
+ // 如果前面有内容且不是空格或行首,在前面添加空格
272
+ if (prevChar && prevChar !== " " && !/[\s({[ ]/.test(prevChar)) {
273
+ contentToInsert = " " + contentToInsert;
274
+ }
275
+
276
+ // 如果后面有内容且不是空格或行尾,在后面添加空格
277
+ if (nextChar && nextChar !== " " && !/[\s)}\]]/.test(nextChar)) {
278
+ contentToInsert = contentToInsert + " ";
279
+ }
260
280
 
261
281
  // 在光标位置插入内容
262
- const newLine = line.substring(0, position.column - 1) + content + line.substring(position.column - 1);
282
+ const newLine = line.substring(0, columnIndex) + contentToInsert + line.substring(columnIndex);
263
283
  lines[lineIndex] = newLine;
264
284
 
265
285
  // 更新编辑器内容
@@ -267,7 +287,7 @@ const handleInsertCustomFunction = (value) => {
267
287
  monacoEditorRef.value.setValue(newValue);
268
288
 
269
289
  // 将光标移动到插入内容之后
270
- const newColumn = position.column + content.length;
290
+ const newColumn = position.column + contentToInsert.length;
271
291
  editorIns.setPosition({
272
292
  lineNumber: position.lineNumber,
273
293
  column: newColumn,