Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

メッセージ入力欄でのサジェストにチャンネル名補完を追加 #4436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import { useGroupsStore } from '/@/store/entities/groups'
import { useStampsStore } from '/@/store/entities/stamps'
import useUserList from '/@/composables/users/useUserList'
import { useChannelsStore } from '/@/store/entities/channels'
import useChannelPath from '/@/composables/useChannelPath'

const events: Array<keyof EntityEventMap> = [
'setUser',
Expand All @@ -23,11 +25,14 @@ const events: Array<keyof EntityEventMap> = [
'deleteUserGroup',
'setStamp',
'setStamps',
'deleteStamp'
'deleteStamp',
'addChannel',
'setChannels',
'updateChannel'
]

type WordWithId = {
type: 'user' | 'user-group' | 'stamp'
type: 'user' | 'user-group' | 'stamp' | 'channel'
text: string
id: string
}
Expand All @@ -42,6 +47,8 @@ const useCandidateTree = () => {
const userList = useUserList()
const { userGroupsMap } = useGroupsStore()
const { stampsMap } = useStampsStore()
const { channelsMap } = useChannelsStore()
const { channelIdToPathString } = useChannelPath()

const constructTree = () =>
new TrieTree<Word>(
Expand All @@ -66,6 +73,11 @@ const useCandidateTree = () => {
[...animeEffectSet, ...sizeEffectSet].map(effectName => ({
type: 'stamp-effect',
text: '.' + effectName
})),
[...channelsMap.value.values()].map(channel => ({
type: 'channel',
text: channelIdToPathString(channel.id, true),
id: channel.id
}))
)

Expand All @@ -86,6 +98,11 @@ const useCandidateTree = () => {
return tree
}

const replaceMap: Record<string, string | undefined> = {
'@': '@',
'#': '#'
}

/**
* @param minLength 補完が利用できるようになる最小の文字数
*/
Expand All @@ -97,7 +114,9 @@ const useWordSuggestionList = (
const tree = useCandidateTree()
const candidates = computed(() =>
target.value.word.length >= minLength
? tree.value.search(target.value.word.replaceAll('@', '@'))
? tree.value.search(
target.value.word.replace(/[@#]/g, c => replaceMap[c] ?? c)
)
: []
)
const confirmedPart = computed(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getCurrentWord = (
text: string
): Target => {
const startIndex = elm.selectionStart
const nearest = lastIndexOf(text, ['@', ':', '.'], startIndex - 1)
const nearest = lastIndexOf(text, ['@', ':', '.', '#'], startIndex - 1)
const prevSpaceIndex = lastIndexOf(text, [' ', ' '], startIndex - 1)
if (prevSpaceIndex > nearest) {
return { word: '', begin: 0, end: 0 }
Expand Down
Loading