Merge branch 'develop' into 'fix/wait-for-request-before-starting-interval'

# Conflicts:
#   CHANGELOG.md
This commit is contained in:
Shpuld Shpludson 2020-09-04 08:38:13 +00:00
commit e331db79e5
24 changed files with 126 additions and 70 deletions

View file

@ -5,11 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased] ## [Unreleased]
## [Unreleased patch] ## [Unreleased patch]
### Changed ### Changed
- Polls will be hidden with status content if "Collapse posts with subjects" is enabled and the post is collapsed. - Polls will be hidden with status content if "Collapse posts with subjects" is enabled and the post is collapsed.
### Fixed ### Fixed
- Network fetches don't pile up anymore but wait for previous ones to finish to reduce throttling. - Network fetches don't pile up anymore but wait for previous ones to finish to reduce throttling.
- Autocomplete won't stop at the second @, so it'll still work with "@lain@l" and not start over.
- Fixed weird autocomplete behavior when you write ":custom_emoji: ?"
## [2.1.0] - 2020-08-28 ## [2.1.0] - 2020-08-28
### Added ### Added

View file

@ -47,11 +47,6 @@ const passwordReset = {
if (status === 204) { if (status === 204) {
this.success = true this.success = true
this.error = null this.error = null
} else if (status === 404 || status === 400) {
this.error = this.$t('password_reset.not_found')
this.$nextTick(() => {
this.$refs.email.focus()
})
} else if (status === 429) { } else if (status === 429) {
this.throttled = true this.throttled = true
this.error = this.$t('password_reset.too_many_requests') this.error = this.$t('password_reset.too_many_requests')

View file

@ -555,6 +555,9 @@ const PostStatusForm = {
}, },
updateIdempotencyKey () { updateIdempotencyKey () {
this.idempotencyKey = Date.now().toString() this.idempotencyKey = Date.now().toString()
},
openProfileTab () {
this.$store.dispatch('openSettingsModalTab', 'profile')
} }
} }
} }

View file

@ -23,9 +23,12 @@
tag="p" tag="p"
class="visibility-notice" class="visibility-notice"
> >
<router-link :to="{ name: 'user-settings' }"> <a
href="#"
@click="openProfileTab"
>
{{ $t('post_status.account_not_locked_warning_link') }} {{ $t('post_status.account_not_locked_warning_link') }}
</router-link> </a>
</i18n> </i18n>
<p <p
v-if="!hideScopeNotice && newStatus.visibility === 'public'" v-if="!hideScopeNotice && newStatus.visibility === 'public'"

View file

@ -27,6 +27,34 @@ const SettingsModalContent = {
computed: { computed: {
isLoggedIn () { isLoggedIn () {
return !!this.$store.state.users.currentUser return !!this.$store.state.users.currentUser
},
open () {
return this.$store.state.interface.settingsModalState !== 'hidden'
}
},
methods: {
onOpen () {
const targetTab = this.$store.state.interface.settingsModalTargetTab
// We're being told to open in specific tab
if (targetTab) {
const tabIndex = this.$refs.tabSwitcher.$slots.default.findIndex(elm => {
return elm.data && elm.data.attrs['data-tab-name'] === targetTab
})
if (tabIndex >= 0) {
this.$refs.tabSwitcher.setTab(tabIndex)
}
}
// Clear the state of target tab, so that next time settings is opened
// it doesn't force it.
this.$store.dispatch('clearSettingsModalTargetTab')
}
},
mounted () {
this.onOpen()
},
watch: {
open: function (value) {
if (value) this.onOpen()
} }
} }
} }

View file

