From 5dc423a924f5afeff0efee8158f4273d20adcde0 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 25 May 2022 21:40:17 +0800 Subject: [PATCH] enhancement: show column list only when column is the only option --- .../components/editColumn/FormulaOptions.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue b/packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue index 38664f4800..95aaefbdd7 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue @@ -568,9 +568,15 @@ export default { this.selected = 0 this.suggestion = null const query = getWordUntilCaret(this.$refs.input.$el.querySelector('input')) - const parts = query.split(/\W+/) - this.wordToComplete = parts.pop() - this.suggestion = this.acTree.complete(this.wordToComplete)?.sort((x, y) => this.sortOrder[x.type] - this.sortOrder[y.type]) + // count number of opening curly brackets and closing curly brackets + const cntCurlyBrackets = (this.$refs.input.$el.querySelector('input').value.match(/\{|}/g) || []).reduce((acc, cur) => (acc[cur] = (acc[cur] || 0) + 1, acc), {}) + if (Math.abs((cntCurlyBrackets['{'] || 0) - (cntCurlyBrackets['}'] || 0))) { + this.suggestion = this.suggestionsList.filter(v => v.type === 'column') + } else { + const parts = query.split(/\W+/) + this.wordToComplete = parts.pop() + this.suggestion = this.acTree.complete(this.wordToComplete)?.sort((x, y) => this.sortOrder[x.type] - this.sortOrder[y.type]) + } this.autocomplete = !!this.suggestion.length }, selectText() {