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

Last two BR-Tags cant be remove if option enter is ENTER_BR.

Open PATROMO opened this issue 5 years ago • 9 comments

If you use enter: $.FroalaEditor.ENTER_BR then it is not possible to remove the last two <br> Tags with push Backspace. Only possible if you open the Code view and remove it there.

Try it out here: https://jsfiddle.net/L4vkamhz/

Expected behavior.

I expect to be able to empty the complete contents in the editor.

Actual behavior.

Two <br><br> can not be deleted.

Steps to reproduce the problem.

Try to remove the BR-Tags https://jsfiddle.net/L4vkamhz/

Editor version.

v2

PATROMO avatar Nov 14 '19 09:11 PATROMO

I've run in the same problem, currently using the following workaround on keydown:

const fixBr = (e, editor) => {
  if (editor.html.get() === '<br><br>' && (
    (editor.selection.get().anchorOffset === 1 && e.key === 'Backspace') ||
    (editor.selection.get().anchorOffset === 0 && e.key === 'Delete')
  )) {
    editor.html.set('');
  }
};

The methods cursor.isAtEnd() and cursor.isAtStart() aren't used above since they always returned false for an unknown reason.

seahorsepip avatar May 09 '20 14:05 seahorsepip

Small update for anyone who also runs into the issue with e.g. <strong> tags:

const fixBr = (e, editor) => {
  if ((
    (editor.selection.get().anchorOffset === 1 && e.key === 'Backspace') ||
    (editor.selection.get().anchorOffset === 0 && e.key === 'Delete')
  ) && htmlToText(editor.html.get()).length <= 1) {
    editor.html.set('');
  }
};
// HTML string to plaintext
export const htmlToText = (html: string) => {
  const div = document.createElement('div');
  div.innerHTML = html;
  return div.innerText;
};

Also regarding the version 2 label, this issue is also on version 3.

seahorsepip avatar Jun 07 '20 11:06 seahorsepip

I'm here because I'm experiencing the same troublesome bug, and it's causing a validation error when the user wants to delete their post (there is a separate title field that is only required when the field we are using froala for is not empty, and the user can't delete the <br><br> so their post is not valid for deletion.)

m-andrew-albright avatar Mar 04 '21 16:03 m-andrew-albright

Never found a proper solution for this issue, the above workaround didn't work reliable enough.

Currently we're using the default paragraph <p> option and convert them to line breaks <br> afterwards on user submit:

const paragraphsToLineBreaks = (html: string) =>
	html
		.replace(/[\n\r]/g, '')
		.replace(/<ol>/g, '<p><ol>')
		.replace(/<\/ol>/g, '</ol></p>')
		.replace(/<ul>/g, '<p><ul>')
		.replace(/<\/ul>/g, '</ul></p>')
		.replace(/<p><br><\/p>/g, '<p></p>')
		.replace(/<\/p><p>/g, '<br>')
		.replace(/<\/?p>/g, '');

seahorsepip avatar Mar 04 '21 16:03 seahorsepip

~~I just updated to 3.2.6-1 and the problem seems fixed!~~

m-andrew-albright avatar Mar 04 '21 17:03 m-andrew-albright

I could swear that it was fixed after testing multiple times, but now I'm finding that I was mistaken and it is still broken. Sorry for the false positive. This is still broken. It would be nice if the Froala team would give us some kind of acknowledgment that they are aware of this bug existing, and a path to it being fixed.

m-andrew-albright avatar Mar 09 '21 12:03 m-andrew-albright

This is still a problem. The lack of attention on bugs makes me wary to recommend Froala to other developers, and in any new projects we will seek alternative products.

m-andrew-albright avatar Aug 02 '21 12:08 m-andrew-albright

Still happens in 4.0.7: https://jsfiddle.net/u80wngpx/2/

dcsaszar avatar Nov 29 '21 06:11 dcsaszar

Confirmed fixed in 4.0.12 https://jsfiddle.net/yhcLguxj/1/ 👍

dcsaszar avatar Jun 08 '22 17:06 dcsaszar