diff --git a/routes/_components/compose/ComposeAutosuggest.html b/routes/_components/compose/ComposeAutosuggest.html index 6d42a909..89186408 100644 --- a/routes/_components/compose/ComposeAutosuggest.html +++ b/routes/_components/compose/ComposeAutosuggest.html @@ -83,7 +83,8 @@ } }) this.observe('searchText', async searchText => { - if (!searchText) { + let { thisComposeFocused } = this.get() + if (!thisComposeFocused || !searchText) { return } let type = searchText.startsWith('@') ? 'account' : 'emoji' @@ -98,6 +99,10 @@ }) }) this.observe('shown', shown => { + let { thisComposeFocused } = this.get() + if (!thisComposeFocused) { + return + } this.store.set({composeAutosuggestionShown: shown}) }) }, @@ -138,7 +143,10 @@ searchResults: ($composeAutosuggestionSearchResults) => $composeAutosuggestionSearchResults || [], type: ($composeAutosuggestionType) => $composeAutosuggestionType || 'account', selected: ($composeAutosuggestionSelected) => $composeAutosuggestionSelected || 0, - searchText: (text, composeSelectionStartDeferred) => { + searchText: (text, composeSelectionStartDeferred, thisComposeFocused) => { + if (!thisComposeFocused) { + return + } let selectionStart = composeSelectionStartDeferred || 0 if (!text || selectionStart < MIN_PREFIX_LENGTH) { return diff --git a/routes/_components/compose/ComposeInput.html b/routes/_components/compose/ComposeInput.html index 2db927ab..e04c4dff 100644 --- a/routes/_components/compose/ComposeInput.html +++ b/routes/_components/compose/ComposeInput.html @@ -93,14 +93,23 @@ stop('autosize.destroy()') }, onBlur () { - this.store.set({composeFocused: null}) + this.store.set({ + composeFocused: null, + composeSelectionStart: null, + composeAutosuggestionSearchText: null, + composeAutosuggestionSearchResults: null + }) }, onFocus () { let { realm } = this.get() this.store.set({composeFocused: realm}) }, 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) { let { keyCode } = e diff --git a/tests/spec/018-compose-autosuggest.js b/tests/spec/018-compose-autosuggest.js index a4d309a4..d0c98ba2 100644 --- a/tests/spec/018-compose-autosuggest.js +++ b/tests/spec/018-compose-autosuggest.js @@ -1,5 +1,5 @@ import { - composeInput, getNthAutosuggestionResult, getNthComposeReplyInput, getNthReplyButton, getNthStatus + composeInput, getNthAutosuggestionResult, getNthComposeReplyInput, getNthReplyButton, getNthStatus, sleep } from '../utils' import { Selector as $ } from 'testcafe' import { foobarRole } from '../roles' @@ -93,3 +93,19 @@ test('autosuggest only shows for one input', async t => { .typeText(getNthComposeReplyInput(0), 'uu') .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() +})