🐛 fix(query-editor): 修复大字号表候选下划线裁剪 (#829)

## 背景

SQL 查询编辑器的表候选项使用 Monaco 原生双行布局,行高固定为 18px + 18px。

当编辑器字号调整为 18px 或 20px 时,表名中的下划线和字母下行部分可能被候选项行高裁剪。

## 变更内容

- 新增 SQL 候选项布局计算逻辑,根据最终编辑器字号动态计算表名行高和候选项总高度。
- 将 Monaco 的 `suggestLineHeight` 与动态布局保持一致。
- 使用 CSS 变量替代候选项中的固定行高,确保大字号下内容完整显示。
- 保持默认字号下原有 36px 候选项高度不变。
- 增加默认字号、大字号和显式字号配置的单元测试。

## 影响范围

- 仅影响 v2 SQL 查询编辑器的表候选项。
- 旧版编辑器和其他类型的 Monaco 编辑器不受影响。
- 不涉及数据结构、接口、数据库或构建配置变更。
- SQL 字号为 18px 时,候选项高度调整为 43px;20px 时调整为 46px。

## 验证方式

- `sqlEditorTypography.test.ts`:3 个测试通过。
- `MonacoEditor.typography.test.tsx`:6 个测试通过。
- TypeScript 类型检查通过:`npx tsc --noEmit`。
- `git diff --check 630ba7fc^ 630ba7fc` 通过。
This commit is contained in:
Syngnat
2026-08-03 19:48:26 +08:00
committed by GitHub
5 changed files with 122 additions and 32 deletions

View File

@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import {
migrateLegacySqlEditorTypographySettings,
resolveSqlEditorFontSize,
resolveSqlEditorSuggestionLayout,
sanitizeSqlEditorTypographySettings,
} from './sqlEditorTypography';
@@ -39,4 +40,22 @@ describe('SQL editor typography', () => {
sqlEditorFontSizeFollowGlobal: false,
});
});
it('keeps default completion rows unchanged and grows the table-name row for large fonts', () => {
expect(resolveSqlEditorSuggestionLayout(13)).toEqual({
nameLineHeight: 18,
commentLineHeight: 18,
rowHeight: 36,
});
expect(resolveSqlEditorSuggestionLayout(18)).toEqual({
nameLineHeight: 25,
commentLineHeight: 18,
rowHeight: 43,
});
expect(resolveSqlEditorSuggestionLayout(20)).toEqual({
nameLineHeight: 28,
commentLineHeight: 18,
rowHeight: 46,
});
});
});

View File

@@ -6,6 +6,14 @@ export interface SqlEditorTypographySettings {
export const MIN_SQL_EDITOR_FONT_SIZE = 10;
export const MAX_SQL_EDITOR_FONT_SIZE = 20;
export const DEFAULT_SQL_EDITOR_FONT_SCALE = 0.92;
export const SQL_EDITOR_SUGGESTION_COMMENT_LINE_HEIGHT = 18;
export const SQL_EDITOR_SUGGESTION_NAME_LINE_HEIGHT_SCALE = 1.4;
export interface SqlEditorSuggestionLayout {
nameLineHeight: number;
commentLineHeight: number;
rowHeight: number;
}
export const DEFAULT_SQL_EDITOR_TYPOGRAPHY_SETTINGS: SqlEditorTypographySettings = {
sqlEditorFontSize: null,
@@ -45,6 +53,26 @@ export const resolveSqlEditorFontSize = ({
return sanitizeSqlEditorFontSize(sqlEditorFontSize) ?? globalDerivedFontSize;
};
/**
* Keep the structured table completion label tall enough for the editor font's
* descenders while preserving the existing 18px + 18px layout at default sizes.
*/
export const resolveSqlEditorSuggestionLayout = (fontSize: unknown): SqlEditorSuggestionLayout => {
const normalizedFontSize = Number.isFinite(Number(fontSize))
? Math.max(MIN_SQL_EDITOR_FONT_SIZE, Math.round(Number(fontSize)))
: 14;
const nameLineHeight = Math.max(
SQL_EDITOR_SUGGESTION_COMMENT_LINE_HEIGHT,
Math.round(normalizedFontSize * SQL_EDITOR_SUGGESTION_NAME_LINE_HEIGHT_SCALE),
);
const commentLineHeight = SQL_EDITOR_SUGGESTION_COMMENT_LINE_HEIGHT;
return {
nameLineHeight,
commentLineHeight,
rowHeight: nameLineHeight + commentLineHeight,
};
};
export const sanitizeSqlEditorTypographySettings = (
value: Partial<SqlEditorTypographySettings> | undefined,
): SqlEditorTypographySettings => {