Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste content is truncated #92

Closed
soyking opened this issue Mar 30, 2018 · 6 comments
Closed

Paste content is truncated #92

soyking opened this issue Mar 30, 2018 · 6 comments

Comments

@soyking
Copy link

soyking commented Mar 30, 2018

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?

@stephencheng
Copy link

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.

@rivo
Copy link
Owner

rivo commented 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.)

@soyking
Copy link
Author

soyking commented Apr 2, 2018

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

@soyking
Copy link
Author

soyking commented 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.

@rivo
Copy link
Owner

rivo commented 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.)

@mtartare
Copy link

mtartare commented Aug 6, 2020

This issue was partially fixed in tcell but is still present on Windows (see gdamore/tcell#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 SoMuchForSubtlety/f1viewer#74 @SoMuchForSubtlety.

SoMuchForSubtlety added a commit to SoMuchForSubtlety/f1viewer that referenced this issue Aug 8, 2020
SoMuchForSubtlety added a commit to SoMuchForSubtlety/f1viewer that referenced this issue Aug 8, 2020
SoMuchForSubtlety added a commit to SoMuchForSubtlety/f1viewer that referenced this issue Aug 22, 2020
SoMuchForSubtlety added a commit to SoMuchForSubtlety/f1viewer that referenced this issue Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants