-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add setState Method in editor.js #9035
Add setState Method in editor.js #9035
Conversation
Codecov Report
@@ Coverage Diff @@
## main #9035 +/- ##
=======================================
Coverage ? 82.05%
=======================================
Files ? 100
Lines ? 5939
Branches ? 0
=======================================
Hits ? 4873
Misses ? 1066
Partials ? 0 |
@@ -29,12 +29,10 @@ jQuery(function() { | |||
}); | |||
|
|||
$(this).on('drop',function(e) { | |||
const params = getEditorParams(e.target); // defined in editorHelper.js | |||
const { textArea, preview, dSelected } = getEditorParams(e.target); // defined in editorHelper.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oohhhh!!! 🤗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I like the separation of functions!
wrap: function(a, b, args) { | ||
// we only refresh $E's values if we are on a page using the rich-text editor (most pages). | ||
// the legacy editor pages only have one editor form, unlike pages with multiple comments. | ||
if (this.isRichTextEditor(window.location.pathname)) { this.refresh(); } | ||
var len = $E.textarea.val().length; | ||
var start = $E.textarea[0].selectionStart; | ||
var end = $E.textarea[0].selectionEnd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren codeclimate won't let this pass because of 'cognitive complexity' in the wrap function... I think the rules are stricter now since the recent changes in CI.
Honestly, I have a feeling that it's the older stuff later on in the method that's holding this back (conditionals like args && args['fallback']
, a nested if statement inside if (args && args['newline'])
. I'm not very familiar with this code yet, can you take a look and let me know if you have any ideas to simplify things here so this can pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren Never mind! I got it to work. Tests are passing now too.
Ready to merge!
Code Climate has analyzed commit 2f04589 and detected 0 issues on this pull request. View more on Code Climate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow 🚀 Great job
Awesome work!!!!!
…On Tue, Jan 19, 2021, 4:37 AM Cess ***@***.***> wrote:
Merged #9035 <#9035> into main.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9035 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6J7FZMDLRSTBUHDDCRTS2VHGTANCNFSM4WH6VBPA>
.
|
* write setState method with default parameters publiclab#9004 * set preview when calling E.setState publiclab#9004 * set preview when calling E.setState publiclab#9004 * change E.initialize to E.setState; add comment-preview class publiclab#9004 * change E.initialize({}) to E.initialize() publiclab#9004 * change regex test to match /features/new in wrap publiclab#9004 * rewrite selector for more specificity publiclab#9004 * rewrite for cognitive complexity publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * oops, switched ternary operator publiclab#9004
* write setState method with default parameters publiclab#9004 * set preview when calling E.setState publiclab#9004 * set preview when calling E.setState publiclab#9004 * change E.initialize to E.setState; add comment-preview class publiclab#9004 * change E.initialize({}) to E.initialize() publiclab#9004 * change regex test to match /features/new in wrap publiclab#9004 * rewrite selector for more specificity publiclab#9004 * rewrite for cognitive complexity publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * oops, switched ternary operator publiclab#9004
* write setState method with default parameters publiclab#9004 * set preview when calling E.setState publiclab#9004 * set preview when calling E.setState publiclab#9004 * change E.initialize to E.setState; add comment-preview class publiclab#9004 * change E.initialize({}) to E.initialize() publiclab#9004 * change regex test to match /features/new in wrap publiclab#9004 * rewrite selector for more specificity publiclab#9004 * rewrite for cognitive complexity publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * oops, switched ternary operator publiclab#9004
* write setState method with default parameters publiclab#9004 * set preview when calling E.setState publiclab#9004 * set preview when calling E.setState publiclab#9004 * change E.initialize to E.setState; add comment-preview class publiclab#9004 * change E.initialize({}) to E.initialize() publiclab#9004 * change regex test to match /features/new in wrap publiclab#9004 * rewrite selector for more specificity publiclab#9004 * rewrite for cognitive complexity publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * desperately trying to pass codeclimate publiclab#9004 * oops, switched ternary operator publiclab#9004
This is a small part of a larger object-oriented refactoring for
editor.js
, see #9004 for details.Basically the major change here is that I am creating a setState method for use in cases like this:
plots2/app/views/comments/_edit.html.erb
Lines 42 to 48 in f0be879
I think
$E.initialize
is used for two different cases, and I'm trying to make a greater distinction between the two:$E.initialize
when the document loads, and the editor must point toward the main comment form (or the only editor form on the page, in the case of/wiki/new
,/wiki/edit
, and/features/new
$E.initialize
when we want the editortextarea
to change on a multi-comment page, as in the above example. For this case, we can use the newsetState
method instead.I have confidence this is going to help!!!
(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)