@ -8,6 +8,7 @@
<div <div
:label="$t('settings.general')" :label="$t('settings.general')"
icon="wrench" icon="wrench"
data-tab-name="general"
> >
<GeneralTab /> <GeneralTab />
</div> </div>
@ -15,6 +16,7 @@
v-if="isLoggedIn" v-if="isLoggedIn"
:label="$t('settings.profile_tab')" :label="$t('settings.profile_tab')"
icon="user" icon="user"
data-tab-name="profile"
> >
<ProfileTab /> <ProfileTab />
</div> </div>
@ -22,18 +24,21 @@
v-if="isLoggedIn" v-if="isLoggedIn"
:label="$t('settings.security_tab')" :label="$t('settings.security_tab')"
icon="lock" icon="lock"
data-tab-name="security"
> >
<SecurityTab /> <SecurityTab />
</div> </div>
<div <div
:label="$t('settings.filtering')" :label="$t('settings.filtering')"
icon="filter" icon="filter"
data-tab-name="filtering"
> >
<FilteringTab /> <FilteringTab />
</div> </div>
<div <div
:label="$t('settings.theme')" :label="$t('settings.theme')"
icon="brush" icon="brush"
data-tab-name="theme"
> >
<ThemeTab /> <ThemeTab />
</div> </div>
@ -41,6 +46,7 @@
v-if="isLoggedIn" v-if="isLoggedIn"
:label="$t('settings.notifications')" :label="$t('settings.notifications')"
icon="bell-ringing-o" icon="bell-ringing-o"
data-tab-name="notifications"
> >
<NotificationsTab /> <NotificationsTab />
</div> </div>
@ -48,6 +54,7 @@
v-if="isLoggedIn" v-if="isLoggedIn"
:label="$t('settings.data_import_export_tab')" :label="$t('settings.data_import_export_tab')"
icon="download" icon="download"
data-tab-name="dataImportExport"
> >
<DataImportExportTab /> <DataImportExportTab />
</div> </div>
@ -56,12 +63,14 @@
:label="$t('settings.mutes_and_blocks')" :label="$t('settings.mutes_and_blocks')"
:fullHeight="true" :fullHeight="true"
icon="eye-off" icon="eye-off"
data-tab-name="mutesAndBlocks"
> >
<MutesAndBlocksTab /> <MutesAndBlocksTab />
</div> </div>
<div <div
:label="$t('settings.version.title')" :label="$t('settings.version.title')"
icon="info-circled" icon="info-circled"
data-tab-name="version"
> >
<VersionTab /> <VersionTab />
</div> </div>

View file

