🐛 Input fields are always in focus now - fixes #5

This commit is contained in:
makeworld 2020-06-29 13:30:20 -04:00
parent 5bb62f7a80
commit d81f0aa0b3
4 changed files with 20 additions and 18 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Actual unicode bullet symbol is used for lists: U+2022
- Performance when loading very long cached pages improved (#26)
- Doesn't crash when wrapping certain complex lines (#20)
- Input fields are always in focus when they appear (#5)
## [1.1.0] - 2020-06-24
### Added

View File

@ -8,7 +8,7 @@ import (
"github.com/makeworld-the-better-one/amfora/display"
)
var version = "1.1.0"
var version = "1.2.0-alpha"
func main() {
// err := logger.Init()

View File

@ -65,17 +65,7 @@ func bkmkInit() {
func openBkmkModal(name string, exists bool) (string, int) {
// Basically a copy of Input()
// Remove and re-add input field - to clear the old text
if bkmkModal.GetForm().GetFormItemCount() > 0 {
bkmkModal.GetForm().RemoveFormItem(0)
}
bkmkModalText = ""
bkmkModal.GetForm().AddInputField("Name: ", name, 0, nil,
func(text string) {
// Store for use later
bkmkModalText = text
})
// Reset buttons before input field, to make sure the input is in focus
bkmkModal.ClearButtons()
if exists {
bkmkModal.SetText("Change or remove the bookmark for the current page?")
@ -84,6 +74,16 @@ func openBkmkModal(name string, exists bool) (string, int) {
bkmkModal.SetText("Create a bookmark for the current page?")
bkmkModal.AddButtons([]string{"Add", "Cancel"})
}
// Remove and re-add input field - to clear the old text
bkmkModal.GetForm().Clear(false)
bkmkModalText = ""
bkmkModal.GetForm().AddInputField("Name: ", name, 0, nil,
func(text string) {
// Store for use later
bkmkModalText = text
})
tabPages.ShowPage("bkmk")
tabPages.SendToFront("bkmk")
App.SetFocus(bkmkModal)

View File

@ -22,8 +22,8 @@ var errorModal = cview.NewModal().
AddButtons([]string{"Ok"})
var inputModal = cview.NewModal().
SetTextColor(tcell.ColorWhite).
AddButtons([]string{"Send", "Cancel"})
SetTextColor(tcell.ColorWhite)
//AddButtons([]string{"Send", "Cancel"}) - Added in func
var inputCh = make(chan string)
var inputModalText string // The current text of the input field in the modal
@ -157,10 +157,11 @@ func Info(s string) {
// Input pulls up a modal that asks for input, and returns the user's input.
// It returns an bool indicating if the user chose to send input or not.
func Input(prompt string) (string, bool) {
// Remove and re-add input field - to clear the old text
if inputModal.GetForm().GetFormItemCount() > 0 {
inputModal.GetForm().RemoveFormItem(0)
}
// Remove elements and re-add them - to clear input text and keep input in focus
inputModal.ClearButtons()
inputModal.GetForm().Clear(false)
inputModal.AddButtons([]string{"Send", "Cancel"})
inputModalText = ""
inputModal.GetForm().AddInputField("", "", 0, nil,
func(text string) {