mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-31 02:39:17 +08:00
🐛 fix(query-editor): 修复当前语句快捷选择在 CRLF 文本下错位
- 统一当前语句选择与执行路径的归一化 offset/position 换算 - 避免 Windows CRLF 文本下 SQL 语句选区错位 - 补充 QueryEditor 当前语句选择回归测试 Fixes #575
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user