[jitsi-dev] [PATCH] Fix for copying text from the chat window that contains images


#1

Hello,

If you try to copy a selected text that contains image (for example smiley
or link of an image) from the chat window, the text for the image is not
copied. This patch changes the implementation to replace all image tags
with the value of the ALT attribute in the selected text if the text
contains any images.

The patch can be tested if you send some messages wtih smileys and then
select text from the messages that contains smiley. If you try to copy the
text and paste it the smiley image in the text should be replaced with the
text which was originaly written for the smiley. For example if the
original message is "test :slight_smile: test" and you select the whole message and
copy / paste it, the pasted text will be "test :slight_smile: test" instead of "test
test" (which is the behavior without the patch).

The same functionality works if you drag the selected text instead of copy
it.

Regards.

copy_paste.txt (6.04 KB)


#2

Hey Hristo,

Really nice patch!! It's now committed (r10469) and ack-ed!

When testing the feature, I was confronted to two small problems and I thought that they're worth mentioning, so that we try to fix them while we're there :slight_smile: The first thing is that if I send heart, which text is "<3" only the number 3 is copied and the "<" disappears. The thing that's maybe more tricky to solve is that the user doesn't really see that the images are actually copied, i.e. there's no blue selection over the image. While this is really a small detail I think we could have a quick look, because it could really enhance the user experience :slight_smile:

Cheers,
Yana

···

On Feb 20, 2013, at 1:29 PM, Hristo Terezov <hristoterezov@gmail.com> wrote:

Hello,

If you try to copy a selected text that contains image (for example smiley or link of an image) from the chat window, the text for the image is not copied. This patch changes the implementation to replace all image tags with the value of the ALT attribute in the selected text if the text contains any images.

The patch can be tested if you send some messages wtih smileys and then select text from the messages that contains smiley. If you try to copy the text and paste it the smiley image in the text should be replaced with the text which was originaly written for the smiley. For example if the original message is "test :slight_smile: test" and you select the whole message and copy / paste it, the pasted text will be "test :slight_smile: test" instead of "test test" (which is the behavior without the patch).

The same functionality works if you drag the selected text instead of copy it.

Regards.
<copy_paste.txt>


#3

Hello,

I'm attaching version 2 of the patch. The problem with the heart emoticon
is fixed.

The value of the ALT attribute is escaped before replacing the image
element with it. To escape that strings I'm using escapeHTMLChars method.
This method was defined in ChatHtmlUtils class, but in order to avoid
including impl bundle (gui impl bundle, where ChatHtmlUtils is defined) in
desktoputils bundle (where the ExtendedTransferHandler class is defined), I
moved that method in GuiUtils class.

Regards.

copy_paste_v2.txt (7.23 KB)

···

On Thu, Feb 21, 2013 at 12:35 PM, Yana Stamcheva <yana@jitsi.org> wrote:

Hey Hristo,

Really nice patch!! It's now committed (r10469) and ack-ed!

When testing the feature, I was confronted to two small problems and I
thought that they're worth mentioning, so that we try to fix them while
we're there :slight_smile: The first thing is that if I send heart, which text is "<3"
only the number 3 is copied and the "<" disappears. The thing that's maybe
more tricky to solve is that the user doesn't really see that the images
are actually copied, i.e. there's no blue selection over the image. While
this is really a small detail I think we could have a quick look, because
it could really enhance the user experience :slight_smile:

Cheers,
Yana

On Feb 20, 2013, at 1:29 PM, Hristo Terezov <hristoterezov@gmail.com> > wrote:

> Hello,
>
> If you try to copy a selected text that contains image (for example
smiley or link of an image) from the chat window, the text for the image is
not copied. This patch changes the implementation to replace all image tags
with the value of the ALT attribute in the selected text if the text
contains any images.
>
> The patch can be tested if you send some messages wtih smileys and then
select text from the messages that contains smiley. If you try to copy the
text and paste it the smiley image in the text should be replaced with the
text which was originaly written for the smiley. For example if the
original message is "test :slight_smile: test" and you select the whole message and
copy / paste it, the pasted text will be "test :slight_smile: test" instead of "test
test" (which is the behavior without the patch).
>
> The same functionality works if you drag the selected text instead of
copy it.
>
> Regards.
> <copy_paste.txt>


#4

Hi Hristo,

Thanks! The fix is now part of revision 10475.

Cheers,
Yana

···

On Feb 21, 2013, at 8:01 PM, Hristo Terezov <hristoterezov@gmail.com> wrote:

Hello,

I'm attaching version 2 of the patch. The problem with the heart emoticon is fixed.

The value of the ALT attribute is escaped before replacing the image element with it. To escape that strings I'm using escapeHTMLChars method. This method was defined in ChatHtmlUtils class, but in order to avoid including impl bundle (gui impl bundle, where ChatHtmlUtils is defined) in desktoputils bundle (where the ExtendedTransferHandler class is defined), I moved that method in GuiUtils class.

Regards.

On Thu, Feb 21, 2013 at 12:35 PM, Yana Stamcheva <yana@jitsi.org> wrote:
Hey Hristo,

Really nice patch!! It's now committed (r10469) and ack-ed!

When testing the feature, I was confronted to two small problems and I thought that they're worth mentioning, so that we try to fix them while we're there :slight_smile: The first thing is that if I send heart, which text is "<3" only the number 3 is copied and the "<" disappears. The thing that's maybe more tricky to solve is that the user doesn't really see that the images are actually copied, i.e. there's no blue selection over the image. While this is really a small detail I think we could have a quick look, because it could really enhance the user experience :slight_smile:

Cheers,
Yana

On Feb 20, 2013, at 1:29 PM, Hristo Terezov <hristoterezov@gmail.com> wrote:

> Hello,
>
> If you try to copy a selected text that contains image (for example smiley or link of an image) from the chat window, the text for the image is not copied. This patch changes the implementation to replace all image tags with the value of the ALT attribute in the selected text if the text contains any images.
>
> The patch can be tested if you send some messages wtih smileys and then select text from the messages that contains smiley. If you try to copy the text and paste it the smiley image in the text should be replaced with the text which was originaly written for the smiley. For example if the original message is "test :slight_smile: test" and you select the whole message and copy / paste it, the pasted text will be "test :slight_smile: test" instead of "test test" (which is the behavior without the patch).
>
> The same functionality works if you drag the selected text instead of copy it.
>
> Regards.
> <copy_paste.txt>

<copy_paste_v2.txt>