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 doesn't work #364

Closed
goflatworld opened this issue Nov 20, 2016 · 24 comments
Closed

Paste doesn't work #364

goflatworld opened this issue Nov 20, 2016 · 24 comments
Assignees
Labels
area/clipboard type/bug Something is misbehaving

Comments

@goflatworld
Copy link

The issue I opened in below link, it is not fixed yet. The issue is that when I right click the and choose "paste", it doesn't paste anything.

#344

@parisk
Copy link
Contributor

parisk commented Nov 22, 2016

Thanks for opening this @goflatworld. I think I have spotted the bug and will get on top of this within the week hopefully.

@parisk parisk added this to the 2.2.0 milestone Nov 22, 2016
@parisk parisk added the type/bug Something is misbehaving label Nov 22, 2016
@parisk parisk self-assigned this Nov 22, 2016
@goflatworld
Copy link
Author

Thanks Parisk. Great to know that you have spotted the bug. Waiting for your solution.

@parisk
Copy link
Contributor

parisk commented Dec 5, 2016

@goflatworld can you let us know if any of xterm.js' element parents use the transform CSS property?

Seems like this is causing an issue and misplaces the hidden textarea, so the right-click won't work.

fixed
Do not leave space for the element. Instead, position it at a specified position relative to the screen's viewport and don't move it when scrolled. When printing, position it at that fixed position on every page. This value always create a new stacking context. When an ancestor has the transform property set to something different than none then this ancestor is used as container instead of the viewport (see CSS Transforms Spec).

From: https://developer.mozilla.org/en/docs/Web/CSS/position#Values

Also, I am removing this from the milestone, as it will need more work than initially thought, in order to calculate appropriately the position of the hidden textarea on the user's right click.

@parisk parisk removed this from the 2.2.0 milestone Dec 5, 2016
@goflatworld
Copy link
Author

Hi Parisk,

Below is all the HTML code I have (it is a PHP file). You can see that the CSS are from xterm.js. I suppose that they don't use transform? I also tried to search transform in these CSS. but did not see it.

<!doctype html>
<html>
    <head>
        <title>Stingray Solution</title>
        <link rel="stylesheet" href="xterminal.js/build/xterm.css" />
        <link rel="stylesheet" href="xterminal.js/addons/fullscreen/fullscreen.css" />
        <link rel="stylesheet" href="style.css" />
        <script>
		var hash= "<?php echo $_REQUEST['id']; ?>\n";
	</script>	
		
	<script src="xterminal.js/dist/xterm.js" ></script>
        <script src="xterminal.js/addons/attach/attach.js" ></script>
        <script src="xterminal.js/addons/fit/fit.js" ></script>
        <script src="xterminal.js/addons/fullscreen/fullscreen.js" ></script>
    </head>
    <body>
        <div id="terminal-container"></div>
        <script src="main.js" defer ></script>
    </body>
</html>

The main.js is the code from xterm.js example, I modified it a bit. and it is as follow:

var term,
    protocol,
    socketURL,
    socket,
    pid,
    charWidth,
    charHeight;

var terminalContainer = document.getElementById('terminal-container');

createTerminal();

function createTerminal() {

  while (terminalContainer.children.length) {
    terminalContainer.removeChild(terminalContainer.children[0]);
  }

  term = new Terminal({
    cursorBlink: true 
  });
  protocol = 'wss://';
  socketURL = 'wss://www.flatworld.com:443';

  term.open(terminalContainer);
  term.fit();
  
  var initialGeometry = term.proposeGeometry(),
	cols = 80,
	rows = 30;

    charWidth = Math.ceil(term.element.offsetWidth / cols);
    charHeight = Math.ceil(term.element.offsetHeight / rows);

      if (window.WebSocket === undefined)
      {
        state.innerHTML = "sockets not supported";
        state.className = "fail";
      }
      socket = new WebSocket(socketURL);
      socket.onopen = runRealTerminal;
      socket.onclose = onClose;
      socket.onerror = onError;
}


function runRealTerminal() {
  term.attach(socket);
  term._initialized = true;
  socket.send("C");

  term.on('key', function (key, ev) {
    var printable = (
      !ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey
    );
 
    var message ="A" + key;

    socket.send(message);

  });

  term.on('paste', function (data, ev) {
    socket.send(data);
  });
}


function onClose()
{
  term.write("\rDisconnected from server.");       
}
  

function onError()
{ 
  term.write("\rFail: ");
  term.write("Communication error");
}

