mirror of
https://github.com/rivo/tview.git
synced 2025-04-28 13:48:53 +08:00
Selected autocomplete items should be used without colour tags. Fixes #472
This commit is contained in:
parent
9b49eb3fef
commit
42866ecf6c
@ -573,6 +573,7 @@ func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p
|
|||||||
}
|
}
|
||||||
i.autocompleteList.SetCurrentItem(newEntry)
|
i.autocompleteList.SetCurrentItem(newEntry)
|
||||||
currentText, _ = i.autocompleteList.GetItemText(newEntry) // Don't trigger changed function twice.
|
currentText, _ = i.autocompleteList.GetItemText(newEntry) // Don't trigger changed function twice.
|
||||||
|
currentText = stripTags(currentText)
|
||||||
i.SetText(currentText)
|
i.SetText(currentText)
|
||||||
} else {
|
} else {
|
||||||
finish(key)
|
finish(key)
|
||||||
@ -585,6 +586,7 @@ func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p
|
|||||||
}
|
}
|
||||||
i.autocompleteList.SetCurrentItem(newEntry)
|
i.autocompleteList.SetCurrentItem(newEntry)
|
||||||
currentText, _ = i.autocompleteList.GetItemText(newEntry) // Don't trigger changed function twice.
|
currentText, _ = i.autocompleteList.GetItemText(newEntry) // Don't trigger changed function twice.
|
||||||
|
currentText = stripTags(currentText)
|
||||||
i.SetText(currentText)
|
i.SetText(currentText)
|
||||||
} else {
|
} else {
|
||||||
finish(key)
|
finish(key)
|
||||||
|
17
textview.go
17
textview.go
@ -269,13 +269,13 @@ func (t *TextView) SetText(text string) *TextView {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetText returns the current text of this text view. If "stripTags" is set
|
// GetText returns the current text of this text view. If "stripAllTags" is set
|
||||||
// to true, any region/color tags are stripped from the text.
|
// to true, any region/color tags are stripped from the text.
|
||||||
func (t *TextView) GetText(stripTags bool) string {
|
func (t *TextView) GetText(stripAllTags bool) string {
|
||||||
// Get the buffer.
|
// Get the buffer.
|
||||||
buffer := make([]string, len(t.buffer), len(t.buffer)+1)
|
buffer := make([]string, len(t.buffer), len(t.buffer)+1)
|
||||||
copy(buffer, t.buffer)
|
copy(buffer, t.buffer)
|
||||||
if !stripTags {
|
if !stripAllTags {
|
||||||
buffer = append(buffer, string(t.recentBytes))
|
buffer = append(buffer, string(t.recentBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,19 +283,14 @@ func (t *TextView) GetText(stripTags bool) string {
|
|||||||
text := strings.Join(buffer, "\n")
|
text := strings.Join(buffer, "\n")
|
||||||
|
|
||||||
// Strip from tags if required.
|
// Strip from tags if required.
|
||||||
if stripTags {
|
if stripAllTags {
|
||||||
if t.regions {
|
if t.regions {
|
||||||
text = regionPattern.ReplaceAllString(text, "")
|
text = regionPattern.ReplaceAllString(text, "")
|
||||||
}
|
}
|
||||||
if t.dynamicColors {
|
if t.dynamicColors {
|
||||||
text = colorPattern.ReplaceAllStringFunc(text, func(match string) string {
|
text = stripTags(text)
|
||||||
if len(match) > 2 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return match
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if t.regions || t.dynamicColors {
|
if t.regions && !t.dynamicColors {
|
||||||
text = escapePattern.ReplaceAllString(text, `[$1$2]`)
|
text = escapePattern.ReplaceAllString(text, `[$1$2]`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
util.go
12
util.go
@ -628,3 +628,15 @@ func iterateStringReverse(text string, callback func(main rune, comb []rune, tex
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stripTags strips colour tags from the given string. (Region tags are not
|
||||||
|
// stripped.)
|
||||||
|
func stripTags(text string) string {
|
||||||
|
stripped := colorPattern.ReplaceAllStringFunc(text, func(match string) string {
|
||||||
|
if len(match) > 2 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return match
|
||||||
|
})
|
||||||
|
return escapePattern.ReplaceAllString(stripped, `[$1$2]`)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user