mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c456ef135 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sqliteviz",
|
||||
"version": "0.21.0",
|
||||
"version": "0.21.1",
|
||||
"license": "Apache-2.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -3,14 +3,20 @@ import 'codemirror/addon/hint/show-hint.js'
|
||||
import 'codemirror/addon/hint/sql-hint.js'
|
||||
import store from '@/store'
|
||||
|
||||
function _getHintText (hint) {
|
||||
return typeof hint === 'string' ? hint : hint.text
|
||||
}
|
||||
export function getHints (cm, options) {
|
||||
const token = cm.getTokenAt(cm.getCursor()).string.toUpperCase()
|
||||
const result = CM.hint.sql(cm, options)
|
||||
|
||||
// Don't show the hint if there is only one option
|
||||
// and the token is already completed with this option
|
||||
if (result.list.length === 1 && result.list[0].text.toUpperCase() === token) {
|
||||
// and the replacingText is already equals to this option
|
||||
const replacedText = cm.getRange(result.from, result.to).toUpperCase()
|
||||
if (result.list.length === 1 &&
|
||||
_getHintText(result.list[0]).toUpperCase() === replacedText) {
|
||||
result.list = []
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -138,15 +138,37 @@ describe('hint.js', () => {
|
||||
'getHints returns [ ] if there is only one option and token is completed with this option',
|
||||
() => {
|
||||
// mock CM.hint.sql and editor
|
||||
sinon.stub(CM.hint, 'sql').returns({ list: [{ text: 'SELECT' }] })
|
||||
sinon.stub(CM.hint, 'sql').returns({
|
||||
list: [{ text: 'SELECT' }],
|
||||
from: null, // from/to doesn't metter because getRange is mocked
|
||||
to: null
|
||||
})
|
||||
|
||||
const editor = {
|
||||
getTokenAt () {
|
||||
return {
|
||||
string: 'select',
|
||||
type: 'keyword'
|
||||
}
|
||||
},
|
||||
getCursor: sinon.stub()
|
||||
getRange () {
|
||||
return 'select'
|
||||
}
|
||||
}
|
||||
|
||||
const hints = getHints(editor, {})
|
||||
expect(hints.list).to.eql([])
|
||||
}
|
||||
)
|
||||
|
||||
it(
|
||||
'getHints returns [ ] if there is only one string option and token ' +
|
||||
'is completed with this option',
|
||||
() => {
|
||||
// mock CM.hint.sql and editor
|
||||
sinon.stub(CM.hint, 'sql').returns({
|
||||
list: ['house.name'],
|
||||
from: null, // from/to doesn't metter because getRange is mocked
|
||||
to: null
|
||||
})
|
||||
const editor = {
|
||||
getRange () {
|
||||
return 'house.name'
|
||||
}
|
||||
}
|
||||
|
||||
const hints = getHints(editor, {})
|
||||
@@ -160,15 +182,11 @@ describe('hint.js', () => {
|
||||
{ text: 'SELECT' },
|
||||
{ text: 'ST' }
|
||||
]
|
||||
sinon.stub(CM.hint, 'sql').returns({ list })
|
||||
sinon.stub(CM.hint, 'sql').returns({ list, from: null, to: null })
|
||||
const editor = {
|
||||
getTokenAt () {
|
||||
return {
|
||||
string: 'se',
|
||||
type: 'keyword'
|
||||
}
|
||||
},
|
||||
getCursor: sinon.stub()
|
||||
getRange () {
|
||||
return 'se'
|
||||
}
|
||||
}
|
||||
|
||||
const hints = getHints(editor, {})
|
||||
@@ -182,15 +200,11 @@ describe('hint.js', () => {
|
||||
() => {
|
||||
// mock CM.hint.sql and editor
|
||||
const list = [{ text: 'SELECT' }]
|
||||
sinon.stub(CM.hint, 'sql').returns({ list })
|
||||
sinon.stub(CM.hint, 'sql').returns({ list, from: null, to: null })
|
||||
const editor = {
|
||||
getTokenAt () {
|
||||
return {
|
||||
string: 'sele',
|
||||
type: 'keyword'
|
||||
}
|
||||
},
|
||||
getCursor: sinon.stub()
|
||||
getRange () {
|
||||
return 'sele'
|
||||
}
|
||||
}
|
||||
|
||||
const hints = getHints(editor, {})
|
||||
|
||||
Reference in New Issue
Block a user