🐛 fix(query-editor): 修复当前语句快捷选择在 CRLF 文本下错位

- 统一当前语句选择与执行路径的归一化 offset/position 换算
- 避免 Windows CRLF 文本下 SQL 语句选区错位
- 补充 QueryEditor 当前语句选择回归测试

Fixes #575
This commit is contained in:
Syngnat
2026-06-21 15:08:34 +08:00
parent 29e7e365f1
commit e7b8e78f9c
3 changed files with 58 additions and 4 deletions

View File

@@ -604,6 +604,20 @@ export const getNormalizedOffsetAtPosition = (
return Math.max(0, Math.min(text.length, offset + Math.max(0, position.column - 1)));
};
export const getNormalizedPositionAtOffset = (
sqlText: string,
offset: number,
): { lineNumber: number; column: number } => {
const text = String(sqlText || '').replace(/\r\n/g, '\n');
const safeOffset = Math.max(0, Math.min(text.length, Number.isFinite(offset) ? Math.trunc(offset) : 0));
const prefix = text.slice(0, safeOffset);
const lines = prefix.split('\n');
return {
lineNumber: Math.max(1, lines.length),
column: (lines[lines.length - 1]?.length || 0) + 1,
};
};
export const getFirstRowValue = (row: Record<string, any>): string => {
for (const value of Object.values(row || {})) {
if (value !== undefined && value !== null) {