Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title Input Box Shouldn't Support Formatting #109

Open
MaximilianEmel opened this issue Jul 22, 2023 · 3 comments
Open

Title Input Box Shouldn't Support Formatting #109

MaximilianEmel opened this issue Jul 22, 2023 · 3 comments

Comments

@MaximilianEmel
Copy link

The title input box for a new title, allows formatted text to be pasted, which shouldn't be the case, since it isn't sent off anywhere, and can therefore be confusing.

@ajayyy
Copy link
Owner

ajayyy commented Jul 22, 2023

What do you mean by formatted text?

@MaximilianEmel
Copy link
Author

firefox_lChZV15qZX
(Copy-pasted from LibreOffice Writer into Firefox)

@rmw4269
Copy link

rmw4269 commented Sep 7, 2023

While this isn’t a perfect fix, it is simple, and the problem is also not a big issue. The text input field has this (simplified) HTML <span contenteditable="true">. The contenteditable attribute is what allows the element to act as a text input. Modifying the attribute to contenteditable="plaintext-only" should allow text input without formatting. This new-ish option is only supported in about 83% of desktop browsers, and some testing needs to be done to ensure that browsers that don’t support this still allow text input (as, technically, invalid values are supposed to use the ‘inherit’ state).

I think that support can be tested like below.

try {
	let e = document.createElement("span");
	e.contentEditable = "plaintext-only";
	// supported
	// Use contenteditable="plaintext-only".
} catch (error) {
	if (! (error instanceof SyntaxError)) { throw error; }
	// not supported
	// Use contenteditable="true", and add a listener similar to below, maybe triggered when the element loses focus.
	function listener({target}) {
		target.textContent = target.textContent;
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants