[Pushed] The 'redundant tags on paste of unformatted text' browser-dependent SCEditor bug
#1
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.
Reply
#2
Well stated and explained @Laird.  Wasn't sure about the browser dependency, but confirm Firefox appears unaffected:

copy/paste result - confirm Firefox appears unaffected

cheers...
Reply
#3
I can confirm... SCeditor is not good, we should think about a replacement for 1.9
[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system
Reply
#4
Thanks @nixer55 and @Eldenroot. Yep, SCEditor has quite a few "niggles". I'm personally not sure whether it's best to tackle them one by one in the MyBB fork or to simply replace it with another editor - I don't have much experience with other editors.

(2020-10-07, 04:26 PM)Laird Wrote: 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.

OK, I've come up with a solution that does work without any apparent drawbacks. In case it's not clear from the above quote, that solution was flawed because I was hard-coding the values for the default styles from jscripts/sceditor/styles/jquery.sceditor.mybb.css into jscript/bbcodes_sceditor.js.

The working solution I've come up with is to instead detect those values dynamically by pulling them out of the editor's iframe body.

Would be happy to supply a PR if anybody is kind enough to push this to GitHub as a confirmed bug.
Reply
#5
I think MYBB team si busy Sad
[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system
Reply
#6
Oh well, it's not urgent, so I guess we can wait.

But if anyone wants a fix right now, here's a full copy of jscripts/bbcodes_sceditor.js with all of my updates which fix all three of the SCEditor bugs I've recently reported, including this one. Should be save to simply overwrite your existing copy with this copy.


Attached Files
.js   bbcodes_sceditor.js (Size: 21.59 KB / Downloads: 47)
Reply
#7
Looks good based on early testing. Nice work! +1 from me.
Reply
#8
Thanks! Glad it's working for you so far.
Reply
#9
In post #5 of the thread for another SCEditor bug, noyle referred to something that I have been thinking about re the three SCEditor bugs I've recently reported: that the solutions I've provided may not address "the root cause". I agree with noyle. Why? Because it seems that none of these three bugs are present in the current code for MyBB 1.9, which uses SCEditor version 1.4.7. MyBB's 1.8 feature branch, on which these bugs are present, uses SCEditor version 2.1.3. The root cause, then, is presumably among whatever changes took place between SCEditor version 1.4.7 and SCEditor version 2.1.3, and/or, perhaps, the additional SCEditor-related Javascript files that MyBB provides and has updated since 1.9 was branched. I haven't (yet?) though dug in to try to identify those changes.
Reply
#10
(2020-10-13, 10:43 AM)Laird Wrote: In post #5 of the thread for another SCEditor bug, noyle referred to something that I have been thinking about re the three SCEditor bugs I've recently reported: that the solutions I've provided may not address "the root cause". I agree with noyle. Why? Because it seems that none of these three bugs are present in the current code for MyBB 1.9, which uses SCEditor version 1.4.7. MyBB's 1.8 feature branch, on which these bugs are present, uses SCEditor version 2.1.3. The root cause, then, is presumably among whatever changes took place between SCEditor version 1.4.7 and SCEditor version 2.1.3, and/or, perhaps, the additional SCEditor-related Javascript files that MyBB provides and has updated since 1.9 was branched. I haven't (yet?) though dug in to try to identify those changes.

Thanks for the investigation!

Don't know if @effone or @JordanMussi has any thoughts about this editor issue.
Could be wrong but worth a try.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)