mirror of
https://github.com/rivo/tview.git
synced 2024-11-12 19:10:28 +00: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)
|
||||
currentText, _ = i.autocompleteList.GetItemText(newEntry) // Don't trigger changed function twice.
|
||||
currentText = stripTags(currentText)
|
||||
i.SetText(currentText)
|
||||
} else {
|
||||
finish(key)
|
||||
@ -585,6 +586,7 @@ func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p
|
||||
}
|
||||
i.autocompleteList.SetCurrentItem(newEntry)
|
||||
currentText, _ = i.autocompleteList.GetItemText(newEntry) // Don't trigger changed function twice.
|
||||
currentText = stripTags(currentText)
|
||||
i.SetText(currentText)
|
||||
} else {
|
||||
finish(key)
|
||||
|
17
textview.go
17
textview.go
@ -269,13 +269,13 @@ func (t *TextView) SetText(text string) *TextView {
|
||||
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.
|
||||
func (t *TextView) GetText(stripTags bool) string {
|
||||
func (t *TextView) GetText(stripAllTags bool) string {
|
||||
// Get the buffer.
|
||||
buffer := make([]string, len(t.buffer), len(t.buffer)+1)
|
||||
copy(buffer, t.buffer)
|
||||
if !stripTags {
|
||||
if !stripAllTags {
|
||||
buffer = append(buffer, string(t.recentBytes))
|
||||
}
|
||||
|
||||
@ -283,19 +283,14 @@ func (t *TextView) GetText(stripTags bool) string {
|
||||
text := strings.Join(buffer, "\n")
|
||||
|
||||
// Strip from tags if required.
|
||||
if stripTags {
|
||||
if stripAllTags {
|
||||
if t.regions {
|
||||
text = regionPattern.ReplaceAllString(text, "")
|
||||
}
|
||||
if t.dynamicColors {
|
||||
text = colorPattern.ReplaceAllStringFunc(text, func(match string) string {
|
||||
if len(match) > 2 {
|
||||
return ""
|
||||
}
|
||||
return match
|
||||
})
|
||||
text = stripTags(text)
|
||||
}
|
||||
if t.regions || t.dynamicColors {
|
||||
if t.regions && !t.dynamicColors {
|
||||
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
|
||||
}
|
||||
|
||||
// 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…
Reference in New Issue
Block a user