Explorar el Código

refactor(cmd): add/remove mentions list page instead

ayn2op hace 10 meses
padre
commit
ba458ca972
Se han modificado 2 ficheros con 14 adiciones y 7 borrados
  1. 3 5
      cmd/application.go
  2. 11 2
      cmd/message_input.go

+ 3 - 5
cmd/application.go

@@ -103,9 +103,7 @@ func (a *application) init() {
 	a.flex.
 		AddItem(a.guildsTree, 0, 1, true).
 		AddItem(right, 0, 4, false)
-	a.pages.
-		AddAndSwitchToPage(flexPageName, a.flex, true).
-		AddPage(mentionsListPageName, a.messageInput.autocomplete, false, false)
+	a.pages.AddAndSwitchToPage(flexPageName, a.flex, true)
 }
 
 func (a *application) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
@@ -124,11 +122,11 @@ func (a *application) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
 func (a *application) onFlexInputCapture(event *tcell.EventKey) *tcell.EventKey {
 	switch event.Name() {
 	case a.cfg.Keys.FocusGuildsTree:
-		a.pages.HidePage(mentionsListPageName)
+		a.messageInput.removeMentionsList()
 		a.SetFocus(app.guildsTree)
 		return nil
 	case a.cfg.Keys.FocusMessagesText:
-		a.pages.HidePage(mentionsListPageName)
+		a.messageInput.removeMentionsList()
 		a.SetFocus(app.messagesText)
 		return nil
 	case a.cfg.Keys.FocusMessageInput:

+ 11 - 2
cmd/message_input.go

@@ -371,7 +371,10 @@ func (mi *messageInput) showMentionList(col int) {
 		x += min(col, maxW-w)
 	}
 	l.SetRect(x, y, w, h)
-	app.pages.ShowPage(mentionsListPageName)
+
+	app.pages.
+		AddAndSwitchToPage(mentionsListPageName, l, false).
+		ShowPage(flexPageName)
 	app.SetFocus(mi)
 }
 
@@ -414,10 +417,16 @@ func (mi *messageInput) addAutocompleteItem(gID discord.GuildID, m *discord.Memb
 	return mi.autocomplete.GetItemCount() > int(mi.cfg.AutocompleteLimit)
 }
 
+func (mi *messageInput) removeMentionsList() {
+	app.pages.
+		RemovePage(mentionsListPageName).
+		SwitchToPage(flexPageName)
+}
+
 func (mi *messageInput) stopTabCompletion() {
 	if mi.cfg.AutocompleteLimit > 0 {
-		app.pages.HidePage(mentionsListPageName)
 		mi.autocomplete.Clear()
+		mi.removeMentionsList()
 		app.SetFocus(mi)
 	}
 }