Bug 204622 - 'FontName' command too aggressive
Summary: 'FontName' command too aggressive
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-26 08:09 PST by Milan Crha
Modified: 2019-11-27 00:48 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Milan Crha 2019-11-26 08:09:44 PST
I'd like to let the users change font when they edit HTML content. The 'FontName' editing command looks like a natural choice. The only problem with it (apart of not being able to unset the font name, or do not know how to do it) is that it is too aggressive.

Open the WebKit inspector and execute these two commands:

   document.documentElement.innerHTML = "<body><div>aaa</div><div>bbb</div><div>ccc</div></body>";
   document.body.style.fontFamily = "Tahoma";

which produces this HTML structure:

   <body style="font-family: Tahoma;">
      <div>aaa</div>
      <div>bbb</div>
      <div>ccc</div>
   </body>

Then select the middle 'b' of the three 'bbb' by mouse and execute:

   document.execCommand("FontName", false, "monopace");

What I'd expect after this change is to have only the middle 'b' enclosed in the <font> tag, something like this (only the middle paragraph changed):

   <body style="font-family: Tahoma;">
      <div>aaa</div>
      <div>b<font face="monospace">b</font>b</div>
      <div>ccc</div>
   </body>

But the 'FontName' commands changes all around the HTML structure, due to the body's style it seems, and produces this complicated HTML code:

   <body>
      <div style="font-family: Tahoma;">aaa</div>
      <div><font face="Tahoma">b</font><font face="monopace">b</font><font face="Tahoma">b</font></div>
      <div style="font-family: Tahoma;">ccc</div>
   </body>

In other words, it removed the style from the 'body' and propagated it into every paragraph, except of the middle paragraph, where it split the text into three separate <font> tags. It is equivalent here, but maybe I could be able to find more complicated HTML structure where the change would cause format changes. Apart of being unnecessarily complicated HTML code, it also has some consequences, like not being able to undo this in an efficient way (I do my own undo/redo code). I do not think the consequences are the main argument against the current behaviour, I'm only mentioning it as the second reason why this is not ideal.

Not using body's 'style' property, but having defined CSS style with:

   body { font-family:tahoma;}

in <head><style></style></head> makes this work as expected.