Skip to content

Commit

Permalink
feat(clipboard): update selection style instead of re-populating list
Browse files Browse the repository at this point in the history
  • Loading branch information
ventsislav-georgiev committed Jan 13, 2024
1 parent 8d00dda commit 96da864
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions pkg/tools/cb/cb.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ var (
clipSize fyne.Size
)

var (
clipStyle = widget.RichTextStyle{
ColorName: theme.ColorNamePlaceHolder,
Inline: false,
SizeName: theme.SizeNameCaptionText,
TextStyle: fyne.TextStyle{Monospace: true},
}
selectedClipStyle = widget.RichTextStyle{
ColorName: theme.ColorNameForeground,
Inline: false,
SizeName: theme.SizeNameCaptionText,
TextStyle: fyne.TextStyle{Monospace: true},
}
)

func init() {
var err error

Expand Down Expand Up @@ -129,8 +144,23 @@ func Show() {
if results[selection] == "" {
selection = 0
}
list.Objects = make([]fyne.CanvasObject, 0, histViewCount)
populateList(results, list, copyAndClose, selection)

for i, v := range list.Objects {
border := v.(*fyne.Container)
clipContainer := border.Objects[0].(*fyneh.FixedContainer)
label := clipContainer.Content.(*widget.RichText)
textSegment := label.Segments[0].(*widget.TextSegment)

style := clipStyle
if i == selection {
style = selectedClipStyle
}

if textSegment.Style != style {
textSegment.Style = style
label.Refresh()
}
}
}
bag["updateSelection"] = updateSelection

Expand Down Expand Up @@ -211,21 +241,6 @@ func Show() {
w.SetFixedSize(true)
}

var (
clipStyle = widget.RichTextStyle{
ColorName: theme.ColorNamePlaceHolder,
Inline: false,
SizeName: theme.SizeNameCaptionText,
TextStyle: fyne.TextStyle{Monospace: true},
}
selectedClipStyle = widget.RichTextStyle{
ColorName: theme.ColorNameForeground,
Inline: false,
SizeName: theme.SizeNameCaptionText,
TextStyle: fyne.TextStyle{Monospace: true},
}
)

func populateList(history []string, list *fyne.Container, copyAndClose func(i int) bool, selection int) {
newLabel := func(t string, style widget.RichTextStyle) *widget.RichText {
w := widget.NewRichText(&widget.TextSegment{
Expand Down

0 comments on commit 96da864

Please sign in to comment.