From 6fc21e40bfc83843de2e0a82c41d937ef5dfa367 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 24 Mar 2018 18:04:54 -0700 Subject: [PATCH] add username autocomplete feature --- routes/_actions/compose.js | 18 +++ .../compose/ComposeAutosuggest.html | 128 ++++++++++++++++++ .../compose/ComposeAutosuggestionList.html | 90 ++++++++++++ routes/_components/compose/ComposeBox.html | 2 +- routes/_components/compose/ComposeInput.html | 56 +++++++- .../_components/compose/ComposeToolbar.html | 66 +++++---- routes/_database/accountsAndRelationships.js | 28 +++- routes/_database/constants.js | 1 + routes/_database/databaseLifecycle.js | 16 ++- routes/_database/helpers.js | 6 +- routes/_database/keys.js | 11 ++ routes/_utils/events.js | 17 +++ routes/_utils/once.js | 8 ++ scss/themes/_base.scss | 4 + scss/themes/_default.scss | 1 + scss/themes/_offline.scss | 1 + scss/themes/gecko.scss | 1 + scss/themes/hotpants.scss | 1 + scss/themes/majesty.scss | 1 + scss/themes/oaken.scss | 1 + scss/themes/scarlet.scss | 1 + scss/themes/seafoam.scss | 1 + templates/2xx.html | 4 +- 23 files changed, 428 insertions(+), 35 deletions(-) create mode 100644 routes/_components/compose/ComposeAutosuggest.html create mode 100644 routes/_components/compose/ComposeAutosuggestionList.html create mode 100644 routes/_utils/once.js diff --git a/routes/_actions/compose.js b/routes/_actions/compose.js index aadd5a6..c0c356b 100644 --- a/routes/_actions/compose.js +++ b/routes/_actions/compose.js @@ -47,3 +47,21 @@ export async function postStatus (realm, text, inReplyToId, mediaIds, store.set({postingStatus: false}) } } + +export async function insertUsername (realm, username, startIndex, endIndex) { + let oldText = store.getComposeData(realm, 'text') + let pre = oldText.substring(0, startIndex) + let post = oldText.substring(endIndex) + let newText = `${pre}@${username} ${post}` + store.setComposeData(realm, {text: newText}) +} + +export async function clickSelectedAutosuggestionUsername (realm) { + let selectionStart = store.get('composeSelectionStart') + let searchText = store.get('composeAutosuggestionSearchText') + let selection = store.get('composeAutosuggestionSelected') || 0 + let account = store.get('composeAutosuggestionSearchResults')[selection] + let startIndex = selectionStart - searchText.length + let endIndex = selectionStart + await insertUsername(realm, account.acct, startIndex, endIndex) +} diff --git a/routes/_components/compose/ComposeAutosuggest.html b/routes/_components/compose/ComposeAutosuggest.html new file mode 100644 index 0000000..88833e6 --- /dev/null +++ b/routes/_components/compose/ComposeAutosuggest.html @@ -0,0 +1,128 @@ + + + \ No newline at end of file diff --git a/routes/_components/compose/ComposeAutosuggestionList.html b/routes/_components/compose/ComposeAutosuggestionList.html new file mode 100644 index 0000000..68978d8 --- /dev/null +++ b/routes/_components/compose/ComposeAutosuggestionList.html @@ -0,0 +1,90 @@ + + + \ No newline at end of file diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html index 8135bb2..d02d107 100644 --- a/routes/_components/compose/ComposeBox.html +++ b/routes/_components/compose/ComposeBox.html @@ -8,7 +8,7 @@ {{/if}} - + diff --git a/routes/_components/compose/ComposeInput.html b/routes/_components/compose/ComposeInput.html index 9acfbac..ee8a61a 100644 --- a/routes/_components/compose/ComposeInput.html +++ b/routes/_components/compose/ComposeInput.html @@ -4,6 +4,9 @@ ref:textarea bind:value=rawText on:blur="onBlur()" + on:focus="onFocus()" + on:selectionChange="onSelectionChange(event)" + on:keydown="onKeydown(event)" >