Skip to content
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

Merged
merged 13 commits into from
Jan 19, 2021

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Jan 18, 2021

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:

function setInit(id) {
var args = {
'textarea': 'c'+id+'text',
'preview': 'c'+id+'preview'
}
$E.initialize(args);
}

I think $E.initialize is used for two different cases, and I'm trying to make a greater distinction between the two:

  1. $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
  2. $E.initialize when we want the editor textarea to change on a multi-comment page, as in the above example. For this case, we can use the new setState 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)

@noi5e noi5e requested review from a team as code owners January 18, 2021 23:32
@gitpod-io
Copy link

gitpod-io bot commented Jan 18, 2021

@codecov
Copy link

codecov bot commented Jan 18, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@7ed8474). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9035   +/-   ##
=======================================
  Coverage        ?   82.05%           
=======================================
  Files           ?      100           
  Lines           ?     5939           
  Branches        ?        0           
=======================================
  Hits            ?     4873           
  Misses          ?     1066           
  Partials        ?        0           

@noi5e noi5e added feature explains that the issue is to add a new feature JavaScript outreachy labels Jan 18, 2021
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oohhhh!!! 🤗

Copy link
Member

@jywarren jywarren left a 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;
Copy link
Contributor Author

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?

Copy link
Contributor Author

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!

@codeclimate
Copy link

codeclimate bot commented Jan 19, 2021

Code Climate has analyzed commit 2f04589 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Collaborator

@cesswairimu cesswairimu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow 🚀 Great job

@cesswairimu cesswairimu merged commit f82a11c into publiclab:main Jan 19, 2021
@jywarren
Copy link
Member

jywarren commented Jan 19, 2021 via email

@noi5e noi5e deleted the feature/E-initialize-default-params branch January 19, 2021 17:01
@noi5e noi5e changed the title Feature: Add setState Method in editor.js Add setState Method in editor.js Jan 23, 2021
manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
* 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
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
* 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
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* 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
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature explains that the issue is to add a new feature JavaScript outreachy readytomerge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants