Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enable unfinished-comments on temporarily-hidden text fields - #3767

Merged
fregante merged 2 commits into
refined-github:masterfrom
cheap-glitch:fix-unfinished-comments-preview
Nov 29, 2020
Merged

Enable unfinished-comments on temporarily-hidden text fields#3767
fregante merged 2 commits into
refined-github:masterfrom
cheap-glitch:fix-unfinished-comments-preview

Conversation

@cheap-glitch

@cheap-glitch cheap-glitch commented Nov 26, 2020

Copy link
Copy Markdown
Contributor

Thanks for contributing! 馃崉

  1. LINKED ISSUES: Closes unfinished-comments doesn't work after toggling Preview comment tab.聽#3765

  2. TEST URLS:

Tested on Firefox and Chromium in all possible cases (issue comment, PR comment, PR review comment). Side note: it also works on the "New issue"/"New PR" pages now, but we get the same "switching tabs right after posting" problem as we had for the comments (at least on Firefox).

@cheap-glitch cheap-glitch changed the title Detect unfinished comments that are being previewed Fix unfinished-comments for previewed comments Nov 26, 2020
Comment thread source/features/unfinished-comments.tsx Outdated
return select.all<HTMLTextAreaElement>('textarea:not([disabled])').some(textarea =>
textarea.value !== textarea.textContent && // Exclude comments being edited but not yet changed (and empty comment fields)
textarea.offsetWidth > 0 && // Exclude invisible fields
(textarea.offsetWidth > 0 || select('.js-preview-body', textarea.form!)!.textContent !== 'Nothing to preview') && // Exclude invisible fields that aren't being previewed

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.

Maybe this should be

Suggested change
(textarea.offsetWidth > 0 || select('.js-preview-body', textarea.form!)!.textContent !== 'Nothing to preview') && // Exclude invisible fields that aren't being previewed
(textarea.offsetWidth > 0 || select('.js-preview-body', textarea.form!)?.textContent !== 'Nothing to preview') && // Exclude invisible fields that aren't being previewed

?

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 think so because textarea isn't necessarily a comment.

However I think we should drop this check altogether since there are too many exceptions. For examples when you type a final review comment (in the "Review changes" dropdown) and then you close it.

Can you find a list all situations where there are hidden textareas that should be ignored?

@cheap-glitch cheap-glitch Nov 26, 2020

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.

After a bit of testing, I agree we can drop this check altogether. The only reason it was introduced in the first place is because I relied on just textarea.value.length to check for draft comments. But afaik the improved condition we're using now makes checking for hidden textareas redundant.

For examples when you type a final review comment (in the "Review changes" dropdown) and then you close it.

There's actually a case where it doesn't work regardless: when you review your own PR. It's caused by the disabled Approve and Request change buttons. I don't know how common that situation is though.

Can you find a list all situations where there are hidden textareas that should be ignored?

After testing the most common cases, I haven't found any. I'll try to think of possible edge cases.

@yakov116 yakov116 added the bug label Nov 26, 2020
@cheap-glitch

Copy link
Copy Markdown
Contributor Author

After a bit more testing, I found no cases where invisible textareas caused a problem. There are probably some situations I couldn't/didn't check, but at least the main use cases should be covered.

I did find a few bugs, maybe for another PR:

  • the feature doesn't work for the final review comment when you review your own PR (because of the disabled Approve and Request change buttons)
  • there are still a few cases where quickly switching to another tab can leave a dangling Draft comment in the tab title even though the comment has been sent:
    • when creating a new PR
    • when marking a PR discussion as "resolved" while writing a comment

@fregante fregante changed the title Fix unfinished-comments for previewed comments Enable unfinished-comments on temporarily-hidden text fields Nov 29, 2020
@fregante
fregante merged commit 02f197a into refined-github:master Nov 29, 2020
@fregante

Copy link
Copy Markdown
Member
  • the feature doesn't work for the final review comment when you review your own PR (because of the disabled Approve and Request change buttons)

Works for me!

nook

@fregante

Copy link
Copy Markdown
Member
  • when marking a PR discussion as "resolved" while writing a comment

That's fine for me since you didn't actually send the comment. It technically is still there

@cheap-glitch
cheap-glitch deleted the fix-unfinished-comments-preview branch November 29, 2020 23:26
@cheap-glitch

Copy link
Copy Markdown
Contributor Author
  • the feature doesn't work for the final review comment when you review your own PR (because of the disabled Approve and Request change buttons)

Works for me!

Did you try on a PR you opened yourself? Because in your example it doesn't seem like the buttons were disabled.

@Geeyun-JY3

Copy link
Copy Markdown

It seems that this feature only works on the "New issue"/"New PR" pages when the title textarea is not empty.

@cheap-glitch

cheap-glitch commented Dec 4, 2020

Copy link
Copy Markdown
Contributor Author

It seems that this feature only works on the "New issue"/"New PR" pages when the title textarea is not empty.

Yes, this is because GitHub disables the "Submit" button unless a title is entered. Seems like we need a special check for the new issues/PR pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

unfinished-comments doesn't work after toggling Preview comment tab.

4 participants