2020-10-07, 04:26 PM
(This post was last modified: 2020-10-07, 05:00 PM by Laird. Edited 3 times in total.)
This SCEditor bug and the next of the other two I plan to report (and now have reported) reference Hovatek's thread MyCode parse error ( [font="droid sans", sans-serif] ) and nixer55's post #29 in the SCEditor Issues and Resolutions [1.8.21 upgrade] thread (the remaining bug references only Hovatek's thread).
All three bug reports are heavily based on my post #9 in Hovatek's thread, from the first horizontal line onwards.
Specific to this bug report:
The 'redundant tags on paste of unformatted text' browser-dependent SCEditor bug.
Description: In WYSIWYG mode, on pasting unformatted text into the editor which was cut/copied from elsewhere within the editor, some browsers (e.g., Chrome and Microsoft Edge) generate redundant font+size+color attributes in the paste data whose values reflect the editor's default style (based on the default stylesheet jscripts/sceditor/styles/jquery.sceditor.mybb.css), causing redundant MyCode tags with those default font+size+color attributes to be generated (except for the font tag, to which a different bug applies, to be reported next). Other browsers (e.g., Firefox) don't generate redundant attributes, and are not subject to this bug.
How to reproduce: In Chrome or Microsoft Edge, bring up a new editor window through a page such as a New Reply page. Deselect Source mode if it is selected, such that the editor is in WYSIWYG mode. Now, type some text into it, such as "Blah". Do not style or format that text in any way. Now, select that text, cut or copy it, then paste it, and switch to Source mode. You will see that the pasted text has had font, color, and size MyCode tags added to it even though it was unformatted and unstyled prior to being pasted, and thus should not have had any MyCode tags applied to it.
Impact: Mild-moderate. Not detectable in WYSIWYG mode (except in the form of the next bug I plan to report, the 'reduced size on paste of unformatted text' browser-dependent SCEditor bug); irritating when switching to Source mode.
Potential but flawed solution: Because this bug stems from some browsers (but not others) redundantly setting values for style attributes in pasted text that are already at their default values, the "obvious" fix is to edit appropriate sections of jscript/bbcodes_sceditor.js such that default values of those size/font/color attributes are detected and ignored, and so that no tag is thus added in those scenarios. I have tested this approach - for size, font, and color tags - and it does work on a default MyBB installation, resolving both this bug and the next to be reported. The problem, however, is that it involves hard-coding those default style values into this Javascript file based on those in the default stylesheet - again, jscripts/sceditor/styles/jquery.sceditor.mybb.css - whereas, as Hovatek's scenario demonstrates, those default stylesheet values might be changed (customised) by themes. That is to say that, for example, the default font-family specified in (again) jscripts/sceditor/styles/jquery.sceditor.mybb.css is 'Tahoma, Verdana, Arial, Sans-Serif', whereas for Hovatek's forum it appears instead to have been customised to '"droid sans", sans-serif'. Detecting and ignoring in Javascript the default font-family for the editor as specified in (again) jscripts/sceditor/styles/jquery.sceditor.mybb.css would thus fail on Hovatek's forum, because his theme has overridden that default font-family.
All three bug reports are heavily based on my post #9 in Hovatek's thread, from the first horizontal line onwards.
Specific to this bug report:
The 'redundant tags on paste of unformatted text' browser-dependent SCEditor bug.
Description: In WYSIWYG mode, on pasting unformatted text into the editor which was cut/copied from elsewhere within the editor, some browsers (e.g., Chrome and Microsoft Edge) generate redundant font+size+color attributes in the paste data whose values reflect the editor's default style (based on the default stylesheet jscripts/sceditor/styles/jquery.sceditor.mybb.css), causing redundant MyCode tags with those default font+size+color attributes to be generated (except for the font tag, to which a different bug applies, to be reported next). Other browsers (e.g., Firefox) don't generate redundant attributes, and are not subject to this bug.
How to reproduce: In Chrome or Microsoft Edge, bring up a new editor window through a page such as a New Reply page. Deselect Source mode if it is selected, such that the editor is in WYSIWYG mode. Now, type some text into it, such as "Blah". Do not style or format that text in any way. Now, select that text, cut or copy it, then paste it, and switch to Source mode. You will see that the pasted text has had font, color, and size MyCode tags added to it even though it was unformatted and unstyled prior to being pasted, and thus should not have had any MyCode tags applied to it.
Impact: Mild-moderate. Not detectable in WYSIWYG mode (except in the form of the next bug I plan to report, the 'reduced size on paste of unformatted text' browser-dependent SCEditor bug); irritating when switching to Source mode.
Potential but flawed solution: Because this bug stems from some browsers (but not others) redundantly setting values for style attributes in pasted text that are already at their default values, the "obvious" fix is to edit appropriate sections of jscript/bbcodes_sceditor.js such that default values of those size/font/color attributes are detected and ignored, and so that no tag is thus added in those scenarios. I have tested this approach - for size, font, and color tags - and it does work on a default MyBB installation, resolving both this bug and the next to be reported. The problem, however, is that it involves hard-coding those default style values into this Javascript file based on those in the default stylesheet - again, jscripts/sceditor/styles/jquery.sceditor.mybb.css - whereas, as Hovatek's scenario demonstrates, those default stylesheet values might be changed (customised) by themes. That is to say that, for example, the default font-family specified in (again) jscripts/sceditor/styles/jquery.sceditor.mybb.css is 'Tahoma, Verdana, Arial, Sans-Serif', whereas for Hovatek's forum it appears instead to have been customised to '"droid sans", sans-serif'. Detecting and ignoring in Javascript the default font-family for the editor as specified in (again) jscripts/sceditor/styles/jquery.sceditor.mybb.css would thus fail on Hovatek's forum, because his theme has overridden that default font-family.