@fc-components/monaco-editor 0.1.11 → 0.1.12

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.
@@ -12,7 +12,7 @@ interface PromQLEditorProps {
12
12
  disabled?: boolean;
13
13
  interpolateString?: (query: string) => string;
14
14
  onChange?: (value: string) => void;
15
- onShiftEnter?: (value: string) => void;
15
+ onEnter?: (value: string) => void;
16
16
  onBlur?: (value: string) => void;
17
17
  editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
18
18
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.11",
6
+ "version": "0.1.12",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/monaco-editor.esm.js",
@@ -24,7 +24,7 @@ interface PromQLEditorProps {
24
24
  disabled?: boolean;
25
25
  interpolateString?: (query: string) => string;
26
26
  onChange?: (value: string) => void;
27
- onShiftEnter?: (value: string) => void;
27
+ onEnter?: (value: string) => void;
28
28
  onBlur?: (value: string) => void;
29
29
  editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
30
30
  }
@@ -95,7 +95,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
95
95
  readOnly = false,
96
96
  disabled = false,
97
97
  onChange,
98
- onShiftEnter,
98
+ onEnter,
99
99
  onBlur,
100
100
  editorDidMount,
101
101
  } = props;
@@ -165,15 +165,45 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
165
165
  command: null,
166
166
  });
167
167
 
168
- // handle: shift + enter
168
+ // 设置 Shift + Enter 为在光标位置换行
169
169
  editor.addCommand(
170
170
  monaco.KeyMod.Shift | monaco.KeyCode.Enter,
171
171
  () => {
172
- onShiftEnter?.(editor.getValue());
172
+ // 在光标位置插入换行符
173
+ const position = editor.getPosition();
174
+ if (position) {
175
+ editor.executeEdits('shift-enter', [
176
+ {
177
+ range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
178
+ text: '\n',
179
+ },
180
+ ]);
181
+ // 将光标移动到新行
182
+ editor.setPosition({
183
+ lineNumber: position.lineNumber + 1,
184
+ column: 1,
185
+ });
186
+ }
173
187
  },
174
188
  'isEditorFocused' + id,
175
189
  );
176
190
 
191
+ // 完全阻止 Enter 键的默认行为(包括换行)
192
+ monaco.editor.addKeybindingRule({
193
+ keybinding: monaco.KeyCode.Enter,
194
+ command: '-',
195
+ when: '!suggestWidgetVisible',
196
+ });
197
+
198
+ // handle: enter - 只有在没有建议窗口时才执行自定义行为
199
+ editor.addCommand(
200
+ monaco.KeyCode.Enter,
201
+ () => {
202
+ onEnter?.(editor.getValue());
203
+ },
204
+ '!suggestWidgetVisible && isEditorFocused' + id,
205
+ );
206
+
177
207
  editor.onDidChangeModelContent(() => {
178
208
  const model = editor.getModel();
179
209
  if (model) {