Просмотр исходного кода

Rewrite MessageInput to use TextArea (#316)

ayn2op 2 лет назад
Родитель
Сommit
e363f208e9
3 измененных файлов с 16 добавлено и 26 удалено
  1. 14 19
      cmd/run/message_input.go
  2. 2 6
      config/keys.go
  3. 0 1
      docs/configuration.md

+ 14 - 19
cmd/run/message_input.go

@@ -16,17 +16,24 @@ import (
 )
 )
 
 
 type MessageInput struct {
 type MessageInput struct {
-	*tview.InputField
+	*tview.TextArea
 }
 }
 
 
 func newMessageInput() *MessageInput {
 func newMessageInput() *MessageInput {
 	mi := &MessageInput{
 	mi := &MessageInput{
-		InputField: tview.NewInputField(),
+		TextArea: tview.NewTextArea(),
 	}
 	}
 
 
+	mi.SetTextStyle(tcell.StyleDefault.Background(tcell.GetColor(config.Current.Theme.BackgroundColor)))
+	mi.SetClipboard(func(s string) {
+		_ = clipboard.WriteAll(s)
+	}, func() string {
+		text, _ := clipboard.ReadAll()
+		return text
+	})
+
 	mi.SetInputCapture(mi.onInputCapture)
 	mi.SetInputCapture(mi.onInputCapture)
 	mi.SetBackgroundColor(tcell.GetColor(config.Current.Theme.BackgroundColor))
 	mi.SetBackgroundColor(tcell.GetColor(config.Current.Theme.BackgroundColor))
-	mi.SetFieldBackgroundColor(tcell.GetColor(config.Current.Theme.BackgroundColor))
 
 
 	mi.SetTitleColor(tcell.GetColor(config.Current.Theme.TitleColor))
 	mi.SetTitleColor(tcell.GetColor(config.Current.Theme.TitleColor))
 	mi.SetTitleAlign(tview.AlignLeft)
 	mi.SetTitleAlign(tview.AlignLeft)
@@ -41,7 +48,7 @@ func newMessageInput() *MessageInput {
 
 
 func (mi *MessageInput) reset() {
 func (mi *MessageInput) reset() {
 	mi.SetTitle("")
 	mi.SetTitle("")
-	mi.SetText("")
+	mi.SetText("", true)
 }
 }
 
 
 func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
 func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
@@ -49,9 +56,8 @@ func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
 	case config.Current.Keys.MessageInput.Send:
 	case config.Current.Keys.MessageInput.Send:
 		mi.sendAction()
 		mi.sendAction()
 		return nil
 		return nil
-	case config.Current.Keys.MessageInput.Paste:
-		mi.pasteAction()
-		return nil
+	case "Alt+Enter":
+		return tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone)
 	case config.Current.Keys.MessageInput.LaunchEditor:
 	case config.Current.Keys.MessageInput.LaunchEditor:
 		mainFlex.messageInput.launchEditorAction()
 		mainFlex.messageInput.launchEditorAction()
 		return nil
 		return nil
@@ -100,17 +106,6 @@ func (mi *MessageInput) sendAction() {
 	mi.reset()
 	mi.reset()
 }
 }
 
 
-func (mi *MessageInput) pasteAction() {
-	text, err := clipboard.ReadAll()
-	if err != nil {
-		log.Println(err)
-		return
-	}
-
-	// Append the text to the message input.
-	mi.SetText(mi.GetText() + text)
-}
-
 func (mi *MessageInput) launchEditorAction() {
 func (mi *MessageInput) launchEditorAction() {
 	e := config.Current.Editor
 	e := config.Current.Editor
 	if e == "default" {
 	if e == "default" {
@@ -129,5 +124,5 @@ func (mi *MessageInput) launchEditorAction() {
 		}
 		}
 	})
 	})
 
 
-	mi.SetText(b.String())
+	mi.SetText(b.String(), true)
 }
 }

+ 2 - 6
config/keys.go

@@ -25,9 +25,7 @@ type (
 	MessageInputKeys struct {
 	MessageInputKeys struct {
 		Focus string `yaml:"focus"`
 		Focus string `yaml:"focus"`
 
 
-		Send  string `yaml:"send"`
-		Paste string `yaml:"paste"`
-
+		Send         string `yaml:"send"`
 		LaunchEditor string `yaml:"launch_editor"`
 		LaunchEditor string `yaml:"launch_editor"`
 	}
 	}
 )
 )
@@ -68,9 +66,7 @@ func defKeys() Keys {
 		MessageInput: MessageInputKeys{
 		MessageInput: MessageInputKeys{
 			Focus: "Alt+Rune[i]",
 			Focus: "Alt+Rune[i]",
 
 
-			Send: "Enter",
-
-			Paste:        "Ctrl+V",
+			Send:         "Enter",
 			LaunchEditor: "Ctrl+E",
 			LaunchEditor: "Ctrl+E",
 		},
 		},
 	}
 	}

+ 0 - 1
docs/configuration.md

@@ -35,5 +35,4 @@ Keybindings are configurable in the [configuration file](#configuration).
 | **Message Input**     |            |
 | **Message Input**     |            |
 | Focus                 | Alt + i    |
 | Focus                 | Alt + i    |
 | Send message          | Enter      |
 | Send message          | Enter      |
-| Paste from clipboard  | Ctrl + v   |
 | Launch editor         | Ctrl + e   |
 | Launch editor         | Ctrl + e   |