ソースを参照

feat(config): add keys.guilds_tree.yank (#508)

Co-authored-by: ayn2op <ayn2op@mac.local>
Ayyan 1 年間 前
コミット
bad44a4490
2 ファイル変更15 行追加0 行削除
  1. 13 0
      cmd/guilds_tree.go
  2. 2 0
      internal/config/keys.go

+ 13 - 0
cmd/guilds_tree.go

@@ -6,6 +6,7 @@ import (
 	"sort"
 	"strings"
 
+	"github.com/atotto/clipboard"
 	"github.com/ayn2op/discordo/internal/config"
 	"github.com/diamondburned/arikawa/v3/discord"
 	"github.com/diamondburned/arikawa/v3/gateway"
@@ -237,6 +238,18 @@ func (gt *GuildsTree) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
 
 	case gt.cfg.Keys.GuildsTree.SelectCurrent:
 		return tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone)
+
+	case gt.cfg.Keys.GuildsTree.YankID:
+		node := gt.GetCurrentNode()
+		if node == nil {
+			return nil
+		}
+
+		// Reference of a tree node in the guilds tree is its ID.
+		// discord.Snowflake (discord.GuildID and discord.ChannelID) have the String method.
+		if id, ok := node.GetReference().(fmt.Stringer); ok {
+			go clipboard.WriteAll(id.String())
+		}
 	}
 
 	return nil

+ 2 - 0
internal/config/keys.go

@@ -25,6 +25,7 @@ type (
 	GuildsTreeKeys struct {
 		NavigationKeys
 		SelectCurrent string `toml:"select_current"`
+		YankID        string `toml:"yank_id"`
 	}
 
 	MessagesTextKeys struct {
@@ -64,6 +65,7 @@ func defaultKeys() Keys {
 				SelectLast:     "Rune[G]",
 			},
 			SelectCurrent: "Enter",
+			YankID:        "Rune[y]",
 		},
 
 		MessagesText: MessagesTextKeys{