fix: context menu Format SQL not working (#659)#662
Merged
Conversation
…#659) Root cause: formatQuery() passed as onFormatSQL closure captures QueryEditorView struct by value. After SwiftUI recreates the view, the captured @binding queryText becomes stale (empty). Toolbar button works because it runs in current render context. Fix: add fallback in context menu that formats directly via the text view when the callback closure is stale. Also lazily recreate context menu after destroy().
Coordinator lifecycle: - Move callback wiring from .onAppear to view body (fresh on every re-render) - Add revive() method to re-register with EditorEventRouter after tab switch - Add onFormatSQL = nil to destroy() cleanup - Add databaseType property to coordinator - Remove hacky formatSQLInTextView fallback (was hardcoding .mysql dialect) SQL formatter: - Fix comment placeholder order: single-pass extraction by source position - Fix SQL-standard '' escape not handled in string literal regex - Fix addLineBreaks ignoring uppercaseKeywords option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #659
Root Cause
formatQuery()is passed as a closure fromQueryEditorView(a SwiftUI struct) throughSQLEditorView.onFormatSQLtoSQLEditorCoordinator.onFormatSQL. The closure captures theQueryEditorViewstruct by value at body evaluation time. After SwiftUI recreates the view, the captured@Binding queryTextbecomes stale and returns empty string.The toolbar Format button works because it runs in the current SwiftUI render context where the binding is valid.
Fix
onFormatSQLcallback is stale, the context menu formats directly via the coordinator's text view reference usingSQLFormatterServiceshowContextMenu()lazily recreates theAIEditorContextMenuif it was destroyed bydestroy()(tab switch lifecycle)Test plan