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 more comment field shortcuts #961

Merged
merged 7 commits into from
Jan 7, 2018
Merged

Add more comment field shortcuts #961

merged 7 commits into from
Jan 7, 2018

Conversation

niklashigi
Copy link
Contributor

This pull request addresses two issues by adding new shortcuts to comment fields.

Esc to blur comment field

When the user is inside an empty comment field and presses Esc the comment field will be unfocussed/"blurred".

Closes #848

Up to edit last comment

When the user is inside the "Leave a comment" field at the bottom of issues and presses Up while the field is empty, Refined GitHub will .click() the edit button of the last comment by the user and put the caret at the end of the input field.

Closes #858

} else if (event.key === 'ArrowUp') {
if (field.id === 'new_comment_field' && field.value === '') {
const comments = select.all('.js-comment')
.filter(el => select('.author', el).textContent === getUsername());
Copy link
Contributor

Choose a reason for hiding this comment

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

This fails because issue title edit forms also have a .js-comment class but don't contain .author. Either check if it's an issue title form or check if the .author element exists before accessing its textContent.

@jgierer12
Copy link
Contributor

I'd prefer it if the whole comment would be pre-selected:

requestAnimationFrame(() => {
  const commentField = select('.js-comment-field', lastOwnComment);
  commentField.setSelectionRange(0, 1000);
});

@fregante
Copy link
Member

fregante commented Jan 7, 2018

I'd prefer it if the whole comment would be pre-selected:

How is that useful?

@jgierer12
Copy link
Contributor

Hmm yeah on second thought it probably isn't. Somehow I thought Slack did it like that too but it places the cursor at the end as well.

However, select('.js-comment-field', lastOwnComment).selectionStart = 1000000; doesn't work for me at all, it leaves the cursor at the start.

@fregante
Copy link
Member

fregante commented Jan 7, 2018

Strange, it worked in my initial tests, now it doesn't

@jgierer12 jgierer12 merged commit c13df57 into refined-github:master Jan 7, 2018
@fregante
Copy link
Member

fregante commented Jan 7, 2018

Sweet!

@jgierer12
Copy link
Contributor

Thank you @shroudedcode!

@jgierer12
Copy link
Contributor

Ah, forgot the readme update

jgierer12 added a commit that referenced this pull request Jan 7, 2018
@niklashigi niklashigi deleted the comment-field-shortcuts branch January 7, 2018 13:09
if (field.value === '') {
blurAccessibly(field);
} else if (inlineCancelButton) {
inlineCancelButton.click();
Copy link

Choose a reason for hiding this comment

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

I lost so many comments because of this! I frequently write :p but github doesn't know this emoji and opens an autocomplete with :package: & co. So I type escape to hide the autocomplete and it closes the entire comment form with no warning and all my text is lost :(

Few suggestions:

  • Check if the autocomplete is visible and do not trigger this action if it is
  • If there's content, ask for confirmation before deleting all the content

Copy link
Member

@fregante fregante Mar 8, 2018

Choose a reason for hiding this comment

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

If there's content, ask for confirmation before deleting all the content

We do. Where does that happen exactly? Can you provide a URL where I can leave a comment that gets lost?

Are you on Chrome?

Do you have any disabled features?

Copy link

Choose a reason for hiding this comment

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

I'm using Chrome.

I didn't disable any feature (well, until I found out about this issue and disabled add-keyboard-shortcuts-to-comment-fields which stops this behavior from happening).

I was able to repro pressing escape on this very comment. I don't see any warning saying that i'm about to discard the comment when pressing escape or pressing cancel.

Copy link

Choose a reason for hiding this comment

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

Repro steps:

  • Reply to this comment
  • Press escape
  • The whole reply box disappears with no confirmation

[Before pressing escape]

image

[After pressing escape]

screen shot 2018-03-08 at 10 33 57 am

Copy link

Choose a reason for hiding this comment

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

As I'm playing around with it, it doesn't always repro. Sometimes I do get a confirmation dialog, sometimes I don't. I can't see any error in the js console.

Copy link
Member

Choose a reason for hiding this comment

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

I can't repro at all, I always get the confirmation

gif

Copy link

Choose a reason for hiding this comment

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

Okay this is crazy, I can no longer repro... I'll reply here if I can get a repro and figure out what could happen. Sorry for the false alarm.

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.

4 participants