For the attach.js, I modifed a bit, the modified part is as below:

 term._getMessage = function (ev) {
      if (buffered) {
        term._pushToBuffer(ev.data);
      } else if (ev.data==="Auth-Required")
      {
	socket.send(hash);      } else if (ev.data===" Auth OK!")
      {
 	term.write("Press Enter to Start.");
      } else
      {
        term.write(ev.data);
      }
    };

Would these modification cause any issue?

@parisk parisk added this to the 2.3.0 milestone Dec 8, 2016
@parisk
Copy link
Contributor

parisk commented Dec 8, 2016

@goflatworld these modifications do not seem like causing issues.

OK, I put this in the 2.3.0 milestone, in order to find an appropriate solution for this issue.

What would help though are the following details:

  1. The system that you tried this the most times and it didn't work (OS and Browser along with versions)
  2. A production running application where I can get access to try this out as, I can't get it working in the demo

@goflatworld
Copy link
Author

Hi Parisk,

I tried Firefox on MAC the most. However I also tried IE, Chrome on Windows, Linux. None of them worked for me.

The system is not in public domain yet, but you can test it via below:

  1. Modify your windows\system32\driver\hosts file. Point www.flatworld.com to 52.65.93.0
  2. Save below certificate as .cer file and import to you Web Browser.

-----BEGIN CERTIFICATE-----
MIICfzCCAegCCQCvneKQfiJpKDANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC
QVUxDDAKBgNVBAgMA05TVzEPMA0GA1UEBwwGU3lkbmV5MRMwEQYDVQQKDApGbGF0
IFdvcmxkMRowGAYDVQQDDBF3d3cuZmxhdHdvcmxkLmNvbTEkMCIGCSqGSIb3DQEJ
ARYVc3VwcG9ydEBmbGF0d29ybGQuY29tMB4XDTE2MDkwNDIzMzg1M1oXDTI2MDkw
MjIzMzg1M1owgYMxCzAJBgNVBAYTAkFVMQwwCgYDVQQIDANOU1cxDzANBgNVBAcM
BlN5ZG5leTETMBEGA1UECgwKRmxhdCBXb3JsZDEaMBgGA1UEAwwRd3d3LmZsYXR3
b3JsZC5jb20xJDAiBgkqhkiG9w0BCQEWFXN1cHBvcnRAZmxhdHdvcmxkLmNvbTCB
nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtwhi6ubo3dF4R25ztYnBXGyZER1q
mQRf6z9vGA/xxUK6jtqN+kAE/NI51Ofq01hJXCkxOXxRM1i+GW/X0wfFEIfgt+Zn
UWpMQ4bUEqwTyACJOQZvKBdXG/sg7428XvgkDjMrAkdp81t16KtqYMnDW1vXqmNq
ZW9wos9N01MUQCcCAwEAATANBgkqhkiG9w0BAQsFAAOBgQBSKyVKIMQ8UoutpPIq
+wQyf8zi2o8xlR5XM72rIVGIAa1X2MlWyvZHXEHLuyV6t7yN8ltOZdxUH3OBY+OU
Ve3iwjI3+UGazCb9R9HaELvmasdC+cXA9Puu1ej7jt4Vl2sXUQkvkyff1tOzM4VP
vKZfTNAO1toH2jYyU6aeq7bB0g==
-----END CERTIFICATE-----

In IE, you need import it under "Trusted Root Certification Authority". Need do it via the IE "Internet options"->Content -> certificates.
In Firefox, you need import it under "Options->Advanced->View Certificate->Authorities"

The certificate is not publicly signed because the DNS was registered by other party. that's why you need do above. We are working on different names but not now.

Once above is done:

Go to

www.flatworld.com

login username: demo@company1.com
password: test1

You can see "Dural" is green (if it is not green, please email me your prefered test time, I can make sure it is green), click it and then click "connect". You can test copy and paste in there.

@uudruid74
Copy link

uudruid74 commented Jan 13, 2017

