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

Add Terminal preferences and allow ctrl+c and ctrl+v on terminal if it has a selection #3469

Merged
merged 1 commit into from
Dec 10, 2018

Conversation

uniibu
Copy link
Contributor

@uniibu uniibu commented Nov 13, 2018

Background:
Since theia let most key bindings be handled by xtermjs, the usual
copy&paste key shortcuts no longer works.

Theia did this intentionally to have key bindings such as ctrl+c to
propagate into xterm, which then is used to send a kill signal SIGINT.

About:
This PR adds Terminal to preferences with enableCopy and enablePaste as initial options.

  • enableCopy [Boolean] - Enables ctrl-c or cmd-c(for OSX) to copy selected texts from the terminal.
    If there is no text selected, the command will propagate normally to xterm.
  • enablePaste [Boolean] - Enabled ctrl-v or cmd-v(for OSX) to paste from clipboard,

This PR uses xterm's attachCustomKeyEventHandler to listen for key strokes and the selection is returned by xterm's hasSelection function.

Signed-off-by: Uni Sayo [email protected]

@simark
Copy link
Contributor

simark commented Nov 13, 2018

I think it's a useful heuristic for the ctrl-c, since you are still able to send a ctrl-c to your program. But it blocks ctrl-v all the time, how would a user send a ctrl-v to the program?

@kittaakos
Copy link
Contributor

ECA

There is a valid ECA on file for [email protected].

FYI: ^C (SIGINT ) does not work on OS X when I have anything selected in the terminal. const ctrlCmd = event.ctrlKey || event.metaKey; seems to be incorrect on OS X.

screencast 2018-11-14 09-02-40

@uniibu
Copy link
Contributor Author

uniibu commented Nov 14, 2018

@AndrienkoAleksandr Thanks for all the input. I've updated this PR with latest commit fd0a08d which uses KeyCode from @theia/core/lib/browser to detect keybindings.

@kittaakos This now also detects user's system if it is an OSX, and only allows cmd+c and cmd+v, while ctrl+c and ctrl+v propagates normally to xterm. Further information on the commit message. Cheers!

@kittaakos
Copy link
Contributor

@uniibu, please make sure you have squashed your commits before handing it over for the review. Thank you!

@simark
Copy link
Contributor

simark commented Nov 14, 2018

I think it's a useful heuristic for the ctrl-c, since you are still able to send a ctrl-c to your program. But it blocks ctrl-v all the time, how would a user send a ctrl-v to the program?

This has not been addressed. With this patch, it's not possible to send ctrl-v to the program anymore...

@AndrienkoAleksandr
Copy link
Contributor

AndrienkoAleksandr commented Nov 14, 2018

I think it's a useful heuristic for the ctrl-c, since you are still able to send a ctrl-c to your program. But it blocks ctrl-v all the time, how would a user send a ctrl-v to the program?

This has not been addressed. With this patch, it's not possible to send ctrl-v to the program anymore...

@simark @uniibu Maybe we should create a command to activate/deactivate custom keyDownHandler?

@uniibu
Copy link
Contributor Author

uniibu commented Nov 14, 2018

This has not been addressed. With this patch, it's not possible to send ctrl-v to the program anymore...

@simark The patch still allows ctrl+v but only for non-osx systems. And for osx systems it uses cmd+v

Demo on Windwos 10/chrome:
theiacopypaste

@AndrienkoAleksandr I initially planned to add a preference for terminal where a user can enable/disable the keybindings such as ctrl+c or ctrl+v.. So that could be an option.

@kittaakos commits squashed.

@simark
Copy link
Contributor

simark commented Nov 14, 2018

@simark The patch still allows ctrl+v but only for non-osx systems. And for osx systems it uses cmd+v

I mean, if you have bound something to ctrl-v in your program which runs in the terminal, you can't use that anymore since it will paste text instead.

@uniibu uniibu changed the title Allow ctrl+c and ctrl+v on terminal if it has a selection Add Terminal preferences and allow ctrl+c and ctrl+v on terminal if it has a selection Nov 14, 2018
@uniibu
Copy link
Contributor Author

uniibu commented Nov 14, 2018

As per @simark's concern, I've added terminal to the preferences with enableCopy and enablePaste as initial options and both defaults to false.

This further opens up the terminal for further front-end user configurations, such as cursorStyle, cursorBlink etc.

@uniibu uniibu force-pushed the copy-paste branch 2 times, most recently from 2982ce7 to 84cdd7e Compare November 14, 2018 23:49
@uniibu
Copy link
Contributor Author

uniibu commented Nov 15, 2018

Demo on Windows 10/Chrome:
demo

Should be ready for review. Cheers!

'terminal.enableCopy': {
type: 'boolean',
description: 'Enable ctrl-c (cmd-c on macOS) to copy selected text',
default: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I wouldn't be against setting these to true by default, since it's probably more common for people to use copy/paste than to use ctrl-v.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to set up true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this gets merged, i'd be happy to have the default to true as well. +1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update it before merge?

Since theia let most key bindings be handled by xterm, the usual
copy&paste key shortcuts no longer works.
Theia did this intentionally to have key bindings such as ctrl+c to
propagate into xterm, which then is used to send a kill signal SIGINT.

This PR, allows the user to copy texts on the terminal via ctrl+c
or cmd+c(mac), but only if there is a selected/highlighted text on the
terminal.

This also allows the user to use ctrl+v or cmd+v to paste from clipboard

Signed-off-by: Uni Sayo <[email protected]>

add missing semicolon and remove trailing whitespace

Signed-off-by: Uni Sayo <[email protected]>

use KeyCode from core to detect keybindings, ignore ctrl+c/v if osx

As suggested, this commit simplifies detection of the keybindings by
using KeyCode class from theia/core.
It also detects if the user system is OSX.
For non-osx systems, ctrl+c with selection and ctrl+v will work.
And for osx systems, cmd+c with selection and cmd+v will work, while
ctrl+c and ctrl+v will propagate to xterm normally.

Signed-off-by: Uni Sayo <[email protected]>

Add Terminal Preferences with enableCopy and enablePaste

Adding terminal preferences gives the user an option to enable
ctrl/cmd+c and ctrl/cmd+v keyboard commands.
This also opens up the terminal for other user configurations.

Signed-off-by: Uni Sayo <[email protected]>

remove preferencechange listener

Signed-off-by: Uni Sayo <[email protected]>

reword descriptions

Signed-off-by: Uni Sayo <[email protected]>

remove clearSelection on copy

Signed-off-by: Uni Sayo <[email protected]>

Change copyright to reflect my company

Signed-off-by: Uni Sayo <[email protected]>

set default value to true

Signed-off-by: Uni Sayo <[email protected]>
@uniibu
Copy link
Contributor Author

uniibu commented Nov 16, 2018

  • Updated and set defaults to true
  • Commits squashed

@svenefftinge svenefftinge merged commit b01110a into eclipse-theia:master Dec 10, 2018
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

Successfully merging this pull request may close these issues.

6 participants