Skip to content

Add collapsible content button - #1804

Merged
sindresorhus merged 26 commits into
refined-github:masterfrom
doms:doms/insert-summary-button
Mar 3, 2019
Merged

sindresorhus merged 26 commits into
refined-github:masterfrom
doms:doms/insert-summary-button

Conversation

@doms

@doms doms commented Feb 21, 2019

Copy link
Copy Markdown
Contributor

What

closes #1670

Notes

Still learning how to web dev, and using this PR as a learning opportunity. Looking forward to feedback!

I wasn't sure what icon to use for the toolbar button for inserting a summary, so I used the info just for representation, but can change it to something else if needed.


I might be overthinking it, but I'm not sure how to properly insert the details block into the textarea without it being formatted into a block of text. 🤔

This:

<details>
  <summary>Some text</summary>
  then here is some long text you want to hide
</details>

gets formatted as a block of text when I use string interpolation, or if I try to insert as innerHTML, it comes out like so:

[object HTMLDetailsElement]


I'm also getting a console error:

Uncaught DOMException: Failed to construct 'CustomElement': The result must not have attributes

But I've tried to follow the format of existing features as much as possible and am not sure what I am doing wrong..

const pos = commentField.selectionStart;
const currentVal = commentField.value;
const before = currentVal.substring(0, pos);
const after = currentVal.substring(pos);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We prefer slice over substring.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why by the way?

@doms

doms commented Feb 22, 2019

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback and helpful tips! It also helped me realize I needed to make a couple extra changes that weren't pointed out (e.g. adding the "insert summary" button to all <markdown-toolbar>'s for existing comments too, rather than just the new comment one)

@doms
doms marked this pull request as ready for review February 22, 2019 07:25
@fregante fregante self-assigned this Feb 22, 2019
@fregante fregante removed their assignment Feb 22, 2019
@fregante

Copy link
Copy Markdown
Member

Here's what it looks like now:

@fregante

fregante commented Mar 1, 2019

Copy link
Copy Markdown
Member

@doms Let's apply the latest suggested changes and merge this soon ^_^

@doms

doms commented Mar 1, 2019

Copy link
Copy Markdown
Contributor Author

@bfred-it Sorry for the lack of updates, I've been super busy! I took some time to try implementing an idempotent delegate (and reading up on multi-key WeakMaps) and tried to make sense of it by playing around with the concepts in that thread, but I wasn't able to come up with something different than the other proposed implementations.. (well, that and my code was a mess 😅 )

@fregante

fregante commented Mar 1, 2019 •

Copy link
Copy Markdown
Member

I took some time to try implementing an idempotent delegate

You can skip that for this PR, it'd mean (re-)writing and publishing 2 unrelated modules. The current code already works in here.

@doms

doms commented Mar 1, 2019

Copy link
Copy Markdown
Contributor Author

I believe renaming the feature was the last suggested change that needed to be done! 😄

@fregante fregante assigned fregante and unassigned doms Mar 2, 2019
@fregante

fregante commented Mar 2, 2019 •

Copy link
Copy Markdown
Member

a

@fregante fregante removed their assignment Mar 2, 2019

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is good to go for me. Please review one last time

@fregante fregante changed the title Add button to insert summary Add collapsible content button Mar 2, 2019
newlinesToPrepend = '\n'.repeat(2 - whitespaceAtStart.length);
}

if (after.match(/\S/) && whitespaceAtEnd.length < 2) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wow, this is a really cool way to dynamically determine the amount of whitespace to lead/trail with!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wish it wasn't so wordy. Thanks to GitHub's code at least I didn't have to reinvent the wheel.

@sindresorhus
sindresorhus merged commit 547795c into refined-github:master Mar 3, 2019
@sindresorhus

Copy link
Copy Markdown
Member

This looks great. Thanks for working on it, @doms :)

@doms
doms deleted the doms/insert-summary-button branch March 3, 2019 18:29
@fregante fregante mentioned this pull request Mar 30, 2019
@SunsetTechuila SunsetTechuila mentioned this pull request Feb 2, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Add button to insert summary

3 participants