fix(selector): only escape newlines
Previously we were also escaping unneeded stuff like tabs, etc.
This commit is contained in:
parent
1d9de528ed
commit
e0e1c47c0a
1 changed files with 10 additions and 10 deletions
18
selector.go
18
selector.go
|
@ -65,8 +65,8 @@ func selector(data []string, max int, tool string) (string, error) {
|
|||
|
||||
// preprocessData:
|
||||
// - reverses the data
|
||||
// - escapes special characters (like newlines) that would break external selectors;
|
||||
// - optionally it cuts items longer than 400 bytes (dmenu doesn't allow more than ~1200).
|
||||
// - escapes \n (it would break external selectors)
|
||||
// - optionally it cuts items longer than 400 bytes (dmenu doesn't allow more than ~1200)
|
||||
// A guide is created to allow restoring the selected item.
|
||||
func preprocessData(data []string, cutting bool) ([]string, map[string]string) {
|
||||
var escaped []string
|
||||
|
@ -75,15 +75,15 @@ func preprocessData(data []string, cutting bool) ([]string, map[string]string) {
|
|||
for i := len(data) - 1; i >= 0; i-- { // reverse slice
|
||||
original := data[i]
|
||||
|
||||
repr := fmt.Sprintf("%#v", original)
|
||||
size := len(repr) - 1
|
||||
if cutting {
|
||||
// escape newlines
|
||||
repr := strings.ReplaceAll(original, "\\n", "\\\\n") // preserve literal \n
|
||||
repr = strings.ReplaceAll(repr, "\n", "\\n")
|
||||
|
||||
// optionally cut to maxChars
|
||||
const maxChars = 400
|
||||
if size > maxChars {
|
||||
size = maxChars
|
||||
if cutting && len(repr) > maxChars {
|
||||
repr = repr[:maxChars]
|
||||
}
|
||||
}
|
||||
repr = repr[1:size] // drop left and right quotes
|
||||
|
||||
guide[repr] = original
|
||||
escaped = append(escaped, repr)
|
||||
|
|
Loading…
Reference in a new issue