wysiwyg-editor icon indicating copy to clipboard operation
wysiwyg-editor copied to clipboard

html.getSelected() is wrong for selection without markup

Open tpetry opened this issue 6 years ago • 5 comments
trafficstars

Expected behavior.

Selecting content without any html markup (plain text) in the froala editor and calling html.getSelected() will only return the selected part.

Actual behavior.

The complete html markup of the editor is returned

Steps to reproduce the problem.
  1. Type This is some text before. Select this text. This is some text after.
  2. Select Select this text
  3. Call html.getSelected()
Versions.

Froala: 3.0.5 OS/Browser: Chrome, Firefox

tpetry avatar Sep 27 '19 14:09 tpetry

Any news about this? It looks like it's working fine in Chrome and it breaks in Firefox and Safari..... (Froala 3.1.1)

lajuffermans avatar Nov 04 '20 13:11 lajuffermans

I have experienced a similar issue to this, in that calling html.getSelected() does not return the selection, but rather the entire line of text of which the selection belongs. Thought I should add here as it seems very similar and do not want to create unnecessary issues.

The issue also only seems to repro in Firefox for me. Safari is all OK.

Version 3.1.0

georgedoescode avatar Nov 26 '20 14:11 georgedoescode

observing same issue here, on version 3.1.1...

MagicDuck avatar Jan 07 '21 21:01 MagicDuck

Hi there, this is a huge issue for us, as we want to implement a custom plugin and need a way to get the selected html. From what I have seen, the html.getSelection() method returns the whole parent element - in my test it is the paragraph, as I am selecting just text inside the paragraph, not event trying to mess around with selecting say parts of bold, underlined or italic contents.

In the ideal case, if the markup is something like ... some text <strong>some |other text</strong> yet an|other text... and the user selects everything between the two pipes (|), we need a way to get "other text</strong> yet an" as return value of some method.

In general I have the feeling that nothing big is happening for the froala editor lately, because the focus is obviously on bringing new products on the market. Prove me wrong, dear Froala staff :)

Version 3.1.1

VassilTonev avatar Jan 20 '21 16:01 VassilTonev

This is still happening in version 3.2.5. This was working under Froala v2, so judging by the comments here it has been broken during all of Froala 3.

But I found a workaround that seems to work so far for my custom plugins. However I haven't tested too extensively since it started working, so I can't be sure...

Immediately before calling html.getSelection(), call selection.text()

function myFroalaSelection(editor) {
    editor.selection.text();
    return editor.html.getSelection();
}

It seems like sometimes the selection is not primed and html.getSelection doesn't or fails to prime it itself. Or at least that's the only explanation I can think of without seeing Froala's code unminified.

crackedeggs1 avatar Apr 29 '21 06:04 crackedeggs1