From aa5dae391b1e0de23996ddebeda7d15041d1ad0b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 28 Jul 2020 12:58:37 +0900 Subject: [PATCH] Fix handling of unicode characters in query string --- src/terminal.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index c144569..87703d3 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -405,8 +405,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { } renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, false, maxHeightFunc) } - wordRubout := "[^[:alnum:]][[:alnum:]]" - wordNext := "[[:alnum:]][^[:alnum:]]|(.$)" + wordRubout := "[^\\pL\\pN][\\pL\\pN]" + wordNext := "[\\pL\\pN][^\\pL\\pN]|(.$)" if opts.FileWord { sep := regexp.QuoteMeta(string(os.PathSeparator)) wordRubout = fmt.Sprintf("%s[^%s]", sep, sep) @@ -1232,7 +1232,8 @@ func findLastMatch(pattern string, str string) int { if locs == nil { return -1 } - return locs[len(locs)-1][0] + prefix := []rune(str[:locs[len(locs)-1][0]]) + return len(prefix) } func findFirstMatch(pattern string, str string) int { @@ -1244,7 +1245,8 @@ func findFirstMatch(pattern string, str string) int { if loc == nil { return -1 } - return loc[0] + prefix := []rune(str[:loc[0]]) + return len(prefix) } func copySlice(slice []rune) []rune {