fix(ai): preserve editor content for SQL actions

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-07-11 08:55:51 +08:00
1 parent 343a5ba6c9
commit 088a4a081b
11 files changed
+97 -7

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
/**
* Build the editor content after appending AI-generated SQL to existing editor SQL.
* Preserves the existing editor content exactly and adds only the newline separator
* needed to leave a blank line before the appended SQL.
*/
export function buildAppendedEditorSql(currentEditorSql: string, newSql: string): string {
if (!currentEditorSql) return newSql;
let separator = "\n\n";
if (currentEditorSql.endsWith("\r\n\r\n") || currentEditorSql.endsWith("\n\n")) {
separator = "";
} else if (currentEditorSql.endsWith("\r\n")) {
separator = "\r\n";
} else if (currentEditorSql.endsWith("\n")) {
separator = "\n";
}
return `${currentEditorSql}${separator}${newSql}`;
}