From c22187c3053aef368a351cc35e2f1d407ecde209 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sat, 17 Apr 2021 10:33:15 +0200 Subject: [PATCH] perf(UI): improved table fields suggestion in query editor --- src/renderer/components/QueryEditor.vue | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/QueryEditor.vue b/src/renderer/components/QueryEditor.vue index bc08365f..dbec19b2 100644 --- a/src/renderer/components/QueryEditor.vue +++ b/src/renderer/components/QueryEditor.vue @@ -126,9 +126,13 @@ export default { return 'sql'; } }, + cursorPosition () { + return this.editor.session.doc.positionToIndex(this.editor.getCursorPosition()); + }, lastWord () { - const words = this.value.split(' '); - return words[words.length - 1]; + const charsBefore = this.value.slice(0, this.cursorPosition); + const words = charsBefore.replaceAll('\n', ' ').split(' ').filter(Boolean); + return words.pop(); }, isLastWordATable () { return /\w+\.\w*/gm.test(this.lastWord); @@ -209,7 +213,7 @@ export default { if (['insertstring', 'backspace', 'del'].includes(e.command.name)) { if (this.isLastWordATable || e.args === '.') { if (e.args !== ' ') { - const table = this.tables.find(t => t.name === this.lastWord.split('.').pop()); + const table = this.tables.find(t => t.name === this.lastWord.split('.').pop().trim()); if (table) { const params = {