Browse Source

fix: insertAtCursor position when calling appendText & refactor isCurlyBracketBalanced

feat/0523-export-schema
Wing-Kam Wong 3 years ago committed by Raju Udava
parent
commit
0b75fa1ef1
  1. 11
      packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue

11
packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue

@ -545,13 +545,18 @@ export default {
return 'N/A' return 'N/A'
} }
}, },
isCurlyBracketBalanced() {
// 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), {})
return (cntCurlyBrackets['{'] || 0) === (cntCurlyBrackets['}'] || 0)
},
appendText(it) { appendText(it) {
const text = it.text const text = it.text
const len = this.wordToComplete.length const len = this.wordToComplete.length
if (it.type === 'function') { if (it.type === 'function') {
this.$set(this.formula, 'value', insertAtCursor(this.$refs.input.$el.querySelector('input'), text, len, 1)) this.$set(this.formula, 'value', insertAtCursor(this.$refs.input.$el.querySelector('input'), text, len, 1))
} else if (it.type === 'column') { } else if (it.type === 'column') {
this.$set(this.formula, 'value', insertAtCursor(this.$refs.input.$el.querySelector('input'), '{' + text + '}', len)) this.$set(this.formula, 'value', insertAtCursor(this.$refs.input.$el.querySelector('input'), '{' + text + '}', len + (!this.isCurlyBracketBalanced())))
} else { } else {
this.$set(this.formula, 'value', insertAtCursor(this.$refs.input.$el.querySelector('input'), text, len)) this.$set(this.formula, 'value', insertAtCursor(this.$refs.input.$el.querySelector('input'), text, len))
} }
@ -571,9 +576,7 @@ export default {
const parts = query.split(/\W+/) const parts = query.split(/\W+/)
this.wordToComplete = parts.pop() this.wordToComplete = parts.pop()
this.suggestion = this.acTree.complete(this.wordToComplete)?.sort((x, y) => this.sortOrder[x.type] - this.sortOrder[y.type]) 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 if (this.isCurlyBracketBalanced()) {
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.suggestion.filter(v => v.type === 'column') this.suggestion = this.suggestion.filter(v => v.type === 'column')
} }
this.autocomplete = !!this.suggestion.length this.autocomplete = !!this.suggestion.length

Loading…
Cancel
Save