🐛 fix(monaco-editor): 禁用 EditContext 修复中文输入异常

- 在 MonacoEditor 中统一关闭 editContext
- 修复单引号场景下中文输入首次上屏异常
- 补充编辑器选项回归断言

Close #578
This commit is contained in:
Syngnat
2026-06-20 17:05:38 +08:00
parent b3a54b3ff8
commit 7f2445a6f5
2 changed files with 7 additions and 1 deletions

View File

@@ -113,7 +113,10 @@ const MonacoEditor: React.FC<MonacoEditorProps> = ({
const resolvedOptions = useMemo(() => {
if (uiVersion !== 'v2') {
return options;
return {
...options,
editContext: false,
};
}
const effectiveGlobalFontSize = Math.min(
@@ -129,6 +132,7 @@ const MonacoEditor: React.FC<MonacoEditorProps> = ({
return {
...options,
editContext: false,
fontFamily: options?.fontFamily ?? monoFontFamily ?? DEFAULT_MONO_FONT_FAMILY,
fontSize: options?.fontSize ?? resolvedFontSize,
lineHeight: options?.lineHeight ?? Math.max(18, Math.round(resolvedFontSize * 1.62)),

View File

@@ -57,6 +57,7 @@ describe('MonacoEditor typography', () => {
<MonacoEditor options={{ minimap: { enabled: false } }} />,
);
expect(markup).toContain('&quot;editContext&quot;:false');
expect(markup).toContain('JetBrains Mono');
expect(markup).toContain('ui-monospace');
expect(markup).toContain('&quot;fontSize&quot;:13');
@@ -83,6 +84,7 @@ describe('MonacoEditor typography', () => {
<MonacoEditor options={{ fontFamily: 'Consolas', fontSize: 18 }} />,
);
expect(markup).toContain('&quot;editContext&quot;:false');
expect(markup).toContain('&quot;fontFamily&quot;:&quot;Consolas&quot;');
expect(markup).toContain('&quot;fontSize&quot;:18');
expect(markup).not.toContain('JetBrains Mono');