question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Firefox trims trailing white space, unexpected cursor behavior

See original GitHub issue

Do you want to request a feature or report a bug?

report a bug

What’s the current behavior?

If a text node ends in a \n when a user presses enter, Firefox trims the whitespace and the cursor stays on the same line. If the user continues typing, the characters appear in the correct location. If the user presses down arrow, the cursor will appear on the correct line.

If I change the event handler from Transforms.insertText(editor, \n) to Transforms.insertText(editor, \n\u2060) (adds a zero width white space) the editor works as expected.

See sandbox: here

Slate: 0.59.0 Browser: Firefox OS: Mac

What’s the expected behavior?

It should move the cursor to the new line as it does on Chrome.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:6

github_iconTop GitHub Comments

4reactions
rsdrsdcommented, Oct 28, 2020

Are there more solutions for this bug?

1reaction
JMLX42commented, Nov 14, 2021

This ckeditor PR might be related:

https://github.com/ckeditor/ckeditor5-engine/pull/1582/files

This code in particular:

function fixGeckoSelectionAfterBr( focus, domSelection ) {
	const parent = focus.parent;

	// This fix works only when the focus point is at the very end of an element.
	// There is no point in running it in cases unrelated to the browser bug.
	if ( parent.nodeType != Node.ELEMENT_NODE || focus.offset != parent.childNodes.length - 1 ) {
		return;
	}

	const childAtOffset = parent.childNodes[ focus.offset ];

	// To stay on the safe side, the fix being as specific as possible, it targets only the
	// selection which is at the very end of the element and preceded by <br />.
	if ( childAtOffset && childAtOffset.tagName == 'BR' ) {
		domSelection.addRange( domSelection.getRangeAt( 0 ) );
	}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

When a space overflows the width of a div, the previous word ...
The problem with your patch, afaict, is that it trims all of the trailing white space... which looks fine, but can be a...
Read more >
Firefox wrongly trims trailing white space when editing
The result seems OK: when you see the cursor blinking after that, it appears that there is a trailing space after "Lorem".
Read more >
117968 – White space added when enter pressed
three times. The real problem is that the editor inserts useless trailing whitespace as you edit. This has long been complained about.
Read more >
The poor, misunderstood innerText - Perfection Kills
innerText = $(this)[0].title; // fails in Mozilla ... Notice that no whitespace normalization is performed, the text and whitespace are ...
Read more >
JupyterLab Changelog — JupyterLab 3.6.0b0 documentation
Add show trailing whitespace option to Notebook and Text Editor #11131 (@blink1073) ... Fix cell type dropdown behaviour in Firefox on 3.1.x branch...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found