@ -60,16 +60,19 @@ export default Vue.component('tab-switcher', {
} }
}, },
methods: { methods: {
activateTab (index) { clickTab (index) {
return (e) => { return (e) => {
e.preventDefault() e.preventDefault()
if (typeof this.onSwitch === 'function') { this.setTab(index)
this.onSwitch.call(null, this.$slots.default[index].key) }
} },
this.active = index setTab (index) {
if (this.scrollableTabs) { if (typeof this.onSwitch === 'function') {
this.$refs.contents.scrollTop = 0 this.onSwitch.call(null, this.$slots.default[index].key)
} }
this.active = index
if (this.scrollableTabs) {
this.$refs.contents.scrollTop = 0
} }
} }
}, },
@ -88,7 +91,7 @@ export default Vue.component('tab-switcher', {
<div class={classesWrapper.join(' ')}> <div class={classesWrapper.join(' ')}>
<button <button
disabled={slot.data.attrs.disabled} disabled={slot.data.attrs.disabled}
onClick={this.activateTab(index)} onClick={this.clickTab(index)}
class={classesTab.join(' ')}> class={classesTab.join(' ')}>
<img src={slot.data.attrs.image} title={slot.data.attrs['image-tooltip']}/> <img src={slot.data.attrs.image} title={slot.data.attrs['image-tooltip']}/>
{slot.data.attrs.label ? '' : slot.data.attrs.label} {slot.data.attrs.label ? '' : slot.data.attrs.label}
@ -100,7 +103,7 @@ export default Vue.component('tab-switcher', {
<div class={classesWrapper.join(' ')}> <div class={classesWrapper.join(' ')}>
<button <button
disabled={slot.data.attrs.disabled} disabled={slot.data.attrs.disabled}
onClick={this.activateTab(index)} onClick={this.clickTab(index)}
class={classesTab.join(' ')} class={classesTab.join(' ')}
type="button" type="button"
> >

View file

@ -478,7 +478,6 @@
"placeholder": "Dein Benutzername oder die zugehörige E-Mail-Adresse", "placeholder": "Dein Benutzername oder die zugehörige E-Mail-Adresse",
"check_email": "Im E-Mail-Posteingang des angebenen Kontos müsste sich jetzt (oder zumindest in Kürze) die E-Mail mit dem Link zum Passwortzurücksetzen befinden.", "check_email": "Im E-Mail-Posteingang des angebenen Kontos müsste sich jetzt (oder zumindest in Kürze) die E-Mail mit dem Link zum Passwortzurücksetzen befinden.",
"return_home": "Zurück zur Heimseite", "return_home": "Zurück zur Heimseite",
"not_found": "Benutzername/E-Mail-Adresse nicht gefunden. Vertippt?",
"too_many_requests": "Kurze Pause. Zu viele Versuche. Bitte, später nochmal probieren.", "too_many_requests": "Kurze Pause. Zu viele Versuche. Bitte, später nochmal probieren.",
"password_reset_disabled": "Passwortzurücksetzen deaktiviert. Bitte Administrator kontaktieren.", "password_reset_disabled": "Passwortzurücksetzen deaktiviert. Bitte Administrator kontaktieren.",
"password_reset_required": "Passwortzurücksetzen erforderlich.", "password_reset_required": "Passwortzurücksetzen erforderlich.",

View file

@ -774,7 +774,6 @@
"placeholder": "Your email or username", "placeholder": "Your email or username",
"check_email": "Check your email for a link to reset your password.", "check_email": "Check your email for a link to reset your password.",
"return_home": "Return to the home page", "return_home": "Return to the home page",
"not_found": "We couldn't find that email or username.",
"too_many_requests": "You have reached the limit of attempts, try again later.", "too_many_requests": "You have reached the limit of attempts, try again later.",
"password_reset_disabled": "Password reset is disabled. Please contact your instance administrator.", "password_reset_disabled": "Password reset is disabled. Please contact your instance administrator.",
"password_reset_required": "You must reset your password to log in.", "password_reset_required": "You must reset your password to log in.",

View file

@ -776,7 +776,6 @@
"password_reset_required": "Vi devas restarigi vian pasvorton por saluti.", "password_reset_required": "Vi devas restarigi vian pasvorton por saluti.",
"password_reset_disabled": "Restarigado de pasvortoj estas malŝaltita. Bonvolu kontakti la administranton de via nodo.", "password_reset_disabled": "Restarigado de pasvortoj estas malŝaltita. Bonvolu kontakti la administranton de via nodo.",
"too_many_requests": "Vi atingis la limon de provoj, reprovu pli poste.", "too_many_requests": "Vi atingis la limon de provoj, reprovu pli poste.",
"not_found": "Ni ne trovis tiun retpoŝtadreson aŭ uzantonomon.",
"return_home": "Reiri al la hejmpaĝo", "return_home": "Reiri al la hejmpaĝo",
"check_email": "Kontrolu vian retpoŝton pro ligilo por restarigi vian pasvorton.", "check_email": "Kontrolu vian retpoŝton pro ligilo por restarigi vian pasvorton.",
"placeholder": "Via retpoŝtadreso aŭ uzantonomo", "placeholder": "Via retpoŝtadreso aŭ uzantonomo",

View file

@ -624,7 +624,6 @@
"placeholder": "Su correo electrónico o nombre de usuario", "placeholder": "Su correo electrónico o nombre de usuario",
"check_email": "Revise su correo electrónico para obtener un enlace para restablecer su contraseña.", "check_email": "Revise su correo electrónico para obtener un enlace para restablecer su contraseña.",
"return_home": "Volver a la página de inicio", "return_home": "Volver a la página de inicio",
"not_found": "No pudimos encontrar ese correo electrónico o nombre de usuario.",
"too_many_requests": "Has alcanzado el límite de intentos, vuelve a intentarlo más tarde.", "too_many_requests": "Has alcanzado el límite de intentos, vuelve a intentarlo más tarde.",
"password_reset_disabled": "El restablecimiento de contraseñas está deshabilitado. Póngase en contacto con el administrador de su instancia." "password_reset_disabled": "El restablecimiento de contraseñas está deshabilitado. Póngase en contacto con el administrador de su instancia."
} }

View file

@ -626,7 +626,6 @@
"placeholder": "Zure e-posta edo erabiltzaile izena", "placeholder": "Zure e-posta edo erabiltzaile izena",
"check_email": "Begiratu zure posta elektronikoa pasahitza berrezarri ahal izateko.", "check_email": "Begiratu zure posta elektronikoa pasahitza berrezarri ahal izateko.",
"return_home": "Itzuli hasierara", "return_home": "Itzuli hasierara",
"not_found": "Ezin izan dugu helbide elektroniko edo erabiltzaile hori aurkitu.",
"too_many_requests": "Saiakera gehiegi burutu ditzu, saiatu berriro geroxeago.", "too_many_requests": "Saiakera gehiegi burutu ditzu, saiatu berriro geroxeago.",
"password_reset_disabled": "Pasahitza berrezartzea debekatuta dago. Mesedez, jarri harremanetan instantzia administratzailearekin.", "password_reset_disabled": "Pasahitza berrezartzea debekatuta dago. Mesedez, jarri harremanetan instantzia administratzailearekin.",
"password_reset_required": "Pasahitza berrezarri behar duzu saioa hasteko.", "password_reset_required": "Pasahitza berrezarri behar duzu saioa hasteko.",

View file

@ -752,7 +752,6 @@
"password_reset": "Salasanan nollaus", "password_reset": "Salasanan nollaus",
"placeholder": "Sähköpostiosoite tai käyttäjänimi", "placeholder": "Sähköpostiosoite tai käyttäjänimi",
"return_home": "Palaa etusivulle", "return_home": "Palaa etusivulle",
"not_found": "Sähköpostiosoitetta tai käyttäjänimeä ei löytynyt.",
"too_many_requests": "Olet käyttänyt kaikki yritykset, yritä uudelleen myöhemmin.", "too_many_requests": "Olet käyttänyt kaikki yritykset, yritä uudelleen myöhemmin.",
"password_reset_required": "Sinun täytyy vaihtaa salasana kirjautuaksesi." "password_reset_required": "Sinun täytyy vaihtaa salasana kirjautuaksesi."
}, },

