term.js icon indicating copy to clipboard operation
term.js copied to clipboard

Different behaviour for Cmd+C, Cmd+v, etc on Mac

Open petethepig opened this issue 12 years ago • 9 comments

It allows you to copy/paste any text from/into the terminal. I suggest it, since this is the default behaviour in Terminal.app on Mac.

petethepig avatar Sep 20 '13 05:09 petethepig

+1 Copy and paste doesn't work for Macs, at least in the way that everyone tries. No one will try Opt-C/V!

jagill avatar Feb 07 '14 16:02 jagill

Now I'm confused. The isMac and ev.metaKey check is there to check for a mac's equivalent of Alt (which is Option, I think?). Why would that if statement affect the Command key? This change would also stop a whole range of key combinations from working.

Could either of you show me the raw event output for keydown of Cmd+[anything] in the browser? It should be event.ctrlKey.

chjj avatar Feb 07 '14 16:02 chjj

The check for Cmd in mac is event.metaKey. Option is event.altKey. Ctrl is event.ctrlKey.

Here is Cmd-C:

jQuery.Event {originalEvent: KeyboardEvent, type: "keydown", isDefaultPrevented: function, timeStamp: 1391791240401, jQuery182012300834944471717: true…}
altKey: false
attrChange: undefined
attrName: undefined
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: false
currentTarget: Window
data: null
delegateTarget: Window
eventPhase: 3
handleObj: Object
isDefaultPrevented: function returnFalse() { // 3279
jQuery182012300834944471717: true
key: undefined
keyCode: 67
metaKey: true
originalEvent: KeyboardEvent
relatedNode: undefined
relatedTarget: undefined
shiftKey: false
srcElement: textarea.ace_text-input
target: textarea.ace_text-input
timeStamp: 1391791240401
type: "keydown"
view: Window
which: 67

Here is Opt-C:

jQuery.Event {originalEvent: KeyboardEvent, type: "keydown", isDefaultPrevented: function, timeStamp: 1391791248160, jQuery182012300834944471717: true…}
altKey: true
attrChange: undefined
attrName: undefined
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: false
currentTarget: Window
data: null
delegateTarget: Window
eventPhase: 3
handleObj: Object
isDefaultPrevented: function returnFalse() { // 3279
jQuery182012300834944471717: true
key: undefined
keyCode: 229
metaKey: false
originalEvent: KeyboardEvent
relatedNode: undefined
relatedTarget: undefined
shiftKey: false
srcElement: textarea.ace_text-input
target: textarea.ace_text-input
timeStamp: 1391791248160
type: "keydown"
view: Window
which: 229

Here is Ctrl-C:

jQuery.Event {originalEvent: KeyboardEvent, type: "keydown", isDefaultPrevented: function, timeStamp: 1391791364750, jQuery182012300834944471717: true…}
altKey: false
attrChange: undefined
attrName: undefined
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: true
currentTarget: Window
data: null
delegateTarget: Window
eventPhase: 3
handleObj: Object
isDefaultPrevented: function returnFalse() { // 3279
jQuery182012300834944471717: true
key: undefined
keyCode: 67
metaKey: false
originalEvent: KeyboardEvent
relatedNode: undefined
relatedTarget: undefined
shiftKey: false
srcElement: textarea.ace_text-input
target: textarea.ace_text-input
timeStamp: 1391791364750
type: "keydown"
view: Window
which: 67

jagill avatar Feb 07 '14 16:02 jagill

Ah, okay. So command is considered meta (seriously unfamiliar with mac keyboards). Gotcha. Yeah, I'll add a better check that won't disrupt any other key combinations either. Thanks for checking.

chjj avatar Feb 07 '14 16:02 chjj

Yeah, the mode key event attributes in mac are very non-intuitive.

jagill avatar Feb 07 '14 16:02 jagill

@petethepig thanks for your patch, works great.

soumith avatar Apr 27 '14 06:04 soumith

@chjj would be nice to have this or something to its effect

jessetane avatar Jul 09 '14 21:07 jessetane

See also PR #37. I'm not a Mac user, but assuming that Option+key on Mac should work like Alt+key on other systems, I think that one is preferable - this one appears to disable all Alt shortcuts on Macs.

takluyver avatar Apr 22 '15 22:04 takluyver

I tried to support Cmd-C, Cmd-V on Mac using hidden textarea. https://github.com/chjj/term.js/pull/97

yoshiokatsuneo avatar Nov 09 '15 08:11 yoshiokatsuneo