(props: LineCommentEditorProps)
| 192 | } |
| 193 | |
| 194 | export const LineCommentEditor = (props: LineCommentEditorProps) => { |
| 195 | const i18n = useI18n() |
| 196 | const [split, rest] = splitProps(props, [ |
| 197 | "value", |
| 198 | "selection", |
| 199 | "onInput", |
| 200 | "onCancel", |
| 201 | "onSubmit", |
| 202 | "placeholder", |
| 203 | "rows", |
| 204 | "autofocus", |
| 205 | "cancelLabel", |
| 206 | "submitLabel", |
| 207 | "mention", |
| 208 | ]) |
| 209 | |
| 210 | const refs = { |
| 211 | textarea: undefined as HTMLTextAreaElement | undefined, |
| 212 | } |
| 213 | const [open, setOpen] = createSignal(false) |
| 214 | |
| 215 | function selectMention(item: { path: string } | undefined) { |
| 216 | if (!item) return |
| 217 | |
| 218 | const textarea = refs.textarea |
| 219 | const query = currentMention() |
| 220 | if (!textarea || !query) return |
| 221 | |
| 222 | const value = `${textarea.value.slice(0, query.start)}@${item.path} ${textarea.value.slice(query.end)}` |
| 223 | const cursor = query.start + item.path.length + 2 |
| 224 | |
| 225 | split.onInput(value) |
| 226 | closeMention() |
| 227 | |
| 228 | requestAnimationFrame(() => { |
| 229 | textarea.focus() |
| 230 | textarea.setSelectionRange(cursor, cursor) |
| 231 | }) |
| 232 | } |
| 233 | |
| 234 | const mention = useFilteredList<{ path: string }>({ |
| 235 | items: async (query) => { |
| 236 | if (!split.mention) return [] |
| 237 | if (!query.trim()) return [] |
| 238 | const paths = await split.mention.items(query) |
| 239 | return paths.map((path) => ({ path })) |
| 240 | }, |
| 241 | key: (item) => item.path, |
| 242 | filterKeys: ["path"], |
| 243 | skipFilter: () => true, |
| 244 | onSelect: selectMention, |
| 245 | }) |
| 246 | |
| 247 | const focus = () => refs.textarea?.focus() |
| 248 | const hold: JSX.EventHandlerUnion<HTMLButtonElement, MouseEvent> = (e) => { |
| 249 | e.preventDefault() |
| 250 | e.stopPropagation() |
| 251 | } |
nothing calls this directly
no test coverage detected