View file

@ -730,7 +730,6 @@
"instruction": "Entrer votre address de courriel ou votre nom utilisateur. Nous enverrons un lien pour changer votre mot de passe.", "instruction": "Entrer votre address de courriel ou votre nom utilisateur. Nous enverrons un lien pour changer votre mot de passe.",
"placeholder": "Votre email ou nom d'utilisateur", "placeholder": "Votre email ou nom d'utilisateur",
"return_home": "Retourner à la page d'accueil", "return_home": "Retourner à la page d'accueil",
"not_found": "Email ou nom d'utilisateur inconnu.",
"too_many_requests": "Vos avez atteint la limite d'essais, essayez plus tard.", "too_many_requests": "Vos avez atteint la limite d'essais, essayez plus tard.",
"password_reset_required": "Vous devez changer votre mot de passe pour vous authentifier." "password_reset_required": "Vous devez changer votre mot de passe pour vous authentifier."
} }

View file

@ -745,7 +745,6 @@
"password_reset_required": "Devi reimpostare la tua password per poter continuare.", "password_reset_required": "Devi reimpostare la tua password per poter continuare.",
"password_reset_disabled": "Non puoi azzerare la tua password. Contatta il tuo amministratore.", "password_reset_disabled": "Non puoi azzerare la tua password. Contatta il tuo amministratore.",
"too_many_requests": "Hai raggiunto il numero massimo di tentativi, riprova più tardi.", "too_many_requests": "Hai raggiunto il numero massimo di tentativi, riprova più tardi.",
"not_found": "Non ho trovato questa email o nome utente.",
"return_home": "Torna alla pagina principale", "return_home": "Torna alla pagina principale",
"check_email": "Controlla la tua posta elettronica.", "check_email": "Controlla la tua posta elettronica.",
"placeholder": "La tua email o nome utente", "placeholder": "La tua email o nome utente",

View file

