Fixed mouse/keyboard input issues with input fields and forms. Fixes #363

pull/435/head
Oliver 4 years ago
parent 7e599fe9aa
commit e352ec0156

@ -627,6 +627,17 @@ func (f *Form) MouseHandler() func(action MouseAction, event *tcell.EventMouse,
return false, nil
}
// At the end, update f.focusedElement and prepare current item/button.
defer func() {
if consumed {
index := f.focusIndex()
if index >= 0 {
f.focusedElement = index
}
f.Focus(setFocus)
}
}()
// Determine items to pass mouse events to.
for _, item := range f.items {
consumed, capture = item.MouseHandler()(action, event, setFocus)
@ -644,11 +655,6 @@ func (f *Form) MouseHandler() func(action MouseAction, event *tcell.EventMouse,
// A mouse click anywhere else will return the focus to the last selected
// element.
if action == MouseLeftClick {
if f.focusedElement < len(f.items) {
setFocus(f.items[f.focusedElement])
} else if f.focusedElement < len(f.items)+len(f.buttons) {
setFocus(f.buttons[f.focusedElement-len(f.items)])
}
consumed = true
}

@ -606,9 +606,9 @@ func (i *InputField) MouseHandler() func(action MouseAction, event *tcell.EventM
if action == MouseLeftClick && y == rectY {
// Determine where to place the cursor.
if x >= i.fieldX {
if !iterateString(i.text, func(main rune, comb []rune, textPos int, textWidth int, screenPos int, screenWidth int) bool {
if !iterateString(i.text[i.offset:], func(main rune, comb []rune, textPos int, textWidth int, screenPos int, screenWidth int) bool {
if x-i.fieldX < screenPos+screenWidth {
i.cursorPos = textPos
i.cursorPos = textPos + i.offset
return true
}
return false

Loading…
Cancel
Save