Basic paste works fine for me, but let me throw a monkey wrench into things. Use tmux to split the screen into two panes. Run something that repeatedly updates the display in one pane, such as top (I'm using htop). Now, try and cut text from either pane.

What happens is that the screen update on one pane either deselects the text before you can cut it or it acts as if you started selecting from the top of the screen and selects multiple lines (I was going for one word).

Update: just noticed #318 and #468 (likely dups), which is where this should have been noted. Sorry.

@parisk
Copy link
Contributor

parisk commented Jan 13, 2017

@uudruid74 no prob. Indeed what you describe is a side-effect of not optimal rendering.

The issue here is that the hidden textarea used for input is not positioned correctly in some cases.

@uudruid74
Copy link

@parisk Getting more offtopic, but ... why would it need to be positioned at all? Aren't you just giving it focus and then stealing keyDown events with it? So, why would that have anything to do with the mouse?

@Tyriar
Copy link
Member

Tyriar commented Jan 19, 2017

The textarea needs to be positioned to support IMEs which popup at the cursor position. The only hooks we have to talk to the IME are the oncomposition* events, so we cannot tell the browser/OS where to position the IME.

This is also the reason we are using a textarea over some contenteditable tricks as it was briefly using since they didn't work nicely for internationalization.

@Tyriar Tyriar removed this from the 2.3.0 milestone Feb 9, 2017
@goflatworld
Copy link
Author

Hi Parisk,

I have upgraded the website. Now, you can reproduce the issue follow below steps:

Go to

www.pickmyinfo.com

Username: demo@company1.com
Password: test1

Once you login, on the left pane, click "Menu->City->Stingray->Home Router"
On the Right Pane, click "Connect".

After that, a new window popup and states: "Press Enter to Start.". You can test copy and paste in this window.

Thanks

George

@xujihui1985
Copy link

any update?

@goflatworld
Copy link
Author

Do I need node.js to be able to use paste?

@parisk
Copy link
Contributor

parisk commented Jun 6, 2017

No, you do not need node.js to paste. Node.js lives outside the browser, while the paste happens inside the browser :).

@goflatworld
Copy link
Author

I tried the demo application. When the demo server is active. I can paste to the terminal but when I stop the server, I can not paste to the terminal anymore. Do I need to write any special code on the server side to make copy and paste work?

@mofux
Copy link
Contributor

mofux commented Aug 12, 2017

@goflatworld Here is what happens: The demo sends your inputs to a tty process that is spawned by the server. Any input that you make on the console is sent to the server, received by the tty process, then output from the tty process is generated (for example it will echo the characters you just typed or pasted), sent from the tty to the server to the demo frontend client, and then rendered by xterm.js. If you kill the server, the data will never arrive at the tty, and no output from the tty will ever arrive at the client.

@goflatworld
Copy link
Author

Thanks mofux. I get quite lost on this.

So the demo doesn't echo locally and it only display message from server. This is exactly what my application also behaviors. but why my application can not paste even when my server is active?

My client code has been pasted in previous post in the same thread. That code is a slightly modified demo client version. Is there anything wrong with my client code?

@goflatworld
Copy link
Author

function runRealTerminal() {
  term.attach(socket);
  term._initialized = true;
  socket.send("C");

  term.on('key', function (key, ev) {
    var printable = (
      !ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey
    );
 
    var message ="A" + key;

    socket.send(message);

  });

  term.on('paste', function (data, ev) {
   term.write(data)   ------------------------------------ Added this line to see if I can see my pasted data, but I can not see anything.
    socket.send(data);
  });
}

Can you please shed some lights on whether the code is correct or not?

@mofux
Copy link
Contributor

mofux commented Aug 23, 2017

No, there is a much simpler way to do things. Instead of listening for the key and paste events,
you should actually listen to the data event. This event is emitted whenever you type or paste in the terminal, and it already contains the correct, xterm compatible data (string):

term.on('data', function(data) {
  socket.send(data);
})

@goflatworld
Copy link
Author

Great mofux!

That fixed the issue after 8 months of wondering what am I doing wrong!... Thanks a lot for your great help.

Cheers

George

@Tyriar
Copy link
Member

Tyriar commented Aug 24, 2017

\(^_^)/

@Tyriar Tyriar closed this as completed Aug 24, 2017
@goflatworld
Copy link
Author

goflatworld commented Aug 24, 2017 via email

@Tyriar
Copy link
Member

Tyriar commented Aug 24, 2017

You mean \n or \r\n? Both should work as the text is filtered through this function:

https://github.com/sourcelair/xterm.js/blob/6e9d60d76d6cfb3d279f9e58499ba62ca6af479c/src/handlers/Clipboard.ts#L23-L28

@goflatworld
Copy link
Author

goflatworld commented Aug 25, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clipboard type/bug Something is misbehaving
Projects
None yet
Development

No branches or pull requests

6 participants