Skip to content

Commit

Permalink
add shift+up/down keybinding for selecting range
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Dec 22, 2023
1 parent 03a50b5 commit f9c9d19
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ func (l *List) Resize(s fyne.Size) {

// Select adds the item identified by the given ID to the selection.
func (l *List) Select(id ListItemID) {
for _, selId := range l.selected {
sel := l.selected
for _, selId := range sel {
if id == selId {
return
}
Expand All @@ -207,14 +208,14 @@ func (l *List) Select(id ListItemID) {
if id < 0 || id >= length {
return
}
l.selected = append(l.selected, id)
l.selected = append(sel, id)
defer func() {
if f := l.OnSelected; f != nil {
f(id)
}
}()
l.scrollTo(id)
l.Refresh()
l.RefreshItem(id)
}

// SelectOnly selects only the item identified by the given ID to the selection,
Expand Down Expand Up @@ -371,6 +372,16 @@ func (l *List) ScrollToTop() {
//
// Implements: fyne.Focusable
func (l *List) TypedKey(event *fyne.KeyEvent) {
selectOrFocus := func() {
d, ok := fyne.CurrentApp().Driver().(desktop.Driver)
if ok && d.CurrentKeyModifiers()&fyne.KeyModifierShift > 0 {
l.Select(l.currentFocus)
} else {
l.scrollTo(l.currentFocus)
l.RefreshItem(l.currentFocus)
}
}

switch event.Name {
case fyne.KeySpace:
if sel := l.SelectionMode; sel == SelectionSingle {
Expand All @@ -384,16 +395,14 @@ func (l *List) TypedKey(event *fyne.KeyEvent) {
}
l.RefreshItem(l.currentFocus)
l.currentFocus++
l.scrollTo(l.currentFocus)
l.RefreshItem(l.currentFocus)
selectOrFocus()
case fyne.KeyUp:
if l.currentFocus <= 0 {
return
}
l.RefreshItem(l.currentFocus)
l.currentFocus--
l.scrollTo(l.currentFocus)
l.RefreshItem(l.currentFocus)
selectOrFocus()
}
}

Expand Down

0 comments on commit f9c9d19

Please sign in to comment.