MCPcopy
hub / github.com/anomalyco/opencode / LineCommentEditor

Function LineCommentEditor

packages/session-ui/src/components/line-comment.tsx:194–439  ·  view source on GitHub ↗
(props: LineCommentEditorProps)

Source from the content-addressed store, hash-verified

192}
193
194export 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 }

Callers

nothing calls this directly

Calls 13

useI18nFunction · 0.90
useFilteredListFunction · 0.90
getDirectoryFunction · 0.90
getFilenameFunction · 0.90
syncMentionFunction · 0.85
closeMentionFunction · 0.85
selectActiveMentionFunction · 0.85
selectMentionFunction · 0.85
clickFunction · 0.85
activeMethod · 0.80
focusFunction · 0.70
openFunction · 0.70

Tested by

no test coverage detected