Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(search): use rune-based snippet slicing and fix dialog a11y

yushenb484b78cbdca
diff --git a/apps/web/features/search/components/search-command.tsx b/apps/web/features/search/components/search-command.tsx
index b7d12e4404..3bfb8ddbe9 100644
--- a/apps/web/features/search/components/search-command.tsx
+++ b/apps/web/features/search/components/search-command.tsx
@@ -37,6 +37,14 @@ export function SearchCommand() {
return () => document.removeEventListener("keydown", handleKeyDown);
}, []);
+ // Cleanup debounce/abort on unmount
+ useEffect(() => {
+ return () => {
+ if (debounceRef.current) clearTimeout(debounceRef.current);
+ if (abortRef.current) abortRef.current.abort();
+ };
+ }, []);
+
// Reset state when dialog closes
useEffect(() => {
if (!open) {
@@ -97,16 +105,16 @@ export function SearchCommand() {
return (
<Dialog open={open} onOpenChange={setOpen}>
- <DialogHeader className="sr-only">
- <DialogTitle>Search Issues</DialogTitle>
- <DialogDescription>
- Search issues by title, description, or comments
- </DialogDescription>
- </DialogHeader>
<DialogContent
className="top-[20%] translate-y-0 overflow-hidden rounded-xl! p-0 sm:max-w-xl!"
showCloseButton={false}
>
+ <DialogHeader className="sr-only">
+ <DialogTitle>Search Issues</DialogTitle>
+ <DialogDescription>
+ Search issues by title, description, or comments
+ </DialogDescription>
+ </DialogHeader>
<CommandPrimitive
shouldFilter={false}
className="flex size-full flex-col overflow-hidden rounded-xl bg-popover text-popover-foreground"
diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.go
index 2affdb36bf..e08f30a224 100644
--- a/server/internal/handler/issue.go
+++ b/server/internal/handler/issue.go
@@ -71,13 +71,31 @@ type SearchIssueResponse struct {
}
// extractSnippet extracts a snippet of text around the first occurrence of query.
-// Returns up to ~120 chars centered on the match.
+// Returns up to ~120 runes centered on the match. Uses rune-based slicing to
+// avoid splitting multi-byte UTF-8 characters (important for CJK content).
func extractSnippet(content, query string) string {
- lower := strings.ToLower(content)
- idx := strings.Index(lower, strings.ToLower(query))
+ runes := []rune(content)
+ lowerRunes := []rune(strings.ToLower(content))
+ queryRunes := []rune(strings.ToLower(query))
+
+ idx := -1
+ for i := 0; i <= len(lowerRunes)-len(queryRunes); i++ {
+ match := true
+ for j := range queryRunes {
+ if lowerRunes[i+j] != queryRunes[j] {
+ match = false
+ break
+ }
+ }
+ if match {
+ idx = i
+ break
+ }
+ }
+
if idx < 0 {
- if len(content) > 120 {
- return content[:120] + "..."
+ if len(runes) > 120 {
+ return string(runes[:120]) + "..."
}
return content
}
@@ -85,15 +103,15 @@ func extractSnippet(content, query string) string {
if start < 0 {
start = 0
}
- end := idx + len(query) + 80
- if end > len(content) {
- end = len(content)
+ end := idx + len(queryRunes) + 80
+ if end > len(runes) {
+ end = len(runes)
}
- snippet := content[start:end]
+ snippet := string(runes[start:end])
if start > 0 {
snippet = "..." + snippet
}
- if end < len(content) {
+ if end < len(runes) {
snippet = snippet + "..."
}
return snippet