1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

Fix delimiter highlighting in Firefox #27

input:first-line doesn't work in Firefox.
So, we use input background instead
This commit is contained in:
lana-k
2021-04-23 16:36:52 +02:00
parent 472794e203
commit 9a91dd19bf
2 changed files with 55 additions and 26 deletions

View File

@@ -8,12 +8,12 @@
> >
<div class="value"> <div class="value">
<input <input
:class="{ 'filled': filled }"
ref="delimiterInput" ref="delimiterInput"
type="text" type="text"
maxlength="1" maxlength="1"
:value="value" v-model="inputValue"
@click.stop @click.stop
@input.prevent="onInput($event)"
:disabled="disabled" :disabled="disabled"
/> />
<div class="name">{{ getSymbolName(value) }}</div> <div class="name">{{ getSymbolName(value) }}</div>
@@ -33,7 +33,7 @@
@click="chooseOption(option)" @click="chooseOption(option)"
class="option" class="option"
> >
<span>{{option}}</span><div>{{ getSymbolName(option) }}</div> <pre>{{option}}</pre><div>{{ getSymbolName(option) }}</div>
</div> </div>
</div> </div>
</div> </div>
@@ -51,9 +51,26 @@ export default {
data () { data () {
return { return {
showOptions: false, showOptions: false,
options: [',', '\t', '|', ';', '\u001F', '\u001E'] options: [',', '\t', ' ', '|', ';', '\u001F', '\u001E'],
filled: false,
inputValue: ''
} }
}, },
watch: {
inputValue () {
if (this.inputValue) {
this.filled = true
if (this.inputValue !== this.value) {
this.$emit('input', this.inputValue)
}
} else {
this.filled = false
}
}
},
created () {
this.inputValue = this.value
},
methods: { methods: {
getSymbolName (str) { getSymbolName (str) {
if (!str) { if (!str) {
@@ -61,15 +78,8 @@ export default {
} }
return ascii[str.charCodeAt(0).toString()].name return ascii[str.charCodeAt(0).toString()].name
}, },
onInput (event) {
const value = event.target.value
if (value) {
this.$emit('input', value)
}
},
chooseOption (option) { chooseOption (option) {
this.$emit('input', option) this.inputValue = option
this.showOptions = false this.showOptions = false
}, },
onContainerClick (event) { onContainerClick (event) {
@@ -78,7 +88,7 @@ export default {
clear () { clear () {
if (!this.disabled) { if (!this.disabled) {
this.$refs.delimiterInput.value = '' this.inputValue = ''
this.$refs.delimiterInput.focus() this.$refs.delimiterInput.focus()
} }
} }
@@ -108,6 +118,7 @@ export default {
.value .name { .value .name {
color: var(--color-text-light-2); color: var(--color-text-light-2);
cursor: default; cursor: default;
margin-left: 4px;
} }
.controls { .controls {
@@ -130,7 +141,6 @@ export default {
.option { .option {
display: flex; display: flex;
align-items: center; align-items: center;
white-space: pre;
height: 24px; height: 24px;
padding: 0 6px; padding: 0 6px;
} }
@@ -141,27 +151,30 @@ export default {
cursor: pointer; cursor: pointer;
} }
.option span { .option pre {
background-color: var(--color-bg-warning); background-color: var(--color-bg-warning);
line-height: 16px; line-height: 20px;
letter-spacing: 6px;
margin-right: 6px; margin-right: 6px;
tab-size: 1;
font-family: monospace;
width: 16px;
text-align: center;
} }
input { input {
background: var(--color-white); background: var(--color-white);
border: none; border: none;
color: var(--color-text-base); color: var(--color-text-base);
height: 34px; height: 20px;
font-family: monospace;
font-size: 12px; font-size: 12px;
box-sizing: border-box; box-sizing: border-box;
width: 20px; width: 16px;
letter-spacing: 6px; text-align: center;
line-height: 37px;
} }
input::first-line { input.filled {
background-color: var(--color-bg-warning); background: var(--color-bg-warning);
} }
input:focus { input:focus {

View File

@@ -4,17 +4,21 @@ import DelimiterSelector from '@/components/DelimiterSelector'
describe('DelimiterSelector', async () => { describe('DelimiterSelector', async () => {
it('shows the name of value', async () => { it('shows the name of value', async () => {
const wrapper = shallowMount(DelimiterSelector, { let wrapper = shallowMount(DelimiterSelector, {
propsData: { value: ',' } propsData: { value: ',' }
}) })
expect(wrapper.find('input').element.value).to.equal(',') expect(wrapper.find('input').element.value).to.equal(',')
expect(wrapper.find('.name').text()).to.equal('comma') expect(wrapper.find('.name').text()).to.equal('comma')
await wrapper.setProps({ value: '\t' }) wrapper = shallowMount(DelimiterSelector, {
propsData: { value: '\t' }
})
expect(wrapper.find('input').element.value).to.equal('\t') expect(wrapper.find('input').element.value).to.equal('\t')
expect(wrapper.find('.name').text()).to.equal('horizontal tab') expect(wrapper.find('.name').text()).to.equal('horizontal tab')
await wrapper.setProps({ value: '' }) wrapper = shallowMount(DelimiterSelector, {
propsData: { value: '' }
})
expect(wrapper.find('input').element.value).to.equal('') expect(wrapper.find('input').element.value).to.equal('')
expect(wrapper.find('.name').text()).to.equal('') expect(wrapper.find('.name').text()).to.equal('')
}) })
@@ -90,4 +94,16 @@ describe('DelimiterSelector', async () => {
await wrapper.findComponent({ name: 'drop-down-chevron' }).trigger('click') await wrapper.findComponent({ name: 'drop-down-chevron' }).trigger('click')
expect(wrapper.find('.options').isVisible()).to.equal(false) expect(wrapper.find('.options').isVisible()).to.equal(false)
}) })
it('has filled class when input is not empty', async () => {
const wrapper = shallowMount(DelimiterSelector, {
propsData: { value: ',' }
})
await wrapper.vm.$nextTick()
expect(wrapper.find('input').classes()).to.include('filled')
await wrapper.find('input').setValue('')
expect(wrapper.find('input').classes()).to.not.include('filled')
await wrapper.find('input').setValue(';')
expect(wrapper.find('input').classes()).to.include('filled')
})
}) })