From 8e6f89a59a6ccaae378e81ad6226eb051d59b803 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 11 Mar 2021 22:42:46 +0200 Subject: [PATCH] Fix newline keybind toggle --- config/config.go | 2 +- ui/commands.go | 22 ++++++++++++++++++---- ui/room-view.go | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 243bfe1..5192dce 100644 --- a/config/config.go +++ b/config/config.go @@ -52,7 +52,7 @@ type UserPreferences struct { DisableDownloads bool `yaml:"disable_downloads"` DisableNotifications bool `yaml:"disable_notifications"` DisableShowURLs bool `yaml:"disable_show_urls"` - NewLineByDefault bool `yaml:"new_line_by_default"` + AltEnterToSend bool `yaml:"alt_enter_to_send"` } // Config contains the main config of gomuks. diff --git a/ui/commands.go b/ui/commands.go index 49770a2..454686f 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -550,8 +550,8 @@ func cmdPrivateMessage(cmd *Command) { } } req := &mautrix.ReqCreateRoom{ - Preset: "trusted_private_chat", - Invite: invites, + Preset: "trusted_private_chat", + Invite: invites, IsDirect: true, } room, err := cmd.Matrix.CreateRoom(req) @@ -686,6 +686,20 @@ func (stm SimpleToggleMessage) Name() string { return string(unicode.ToUpper(rune(stm[0]))) + string(stm[1:]) } +type NewlineKeybindMessage string + +func (nkm NewlineKeybindMessage) Format(state bool) string { + if state { + return "Now using to create new line and to send" + } else { + return "Now using to send and to create new line" + } +} + +func (nkm NewlineKeybindMessage) Name() string { + return string(nkm) +} + var toggleMsg = map[string]ToggleMessage{ "rooms": HideMessage("Room list sidebar"), "users": HideMessage("User list sidebar"), @@ -699,7 +713,7 @@ var toggleMsg = map[string]ToggleMessage{ "notifications": SimpleToggleMessage("desktop notifications"), "unverified": SimpleToggleMessage("sending messages to unverified devices"), "showurls": SimpleToggleMessage("show URLs in text format"), - "newline": SimpleToggleMessage("use to create new line and to send"), + "newline": NewlineKeybindMessage("should make a new line or send the message"), } func makeUsage() string { @@ -745,7 +759,7 @@ func cmdToggle(cmd *Command) { case "showurls": val = &cmd.Config.Preferences.DisableShowURLs case "newline": - val = &cmd.Config.Preferences.NewLineByDefault + val = &cmd.Config.Preferences.AltEnterToSend default: cmd.Reply("Unknown toggle %s. Use /toggle without arguments for a list of togglable things.", thing) return diff --git a/ui/room-view.go b/ui/room-view.go index 9098826..5978ac3 100644 --- a/ui/room-view.go +++ b/ui/room-view.go @@ -374,7 +374,7 @@ func (view *RoomView) OnKeyEvent(event mauview.KeyEvent) bool { msgView.AddScrollOffset(-msgView.Height() / 2) return true case tcell.KeyEnter: - if (event.Modifiers()&tcell.ModShift == 0 && event.Modifiers()&tcell.ModCtrl == 0) == (view.config.Preferences.NewLineByDefault) { + if (event.Modifiers()&tcell.ModShift == 0 && event.Modifiers()&tcell.ModCtrl == 0) != (view.config.Preferences.AltEnterToSend) { view.InputSubmit(view.input.GetText()) return true }