@@ -223,15 +223,15 @@ struct SQLEditorView: NSViewRepresentable {
226− // A table completion carries its own quotes; absorb a directly
226+ // A table completion carries its own quotes; absorb any double-quote the
227− // preceding opening quote the user typed (e.g. `FROM "my`) so the
228− // inserted `"name"` replaces it instead of producing `""name"`.
227+ // user typed directly around the word so the inserted `"name"` replaces
228+ // it instead of leaving a stray quote. Leading and trailing are handled
229+ // independently: a closing quote can exist without an opening one (e.g.
230+ // `FROM my"`), which would otherwise produce a dangling `"name""`.
229− if item.kind == .table, wordStart > 0,
231+ if item.kind == .table {
230− nsText.character(at: wordStart - 1) == 0x22 {
232+ if wordStart > 0, nsText.character(at: wordStart - 1) == 0x22 {
231− wordStart -= 1
233+ wordStart -= 1
232− // Mirror on the trailing side: if a matching closing quote follows
234+ }
233− // the word (caret inside an already-quoted `FROM "my|"`), absorb it
234− // too so the inserted `"name"` doesn't leave a dangling `"name""`.
235 if wordEnd < nsText.length, nsText.character(at: wordEnd) == 0x22 {
235 if wordEnd < nsText.length, nsText.character(at: wordEnd) == 0x22 {
236 wordEnd += 1
236 wordEnd += 1