@fc-components/monaco-editor 0.1.11 → 0.1.13

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/README.md CHANGED
@@ -40,8 +40,8 @@ const App = () => {
40
40
  // Interpolate variables in the query string
41
41
  return query.replace(/\$__interval/g, '10s');
42
42
  }}
43
- onShiftEnter={(value) => {
44
- console.log('Shift+Enter pressed, current value:', value);
43
+ onEnter={(value) => {
44
+ console.log('Enter pressed, current value:', value);
45
45
  }}
46
46
  onBlur={(value) => {
47
47
  console.log('Editor lost focus, current value:', value);
@@ -2012,7 +2012,7 @@ function PromQLEditor(props) {
2012
2012
  _props$disabled = props.disabled,
2013
2013
  disabled = _props$disabled === void 0 ? false : _props$disabled,
2014
2014
  onChange = props.onChange,
2015
- onShiftEnter = props.onShiftEnter,
2015
+ onEnter = props.onEnter,
2016
2016
  onBlur = props.onBlur,
2017
2017
  editorDidMount = props.editorDidMount;
2018
2018
  var autocompleteDisposeFun = React.useRef(null);
@@ -2076,10 +2076,32 @@ function PromQLEditor(props) {
2076
2076
  keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyF,
2077
2077
  command: null
2078
2078
  });
2079
- // handle: shift + enter
2079
+ // 设置 Shift + Enter 为在光标位置换行
2080
2080
  editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, function () {
2081
- onShiftEnter == null || onShiftEnter(editor.getValue());
2081
+ // 在光标位置插入换行符
2082
+ var position = editor.getPosition();
2083
+ if (position) {
2084
+ editor.executeEdits('shift-enter', [{
2085
+ range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
2086
+ text: '\n'
2087
+ }]);
2088
+ // 将光标移动到新行
2089
+ editor.setPosition({
2090
+ lineNumber: position.lineNumber + 1,
2091
+ column: 1
2092
+ });
2093
+ }
2082
2094
  }, 'isEditorFocused' + id);
2095
+ // 完全阻止 Enter 键的默认行为(包括换行)
2096
+ monaco.editor.addKeybindingRule({
2097
+ keybinding: monaco.KeyCode.Enter,
2098
+ command: '-',
2099
+ when: '!suggestWidgetVisible'
2100
+ });
2101
+ // handle: enter - 只有在没有建议窗口时才执行自定义行为
2102
+ editor.addCommand(monaco.KeyCode.Enter, function () {
2103
+ onEnter == null || onEnter(editor.getValue());
2104
+ }, '!suggestWidgetVisible && isEditorFocused' + id);
2083
2105
  editor.onDidChangeModelContent(function () {
2084
2106
  var model = editor.getModel();
2085
2107
  if (model) {
@@ -2225,7 +2247,11 @@ function PromQLEditor(props) {
2225
2247
  },
2226
2248
  scrollBeyondLastLine: false,
2227
2249
  suggest: {
2228
- showWords: false
2250
+ showWords: false,
2251
+ // 防止补全层自动关闭的关键配置
2252
+ filterGraceful: false,
2253
+ snippetsPreventQuickSuggestions: false,
2254
+ shareSuggestSelections: false
2229
2255
  },
2230
2256
  suggestFontSize: 12,
2231
2257
  wordWrap: 'on',