@ -666,7 +666,6 @@
"placeholder": "あなたのメールアドレスかユーザーめい", "placeholder": "あなたのメールアドレスかユーザーめい",
"check_email": "パスワードをリセットするためのリンクがかかれたメールが、とどいているかどうか、みてください。", "check_email": "パスワードをリセットするためのリンクがかかれたメールが、とどいているかどうか、みてください。",
"return_home": "ホームページにもどる", "return_home": "ホームページにもどる",
"not_found": "そのメールアドレスまたはユーザーめいを、みつけることができませんでした。",
"too_many_requests": "パスワードリセットを、ためすことが、おおすぎます。しばらくしてから、ためしてください。", "too_many_requests": "パスワードリセットを、ためすことが、おおすぎます。しばらくしてから、ためしてください。",
"password_reset_disabled": "このインスタンスでは、パスワードリセットは、できません。インスタンスのアドミニストレーターに、おといあわせください。", "password_reset_disabled": "このインスタンスでは、パスワードリセットは、できません。インスタンスのアドミニストレーターに、おといあわせください。",
"password_reset_required": "ログインするには、パスワードをリセットしてください。", "password_reset_required": "ログインするには、パスワードをリセットしてください。",

View file

@ -625,7 +625,6 @@
"placeholder": "メールアドレスまたはユーザー名", "placeholder": "メールアドレスまたはユーザー名",
"check_email": "パスワードをリセットするためのリンクが記載されたメールが届いているか確認してください。", "check_email": "パスワードをリセットするためのリンクが記載されたメールが届いているか確認してください。",
"return_home": "ホームページに戻る", "return_home": "ホームページに戻る",
"not_found": "メールアドレスまたはユーザー名が見つかりませんでした。",
"too_many_requests": "試行回数の制限に達しました。しばらく時間を置いてから再試行してください。", "too_many_requests": "試行回数の制限に達しました。しばらく時間を置いてから再試行してください。",
"password_reset_disabled": "このインスタンスではパスワードリセットは無効になっています。インスタンスの管理者に連絡してください。" "password_reset_disabled": "このインスタンスではパスワードリセットは無効になっています。インスタンスの管理者に連絡してください。"
} }

View file

@ -677,7 +677,6 @@
"password_reset_required": "Je dient je wachtwoord opnieuw in te stellen om in te kunnen loggen.", "password_reset_required": "Je dient je wachtwoord opnieuw in te stellen om in te kunnen loggen.",
"password_reset_disabled": "Wachtwoord reset is uitgeschakeld. Neem contact op met de beheerder van deze instantie.", "password_reset_disabled": "Wachtwoord reset is uitgeschakeld. Neem contact op met de beheerder van deze instantie.",
"too_many_requests": "Je hebt het maximaal aantal pogingen bereikt, probeer het later opnieuw.", "too_many_requests": "Je hebt het maximaal aantal pogingen bereikt, probeer het later opnieuw.",
"not_found": "We kunnen die email of gebruikersnaam niet vinden.",
"return_home": "Terugkeren naar de home pagina", "return_home": "Terugkeren naar de home pagina",
"check_email": "Controleer je email inbox voor een link om je wachtwoord opnieuw in te stellen.", "check_email": "Controleer je email inbox voor een link om je wachtwoord opnieuw in te stellen.",
"placeholder": "Je email of gebruikersnaam", "placeholder": "Je email of gebruikersnaam",

View file

@ -753,7 +753,6 @@
"placeholder": "Twój email lub nazwa użytkownika", "placeholder": "Twój email lub nazwa użytkownika",
"check_email": "Sprawdź pocztę, aby uzyskać link do zresetowania hasła.", "check_email": "Sprawdź pocztę, aby uzyskać link do zresetowania hasła.",
"return_home": "Wróć do strony głównej", "return_home": "Wróć do strony głównej",
"not_found": "Nie mogliśmy znaleźć tego emaila lub nazwy użytkownika.",
"too_many_requests": "Przekroczyłeś(-aś) limit prób, spróbuj ponownie później.", "too_many_requests": "Przekroczyłeś(-aś) limit prób, spróbuj ponownie później.",
"password_reset_disabled": "Resetowanie hasła jest wyłączone. Proszę skontaktuj się z administratorem tej instancji.", "password_reset_disabled": "Resetowanie hasła jest wyłączone. Proszę skontaktuj się z administratorem tej instancji.",
"password_reset_required": "Musisz zresetować hasło, by się zalogować.", "password_reset_required": "Musisz zresetować hasło, by się zalogować.",

