Use Unicode case folding for author search

This commit is contained in:
Andy Dixon
2026-08-27 09:37:54 +01:00
parent f20a0bea28
commit d787c4a55e
3 changed files with 24 additions and 4 deletions
+1 -1
View File
@@ -6,6 +6,7 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/lipgloss v1.0.0
golang.org/x/text v0.22.0
)
require (
@@ -24,5 +25,4 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
)
+5 -3
View File
@@ -11,6 +11,7 @@ import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"golang.org/x/text/cases"
)
const (
@@ -1246,6 +1247,8 @@ func stageAuthorReplacement(commits []CommitRecord, draftByHash map[string]Commi
if replacementEmail == "" {
return 0, errors.New("replacement author email is required")
}
fold := cases.Fold()
foldedQuery := fold.String(query)
matched := 0
for _, commit := range commits {
draft, ok := draftByHash[commit.Hash]
@@ -1255,9 +1258,8 @@ func stageAuthorReplacement(commits []CommitRecord, draftByHash map[string]Commi
nameMatches := strings.EqualFold(draft.AuthorName, query)
emailMatches := strings.EqualFold(draft.AuthorEmail, query)
if !exact {
lowerQuery := strings.ToLower(query)
nameMatches = strings.Contains(strings.ToLower(draft.AuthorName), lowerQuery)
emailMatches = strings.Contains(strings.ToLower(draft.AuthorEmail), lowerQuery)
nameMatches = strings.Contains(fold.String(draft.AuthorName), foldedQuery)
emailMatches = strings.Contains(fold.String(draft.AuthorEmail), foldedQuery)
}
if !nameMatches && !emailMatches {
continue
+18
View File
@@ -90,6 +90,24 @@ func TestStageAuthorReplacementExactModeRequiresWholeFieldMatch(t *testing.T) {
}
}
func TestStageAuthorReplacementPartialModeUsesUnicodeCaseFolding(t *testing.T) {
commits := []CommitRecord{
{Hash: "greek", AuthorName: "Σωκράτης", AuthorEmail: "socrates@example.com"},
}
drafts := cloneMapByHash(commits)
matched, err := stageAuthorReplacement(commits, drafts, "ΣΩΚΡΆΤΗΣ", "Socrates", "new@example.com", false)
if err != nil {
t.Fatal(err)
}
if matched != 1 {
t.Fatalf("expected Unicode case variants to match, got %d matches", matched)
}
if got := drafts["greek"]; got.AuthorName != "Socrates" || got.AuthorEmail != "new@example.com" {
t.Fatalf("expected Unicode author identity to be replaced, got %#v", got)
}
}
func TestStageAuthorReplacementRejectsBlankInputsWithoutChangingDrafts(t *testing.T) {
commits := []CommitRecord{{Hash: "one", AuthorName: "Foo Bar", AuthorEmail: "foo@bar.baz"}}
tests := []struct {