[GH-ISSUE #92] Paste content is truncated #71

Closed
opened 2026-03-04 01:01:39 +03:00 by kerem · 6 comments
Owner

Originally created by @soyking on GitHub (Mar 30, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/92

I wrote a simple demo, and run on my mac:

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	input := tview.NewInputField().SetLabel("paste long text: ")
	if err := app.SetRoot(input, true).Run(); err != nil {
		panic(err)
	}
}

And I tried to copy 123456789123456789 and pasted it on input field, but only got 12345678912. So is it possible that the content is truncated in some where?

Originally created by @soyking on GitHub (Mar 30, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/92 I wrote a simple demo, and run on my mac: ``` package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() input := tview.NewInputField().SetLabel("paste long text: ") if err := app.SetRoot(input, true).Run(); err != nil { panic(err) } } ``` And I tried to copy `123456789123456789` and pasted it on input field, but only got `12345678912`. So is it possible that the content is truncated in some where?
kerem closed this issue 2026-03-04 01:01:39 +03:00
Author
Owner

@stephencheng commented on GitHub (Mar 30, 2018):

I tested your code, yes, it seems only paste 11 chars.

Btw, this is not related to your problem, but it's related to the input field too. I noticed that I can't move cursor to the middle of input. I guess this might be no arrow key binding was implemented yet to handle it. I am all right with it.

<!-- gh-comment-id:377536433 --> @stephencheng commented on GitHub (Mar 30, 2018): I tested your code, yes, it seems only paste 11 chars. Btw, this is not related to your problem, but it's related to the input field too. I noticed that I can't move cursor to the middle of input. I guess this might be no arrow key binding was implemented yet to handle it. I am all right with it.
Author
Owner

@rivo commented on GitHub (Apr 1, 2018):

To be honest, I noticed the pasting issue, too, and this seems to be a limitation of tcell. It's still on my todo list to open an issue there but I've been wanting to test if this happens on platforms other than macOS, too. What platforms have you noticed this on?

(And yes, the InputField currently puts the cursor only at the end. This might change at some point in the future.)

<!-- gh-comment-id:377768991 --> @rivo commented on GitHub (Apr 1, 2018): To be honest, I noticed the pasting issue, too, and this seems to be a limitation of [tcell](https://github.com/gdamore/tcell). It's still on my todo list to open an issue there but I've been wanting to test if this happens on platforms other than macOS, too. What platforms have you noticed this on? (And yes, the `InputField` currently puts the cursor only at the end. This might change at some point in the future.)
Author
Owner

@soyking commented on GitHub (Apr 2, 2018):

Hi, I tested it on Ubuntu 16.04 running on VirtualBox, and it still happened.

<!-- gh-comment-id:377840693 --> @soyking commented on GitHub (Apr 2, 2018): Hi, I tested it on Ubuntu 16.04 running on VirtualBox, and it still happened.
Author
Owner

@soyking commented on GitHub (Apr 2, 2018):

I tracked the code and found that tcell limit the event channel length in https://github.com/gdamore/tcell/blob/master/tscreen.go#L112. So I tried to change 10 to 20 and of course it worked.

By the way, searching make(chan Event, 10) could find more.

<!-- gh-comment-id:377844998 --> @soyking commented on GitHub (Apr 2, 2018): I tracked the code and found that tcell limit the event channel length in https://github.com/gdamore/tcell/blob/master/tscreen.go#L112. So I tried to change 10 to 20 and of course it worked. By the way, searching `make(chan Event, 10)` could find more.
Author
Owner

@rivo commented on GitHub (Apr 4, 2018):

I'll close this issue as we'll be tracking it through tcell. I often paste text into the console, which is why I noticed this very early on. I'm also hoping he'll take the time to fix this, even without a few thousand dollars. ;-)

(I know what it's like, though. A paid job always gets priority attention. It's no different here.)

<!-- gh-comment-id:378739200 --> @rivo commented on GitHub (Apr 4, 2018): I'll close this issue as we'll be tracking it through `tcell`. I often paste text into the console, which is why I noticed this very early on. I'm also hoping he'll take the time to fix this, even without a few thousand dollars. ;-) (I know what it's like, though. A paid job always gets priority attention. It's no different here.)
Author
Owner

@mtartare commented on GitHub (Aug 6, 2020):

This issue was partially fixed in tcell but is still present on Windows (see https://github.com/gdamore/tcell/issues/319).
Waiting for a proper fix, here is a (hacky) workaround, using the clipboard package:

// Hacky solution for a working copy paste on Windows
// Breaks encapsulation by accessing a private member using reflect
// Applies to all InputFields of a Form
for i := 0; i < queryForm.GetFormItemCount(); i++ {
		queryForm.GetFormItem(i).(*tview.InputField).SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
			if event.Key() == tcell.KeyCtrlV || event.Key() == tcell.KeyCtrlY {
				clipContent, _ := clipboard.ReadAll()
				idx, _ := queryForm.GetFocusedItemIndex()
				inputField := queryForm.GetFormItem(idx).(*tview.InputField)
				val := reflect.ValueOf(*inputField)
				cursorPos := val.FieldByName("cursorPos").Int()
				text := inputField.GetText()
				newText := text[0:cursorPos] + clipContent + text[cursorPos:]
				queryForm.GetFormItem(idx).(*tview.InputField).SetText(newText)
			}
			return event
		})
}

Note that without getter for the cursorPos member I had to break encapsulation to access the position of the cursor to be able to insert the paste at the right position. A cleaner solution would require a proper accessor:
func (i *InputField) GetCursorPos() int

Could be a temporary solution to https://github.com/SoMuchForSubtlety/f1viewer/issues/74 @SoMuchForSubtlety.

<!-- gh-comment-id:670208053 --> @mtartare commented on GitHub (Aug 6, 2020): This issue was partially fixed in tcell but is still present on Windows (see https://github.com/gdamore/tcell/issues/319). Waiting for a proper fix, here is a (hacky) workaround, using the clipboard package: ``` // Hacky solution for a working copy paste on Windows // Breaks encapsulation by accessing a private member using reflect // Applies to all InputFields of a Form for i := 0; i < queryForm.GetFormItemCount(); i++ { queryForm.GetFormItem(i).(*tview.InputField).SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyCtrlV || event.Key() == tcell.KeyCtrlY { clipContent, _ := clipboard.ReadAll() idx, _ := queryForm.GetFocusedItemIndex() inputField := queryForm.GetFormItem(idx).(*tview.InputField) val := reflect.ValueOf(*inputField) cursorPos := val.FieldByName("cursorPos").Int() text := inputField.GetText() newText := text[0:cursorPos] + clipContent + text[cursorPos:] queryForm.GetFormItem(idx).(*tview.InputField).SetText(newText) } return event }) } ``` Note that without getter for the `cursorPos` member I had to break encapsulation to access the position of the cursor to be able to insert the paste at the right position. A cleaner solution would require a proper accessor: `func (i *InputField) GetCursorPos() int ` Could be a temporary solution to https://github.com/SoMuchForSubtlety/f1viewer/issues/74 @SoMuchForSubtlety.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#71
No description provided.