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",
|
"name": "sqliteviz",
|
||||||
"version": "0.21.0",
|
"version": "0.21.1",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -3,14 +3,20 @@ import 'codemirror/addon/hint/show-hint.js'
|
|||||||
import 'codemirror/addon/hint/sql-hint.js'
|
import 'codemirror/addon/hint/sql-hint.js'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
|
|
||||||
|
function _getHintText (hint) {
|
||||||
|
return typeof hint === 'string' ? hint : hint.text
|
||||||
|
}
|
||||||
export function getHints (cm, options) {
|
export function getHints (cm, options) {
|
||||||
const token = cm.getTokenAt(cm.getCursor()).string.toUpperCase()
|
|
||||||
const result = CM.hint.sql(cm, options)
|
const result = CM.hint.sql(cm, options)
|
||||||
|
|
||||||
// Don't show the hint if there is only one option
|
// Don't show the hint if there is only one option
|
||||||
// and the token is already completed with this option
|
// and the replacingText is already equals to this option
|
||||||
if (result.list.length === 1 && result.list[0].text.toUpperCase() === token) {
|
const replacedText = cm.getRange(result.from, result.to).toUpperCase()
|
||||||
|
if (result.list.length === 1 &&
|
||||||
|
_getHintText(result.list[0]).toUpperCase() === replacedText) {
|
||||||
result.list = []
|
result.list = []
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,15 +138,37 @@ describe('hint.js', () => {
|
|||||||
'getHints returns [ ] if there is only one option and token is completed with this option',
|
'getHints returns [ ] if there is only one option and token is completed with this option',
|
||||||
() => {
|
() => {
|
||||||
// mock CM.hint.sql and editor
|
// 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 = {
|
const editor = {
|
||||||
getTokenAt () {
|
getRange () {
|
||||||
return {
|
return 'select'
|
||||||
string: 'select',
|
}
|
||||||
type: 'keyword'
|
}
|
||||||
}
|
|
||||||
},
|
const hints = getHints(editor, {})
|
||||||
getCursor: sinon.stub()
|
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, {})
|
const hints = getHints(editor, {})
|
||||||
@@ -160,15 +182,11 @@ describe('hint.js', () => {
|
|||||||
{ text: 'SELECT' },
|
{ text: 'SELECT' },
|
||||||
{ text: 'ST' }
|
{ text: 'ST' }
|
||||||
]
|
]
|
||||||
sinon.stub(CM.hint, 'sql').returns({ list })
|
sinon.stub(CM.hint, 'sql').returns({ list, from: null, to: null })
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt () {
|
getRange () {
|
||||||
return {
|
return 'se'
|
||||||
string: 'se',
|
}
|
||||||
type: 'keyword'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getCursor: sinon.stub()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const hints = getHints(editor, {})
|
const hints = getHints(editor, {})
|
||||||
@@ -182,15 +200,11 @@ describe('hint.js', () => {
|
|||||||
() => {
|
() => {
|
||||||
// mock CM.hint.sql and editor
|
// mock CM.hint.sql and editor
|
||||||
const list = [{ text: 'SELECT' }]
|
const list = [{ text: 'SELECT' }]
|
||||||
sinon.stub(CM.hint, 'sql').returns({ list })
|
sinon.stub(CM.hint, 'sql').returns({ list, from: null, to: null })
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt () {
|
getRange () {
|
||||||
return {
|
return 'sele'
|
||||||
string: 'sele',
|
}
|
||||||
type: 'keyword'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getCursor: sinon.stub()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const hints = getHints(editor, {})
|
const hints = getHints(editor, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user