Manually invoking cut, copy or paste

2,357 views
Skip to first unread message

Juliusz Gonera

unread,
Sep 13, 2011, 9:02:42 PM9/13/11
to ace-d...@googlegroups.com
Hi,

Is there a way of invoking those actions in ACE from JS code? I can see
in Cloud9 that menu items for those actions (the top menu, not editor's
context menu) don't work. Is this not yet implemented?

Thanks,
--
Juliusz Gonera
http://juliuszgonera.com/

Rohit Reddy Korrapolu

unread,
Sep 16, 2011, 7:11:57 PM9/16/11
to ace-d...@googlegroups.com
Even I am new to ACE code, I can give you few suggestions.

To paste code to ace editor, call editorSession.insert(<text>) 

To copy code from ace editor, call editor.getCopyText() after selecting the content you want to copy.

For cut, you can use the above 2 functions. 

I hope this helps you


Juliusz Gonera

unread,
Sep 19, 2011, 4:07:49 PM9/19/11
to ace-d...@googlegroups.com
Rohit Reddy Korrapolu wrote:
> Even I am new to ACE code, I can give you few suggestions.
>
> To paste code to ace editor, call editorSession.insert(<text>)

How would I get the current clipboard content?

Brion Vibber

unread,
Sep 19, 2011, 4:23:28 PM9/19/11
to ace-d...@googlegroups.com
On Mon, Sep 19, 2011 at 1:07 PM, Juliusz Gonera <jgo...@gmail.com> wrote:
Rohit Reddy Korrapolu wrote:
Even I am new to ACE code, I can give you few suggestions.

To paste code to ace editor, call editorSession.insert(<text>)

How would I get the current clipboard content?

Generally speaking, you can only access the clipboard as part of an event that's initiated by the browser. This is an important security mechanism; without it, any web site you visit could grab any data you copy-paste while it's open -- private emails, passwords, your home address, credit card numbers, etc.

So, copy/paste must be initiated by the browser's context menu, edit menu, or keyboard shortcuts.

-- brion vibber (brion @ pobox.com)

Juliusz Gonera

unread,
Sep 19, 2011, 4:51:51 PM9/19/11
to ace-d...@googlegroups.com
Brion Vibber wrote:

> Generally speaking, you can only access the clipboard as part of an
> event that's initiated by the browser. This is an important security
> mechanism; without it, any web site you visit could grab any data you
> copy-paste while it's open -- private emails, passwords, your home
> address, credit card numbers, etc.
>
> So, copy/paste must be initiated by the browser's context menu, edit
> menu, or keyboard shortcuts.

This makes sense, but I still don't understand why Cloud9 devs put those
items (Copy/Cut/Paste) in their application's menu. I mean, they don't
work ATM, but was it always like that?

Would it be possible to send some event to the editor telling it to
paste? I.e. not getting the clipboard contents and then manually
inserting them but instead forcing the paste behaviour on the widget.

Fabian Jakobs

unread,
Sep 28, 2011, 6:39:08 AM9/28/11
to ace-d...@googlegroups.com
On Mon, Sep 19, 2011 at 10:51 PM, Juliusz Gonera <jgo...@gmail.com> wrote:
> Brion Vibber wrote:
>
>> Generally speaking, you can only access the clipboard as part of an
>> event that's initiated by the browser. This is an important security
>> mechanism; without it, any web site you visit could grab any data you
>> copy-paste while it's open -- private emails, passwords, your home
>> address, credit card numbers, etc.
>>
>> So, copy/paste must be initiated by the browser's context menu, edit
>> menu, or keyboard shortcuts.
>
> This makes sense, but I still don't understand why Cloud9 devs put those
> items (Copy/Cut/Paste) in their application's menu. I mean, they don't work
> ATM, but was it always like that?

Actually we had to remove them because of exactly this issue.

> Would it be possible to send some event to the editor telling it to paste?
> I.e. not getting the clipboard contents and then manually inserting them but
> instead forcing the paste behaviour on the widget.

A paste is basically a editor.insert("some text", true). If you get
the pasted text somehoe (e.g. using flash) then this would do it.

Best,
Fabian

Juliusz Gonera

unread,
Sep 28, 2011, 9:57:30 AM9/28/11
to ace-d...@googlegroups.com
Fabian Jakobs wrote:

> A paste is basically a editor.insert("some text", true). If you get
> the pasted text somehoe (e.g. using flash) then this would do it.

I see, thank you. I'll try to experiment with this later.

Reply all
Reply to author
Forward
0 new messages