This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 14554 - Consider adding support for contenteditable=plaintext
Summary: Consider adding support for contenteditable=plaintext
Status: NEW
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: zz_retired (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Deadline: 2018-01-14
Assignee: This bug has no owner yet - up for the taking
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-24 22:38 UTC by Ryosuke Niwa
Modified: 2018-01-13 22:56 UTC (History)
10 users (show)

See Also:


Attachments

Description Ryosuke Niwa 2011-10-24 22:38:32 UTC
WebKit has been getting a lot of bugs reprots from developers who are trying to implement plaintext editable region. Facebook for example overlays invisible span on top of textarea to implement name highlighting.

It'll be much better if UAs supported plaintext editable region (user can only insert plaintext but authors can insert rich content to highlight text, etc...).
Comment 1 Jonas Sicking (Not reading bugmail) 2011-10-24 22:43:33 UTC
This is a really good idea!

Though lots of edge cases which needs to be handled. What happens in the following markup for example:

<div contenteditable=plaintext>This word is <span style="color:blue">not green</span>!. <table><tr><td>And this is in a table</table></div>

Or what happens if the same type of elements are inserted using the DOM?
Comment 2 Jonas Sicking (Not reading bugmail) 2011-10-24 22:45:05 UTC
I guess one solution would be that any DOM elements that are there (through markup or though DOM) are rendered as normal. However execCommand and user editing keystrokes (including pasting) can only insert plaintext.
Comment 3 Ehsan Akhgari [:ehsan] 2011-10-24 23:51:11 UTC
Is there anything here which cannot be handled by the beforeeditingaction/aftereditingaction events?
Comment 4 Ryosuke Niwa 2011-10-24 23:59:44 UTC
(In reply to comment #3)
> Is there anything here which cannot be handled by the
> beforeeditingaction/aftereditingaction events?

Supporting paste will be annoying because you'd have to grab plain text out of the clipboard. Also, declarative notation is much easier to use than having to listen to those events and decide which one to allow.
Comment 5 Ehsan Akhgari [:ehsan] 2011-10-25 01:07:11 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > Is there anything here which cannot be handled by the
> > beforeeditingaction/aftereditingaction events?
> 
> Supporting paste will be annoying because you'd have to grab plain text out of
> the clipboard.

True.  But we can fix that by providing a property on the event object which returns the plaintext content on the clipboard or something to that effect.

> Also, declarative notation is much easier to use than having to
> listen to those events and decide which one to allow.

What makes me hesitate here is that there are a fair number of edge cases to be handled here, such as nested contenteditable elements of different types, things like form controls and images in plaintext contenteditable elements, the way that selections spanning multiple types of contenteditable elements should behave in response to editing commands, etc.

If anything, this needs to be very carefully specified.
Comment 6 Anne 2011-10-25 02:08:59 UTC
The alternative here would be to provide a way to style DOM ranges. <textarea>.addCSSRange(range, identifier) or some such and ::range(identifier) in CSS.
Comment 7 Ehsan Akhgari [:ehsan] 2011-10-25 02:13:03 UTC
(In reply to comment #6)
> The alternative here would be to provide a way to style DOM ranges.
> <textarea>.addCSSRange(range, identifier) or some such and ::range(identifier)
> in CSS.

That would not give web content access to the DOM behind the textarea though (unless it's exposed as shadow DOM, which might introduce other problems).
Comment 8 Anne 2011-10-25 02:26:06 UTC
The case comment 0 described does not require access to the DOM, but I suppose there may be cases that do?
Comment 9 Ian 'Hixie' Hickson 2012-12-19 20:48:08 UTC
Another example of a use case for something like this is the Google+ post editor, which is a markdown-style editor, but supports first-class objects other than text, e.g. if you type "+Ian Hickson" it turns into a chip that represents my profile. The idea in the context of this bug would be for this to be implemented as a plaintext-only contenteditable region, with the script manipulating the DOM to provide features such as the chips as non-editable movable subregions.
Comment 10 Juriy "kangax" Zaytsev 2015-10-20 08:04:15 UTC
(In reply to Ehsan Akhgari [:ehsan] from comment #5)
> (In reply to comment #4)
> > (In reply to comment #3)
> > > Is there anything here which cannot be handled by the
> > > beforeeditingaction/aftereditingaction events?

[...]

> What makes me hesitate here is that there are a fair number of edge cases to
> be handled here, such as nested contenteditable elements of different types,
> things like form controls and images in plaintext contenteditable elements,
> the way that selections spanning multiple types of contenteditable elements
> should behave in response to editing commands, etc.

Nested elements seem fairly trivial — anything within plaintext is rendered as plaintext (even if it contains non-plaintext contenteditable elements). Overlapping selection is trickier. I wonder what WebKit/Chrome do in this case. 

It's unfortunate that we still don't have plaintext insertion and so everyone ends up reinventing the wheel again and again: facebook uses overlay; google plus uses non-standard plaintext and seems to enliven it with JS for non-supporting clients; medium intercepts all operations and maintains internal model; so does few-days-ago-released Trix editor; grammarly.com uses textarea with overlay just like facebook; few other sites implement some kind of hybrid solutions via a series of contenteditable lines; and so on.

Clearly, a better mechanism is desperately needed. I'm not sure if plaintext is the answer but it certainly looks very helpful.