View file

@ -420,7 +420,6 @@
"placeholder": "Ваш email или имя пользователя", "placeholder": "Ваш email или имя пользователя",
"check_email": "Проверьте ваш email и перейдите по ссылке для сброса пароля.", "check_email": "Проверьте ваш email и перейдите по ссылке для сброса пароля.",
"return_home": "Вернуться на главную страницу", "return_home": "Вернуться на главную страницу",
"not_found": "Мы не смогли найти аккаунт с таким email-ом или именем пользователя.",
"too_many_requests": "Вы исчерпали допустимое количество попыток, попробуйте позже.", "too_many_requests": "Вы исчерпали допустимое количество попыток, попробуйте позже.",
"password_reset_disabled": "Сброс пароля отключен. Cвяжитесь с администратором вашего сервера." "password_reset_disabled": "Сброс пароля отключен. Cвяжитесь с администратором вашего сервера."
}, },

View file

@ -640,7 +640,6 @@
"placeholder": "你的电邮地址或者用户名", "placeholder": "你的电邮地址或者用户名",
"check_email": "检查你的邮箱,会有一个链接用于重置密码。", "check_email": "检查你的邮箱,会有一个链接用于重置密码。",
"return_home": "回到首页", "return_home": "回到首页",
"not_found": "我们无法找到匹配的邮箱地址或者用户名。",
"too_many_requests": "你触发了尝试的限制,请稍后再试。", "too_many_requests": "你触发了尝试的限制,请稍后再试。",
"password_reset_disabled": "密码重置已经被禁用。请联系你的实例管理员。" "password_reset_disabled": "密码重置已经被禁用。请联系你的实例管理员。"
}, },

View file

@ -3,6 +3,7 @@ import { set, delete as del } from 'vue'
const defaultState = { const defaultState = {
settingsModalState: 'hidden', settingsModalState: 'hidden',
settingsModalLoaded: false, settingsModalLoaded: false,
settingsModalTargetTab: null,
settings: { settings: {
currentSaveStateNotice: null, currentSaveStateNotice: null,
noticeClearTimeout: null, noticeClearTimeout: null,
@ -62,6 +63,9 @@ const interfaceMod = {
state.settingsModalLoaded = true state.settingsModalLoaded = true
} }
}, },
setSettingsModalTargetTab (state, value) {
state.settingsModalTargetTab = value
},
pushGlobalNotice (state, notice) { pushGlobalNotice (state, notice) {
state.globalNotices.push(notice) state.globalNotices.push(notice)
}, },
@ -97,6 +101,13 @@ const interfaceMod = {
togglePeekSettingsModal ({ commit }) { togglePeekSettingsModal ({ commit }) {
commit('togglePeekSettingsModal') commit('togglePeekSettingsModal')
}, },
clearSettingsModalTargetTab ({ commit }) {
commit('setSettingsModalTargetTab', null)
},
openSettingsModalTab ({ commit }, value) {
commit('setSettingsModalTargetTab', value)
commit('openSettingsModal')
},
pushGlobalNotice ( pushGlobalNotice (
{ commit, dispatch }, { commit, dispatch },
{ {

View file

@ -5,7 +5,7 @@ export const replaceWord = (str, toReplace, replacement) => {
} }
export const wordAtPosition = (str, pos) => { export const wordAtPosition = (str, pos) => {
const words = splitIntoWords(str) const words = splitByWhitespaceBoundary(str)
const wordsWithPosition = addPositionToWords(words) const wordsWithPosition = addPositionToWords(words)
return find(wordsWithPosition, ({ start, end }) => start <= pos && end > pos) return find(wordsWithPosition, ({ start, end }) => start <= pos && end > pos)
@ -34,36 +34,36 @@ export const addPositionToWords = (words) => {
}, []) }, [])
} }
export const splitIntoWords = (str) => { export const splitByWhitespaceBoundary = (str) => {
// Split at word boundaries let result = []
const regex = /\b/ let currentWord = ''
const triggers = /[@#:]+$/ for (let i = 0; i < str.length; i++) {
const currentChar = str[i]
let split = str.split(regex) // Starting a new word
if (!currentWord) {
// Add trailing @ and # to the following word. currentWord = currentChar
const words = reduce(split, (result, word) => { continue
if (result.length > 0) {
let previous = result.pop()
const matches = previous.match(triggers)
if (matches) {
previous = previous.replace(triggers, '')
word = matches[0] + word
}
result.push(previous)
} }
result.push(word) // current character is whitespace while word isn't, or vice versa:
// add our current word to results, start over the current word.
return result if (!!currentChar.trim() !== !!currentWord.trim()) {
}, []) result.push(currentWord)
currentWord = currentChar
return words continue
}
currentWord += currentChar
}
// Add the last word we were working on
if (currentWord) {
result.push(currentWord)
}
return result
} }
const completion = { const completion = {
wordAtPosition, wordAtPosition,
addPositionToWords, addPositionToWords,
splitIntoWords, splitByWhitespaceBoundary,
replaceWord replaceWord
} }

View file

@ -1,8 +1,8 @@
import { replaceWord, addPositionToWords, wordAtPosition, splitIntoWords } from '../../../../../src/services/completion/completion.js' import { replaceWord, addPositionToWords, wordAtPosition, splitByWhitespaceBoundary } from '../../../../../src/services/completion/completion.js'
describe('addPositiontoWords', () => { describe('addPositiontoWords', () => {
it('adds the position to a word list', () => { it('adds the position to a word list', () => {
const words = ['hey', 'this', 'is', 'fun'] const words = ['hey', ' ', 'this', ' ', 'is', ' ', 'fun']
const expected = [ const expected = [
{ {
@ -11,19 +11,34 @@ describe('addPositiontoWords', () => {
end: 3 end: 3
}, },
{ {
word: 'this', word: ' ',
start: 3, start: 3,
end: 7 end: 4
}, },
{ {
word: 'is', word: 'this',
start: 7, start: 4,
end: 8
},
{
word: ' ',
start: 8,
end: 9 end: 9
}, },
{ {
word: 'fun', word: 'is',
start: 9, start: 9,
end: 11
},
{
word: ' ',
start: 11,
end: 12 end: 12
},
{
word: 'fun',
start: 12,
end: 15
} }
] ]
@ -33,11 +48,11 @@ describe('addPositiontoWords', () => {
}) })
}) })
describe('splitIntoWords', () => { describe('splitByWhitespaceBoundary', () => {
it('splits at whitespace boundaries', () => { it('splits at whitespace boundaries', () => {
const str = 'This is a #nice @test for you, @idiot.' const str = 'This is a #nice @test for you, @idiot@idiot.com'
const expected = ['This', ' ', 'is', ' ', 'a', ' ', '#nice', ' ', '@test', ' ', 'for', ' ', 'you', ', ', '@idiot', '.'] const expected = ['This', ' ', 'is', ' ', 'a', ' ', '#nice', ' ', '@test', ' ', 'for', ' ', 'you,', ' ', '@idiot@idiot.com']
const res = splitIntoWords(str) const res = splitByWhitespaceBoundary(str)
expect(res).to.eql(expected) expect(res).to.eql(expected)
}) })
@ -57,13 +72,13 @@ describe('wordAtPosition', () => {
describe('replaceWord', () => { describe('replaceWord', () => {
it('replaces a word (with start and end) with another word in a given string', () => { it('replaces a word (with start and end) with another word in a given string', () => {
const str = 'hey @take, how are you' const str = 'hey @take , how are you'
const wordsWithPosition = addPositionToWords(splitIntoWords(str)) const wordsWithPosition = addPositionToWords(splitByWhitespaceBoundary(str))
const toReplace = wordsWithPosition[2] const toReplace = wordsWithPosition[2]
expect(toReplace.word).to.eql('@take') expect(toReplace.word).to.eql('@take')
const expected = 'hey @takeshitakenji, how are you' const expected = 'hey @takeshitakenji , how are you'
const res = replaceWord(str, toReplace, '@takeshitakenji') const res = replaceWord(str, toReplace, '@takeshitakenji')
expect(res).to.eql(expected) expect(res).to.eql(expected)
}) })