fix more bugs in autocomplete

fully fixes #170
This commit is contained in:
Nolan Lawson 2018-04-21 12:00:06 -07:00
parent 209b36c73b
commit 6bfccc4993
3 changed files with 38 additions and 5 deletions

View File

@ -83,7 +83,8 @@
} }
}) })
this.observe('searchText', async searchText => { this.observe('searchText', async searchText => {
if (!searchText) { let { thisComposeFocused } = this.get()
if (!thisComposeFocused || !searchText) {
return return
} }
let type = searchText.startsWith('@') ? 'account' : 'emoji' let type = searchText.startsWith('@') ? 'account' : 'emoji'
@ -98,6 +99,10 @@
}) })
}) })
this.observe('shown', shown => { this.observe('shown', shown => {
let { thisComposeFocused } = this.get()
if (!thisComposeFocused) {
return
}
this.store.set({composeAutosuggestionShown: shown}) this.store.set({composeAutosuggestionShown: shown})
}) })
}, },
@ -138,7 +143,10 @@
searchResults: ($composeAutosuggestionSearchResults) => $composeAutosuggestionSearchResults || [], searchResults: ($composeAutosuggestionSearchResults) => $composeAutosuggestionSearchResults || [],
type: ($composeAutosuggestionType) => $composeAutosuggestionType || 'account', type: ($composeAutosuggestionType) => $composeAutosuggestionType || 'account',
selected: ($composeAutosuggestionSelected) => $composeAutosuggestionSelected || 0, selected: ($composeAutosuggestionSelected) => $composeAutosuggestionSelected || 0,
searchText: (text, composeSelectionStartDeferred) => { searchText: (text, composeSelectionStartDeferred, thisComposeFocused) => {
if (!thisComposeFocused) {
return
}
let selectionStart = composeSelectionStartDeferred || 0 let selectionStart = composeSelectionStartDeferred || 0
if (!text || selectionStart < MIN_PREFIX_LENGTH) { if (!text || selectionStart < MIN_PREFIX_LENGTH) {
return return

View File

@ -93,14 +93,23 @@
stop('autosize.destroy()') stop('autosize.destroy()')
}, },
onBlur () { onBlur () {
this.store.set({composeFocused: null}) this.store.set({
composeFocused: null,
composeSelectionStart: null,
composeAutosuggestionSearchText: null,
composeAutosuggestionSearchResults: null
})
}, },
onFocus () { onFocus () {
let { realm } = this.get() let { realm } = this.get()
this.store.set({composeFocused: realm}) this.store.set({composeFocused: realm})
}, },
onSelectionChange (selectionStart) { onSelectionChange (selectionStart) {
this.store.set({composeSelectionStart: selectionStart}) let { realm } = this.get()
let { composeFocused } = this.store.get()
if (realm === composeFocused) {
this.store.set({composeSelectionStart: selectionStart})
}
}, },
onKeydown (e) { onKeydown (e) {
let { keyCode } = e let { keyCode } = e

View File

@ -1,5 +1,5 @@
import { import {
composeInput, getNthAutosuggestionResult, getNthComposeReplyInput, getNthReplyButton, getNthStatus composeInput, getNthAutosuggestionResult, getNthComposeReplyInput, getNthReplyButton, getNthStatus, sleep
} from '../utils' } from '../utils'
import { Selector as $ } from 'testcafe' import { Selector as $ } from 'testcafe'
import { foobarRole } from '../roles' import { foobarRole } from '../roles'
@ -93,3 +93,19 @@ test('autosuggest only shows for one input', async t => {
.typeText(getNthComposeReplyInput(0), 'uu') .typeText(getNthComposeReplyInput(0), 'uu')
.expect($('.compose-autosuggest.shown').exists).notOk() .expect($('.compose-autosuggest.shown').exists).notOk()
}) })
test('autosuggest only shows for one input part 2', async t => {
await t.useRole(foobarRole)
.hover(composeInput)
.typeText(composeInput, '@adm')
.expect($('.compose-autosuggest.shown').exists).ok()
.expect(getNthAutosuggestionResult(1).innerText).contains('@admin')
.hover(getNthStatus(0))
.click(getNthReplyButton(0))
.selectText(getNthComposeReplyInput(0))
.pressKey('delete')
.typeText(getNthComposeReplyInput(0), '@dd')
await sleep(1000)
await t.pressKey('backspace')
.expect($('.compose-autosuggest.shown').exists).notOk()
})