mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-28 01:09:17 +08:00
✨ feat(query-editor): 支持还原 SQL 美化前内容
- 美化 SQL 前保存最近一次原始内容快照 - 在格式设置菜单提供还原上次美化入口 - 持久化查询标签页的美化恢复快照 - 补充编辑器与状态恢复回归测试
This commit is contained in:
@@ -3948,12 +3948,22 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
? connectionsRef.current.find(c => c.id === tabConnectionId)
|
||||
: undefined);
|
||||
const formatterLanguage = resolveQueryEditorFormatterLanguage(conn);
|
||||
const formatted = format(getCurrentQuery(), { language: formatterLanguage, keywordCase: sqlFormatOptions.keywordCase });
|
||||
const sourceSql = getCurrentQuery();
|
||||
const formatted = format(sourceSql, { language: formatterLanguage, keywordCase: sqlFormatOptions.keywordCase });
|
||||
if (sourceSql === formatted) {
|
||||
return;
|
||||
}
|
||||
updateQueryTabDraft(tab.id, {
|
||||
formatRestoreSnapshot: {
|
||||
query: sourceSql,
|
||||
createdAt: Date.now(),
|
||||
},
|
||||
});
|
||||
const editor = editorRef.current;
|
||||
const monaco = monacoRef.current;
|
||||
const model = editor?.getModel?.();
|
||||
if (editor && monaco && model) {
|
||||
const currentValue = String(model.getValue?.() || '');
|
||||
const currentValue = String(model.getValue?.() || sourceSql);
|
||||
if (currentValue === formatted) {
|
||||
return;
|
||||
}
|
||||
@@ -3977,6 +3987,21 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
}
|
||||
};
|
||||
|
||||
const handleRestoreLastFormat = () => {
|
||||
const previousQuery = tab.formatRestoreSnapshot?.query;
|
||||
if (!previousQuery) {
|
||||
void message.info('没有可还原的美化前 SQL');
|
||||
return;
|
||||
}
|
||||
syncQueryToEditor(previousQuery);
|
||||
updateQueryTabDraft(tab.id, {
|
||||
query: previousQuery,
|
||||
formatRestoreSnapshot: undefined,
|
||||
});
|
||||
refreshObjectDecorations();
|
||||
void message.success('已还原到美化前 SQL');
|
||||
};
|
||||
|
||||
const handleAIAction = (action: 'generate' | 'explain' | 'optimize' | 'schema') => {
|
||||
const editor = editorRef.current;
|
||||
const selection = editor?.getModel()?.getValueInRange(editor.getSelection()) || '';
|
||||
@@ -4013,6 +4038,13 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
onClick: () => setSqlFormatOptions({ keywordCase: 'lower' })
|
||||
},
|
||||
{ type: 'divider' },
|
||||
{
|
||||
key: 'restore-last-format',
|
||||
label: '还原上次美化',
|
||||
disabled: !tab.formatRestoreSnapshot?.query,
|
||||
onClick: handleRestoreLastFormat,
|
||||
},
|
||||
{ type: 'divider' },
|
||||
{
|
||||
key: 'snippet-settings',
|
||||
label: '代码片段管理...',
|
||||
|
||||
Reference in New Issue
Block a user