-
Notifications
You must be signed in to change notification settings - Fork 1.2k
When pressing ctrl+enter on a markdown cell, unfocus it so it renders #11162
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
Conversation
unfocus it so it renders
@@ -448,6 +448,11 @@ export class NativeCell extends React.Component<INativeCellProps> { | |||
e.stopPropagation(); | |||
e.preventDefault(); | |||
|
|||
// Unfocus the current cell if it is markdown to make it render | |||
if (this.isMarkdownCell() && this.wrapperRef && this.wrapperRef.current && this.isFocused()) { | |||
this.wrapperRef.current.focus(); |
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.
this should probably use the this.props.unfocusCell instead. Although it would have the same net effect.
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's an issue with doing that, by focusing again on the same cell we still are in command mode. If I do the unfocusCell it unfocuses a lot and I can't use the commands anymore, I'd have to click on the notebook again.
Maybe I could change the comment to say 'unfocus and focus back'?
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.
Not sure I understand this part:
If I do the unfocusCell it unfocuses a lot
Shouldn't it just unfocus this one cell? What do you mean by it unfocuses a lot?
In reply to: 408468988 [](ancestors = 408468988)
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.
Are you saying the notebook itself no longer has focus?
In reply to: 408469794 [](ancestors = 408469794,408468988)
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.
yes, pressing up or down no longer works, you need to click the notebook
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.
btw, focusing in the wrapper is the same behavior as pressing escape. I think that's good enough.
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.
Escape handling does look similar to this. Honestly I find some of the focus handling a bit twisty myself. So after you do a ctrl+enter on a markdown cell our HTML focus is on the wrapping div, but the cell vm state is still both selected and focused, is that right?
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.
The blue bar appears, I think so. I'll check.
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.
Can confirm, its still selected and focused.
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.
🕐
Codecov Report
@@ Coverage Diff @@
## master #11162 +/- ##
==========================================
+ Coverage 61.41% 61.43% +0.02%
==========================================
Files 596 596
Lines 32848 32874 +26
Branches 4655 4659 +4
==========================================
+ Hits 20173 20196 +23
+ Misses 12465 11659 -806
- Partials 210 1019 +809
Continue to review full report at Codecov.
|
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.
I'd like to have a look tomorrow. Not happy that we're setting focus/unfocus like this. We had a few issues in the past.
Not saying the fix is not correct
Blocking till I check it out, thanks and sorry
@@ -448,6 +448,11 @@ export class NativeCell extends React.Component<INativeCellProps> { | |||
e.stopPropagation(); | |||
e.preventDefault(); | |||
|
|||
// Unfocus the current cell if it is markdown to make it render | |||
if (this.isMarkdownCell() && this.wrapperRef && this.wrapperRef.current && this.isFocused()) { | |||
this.wrapperRef.current.focus(); |
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.
Please could we try to use existing mechanisms to set focus to the editor.
@@ -448,6 +448,11 @@ export class NativeCell extends React.Component<INativeCellProps> { | |||
e.stopPropagation(); | |||
e.preventDefault(); | |||
|
|||
// Refocus the current cell if it is markdown to make it render | |||
if (this.isMarkdownCell() && this.wrapperRef && this.wrapperRef.current && this.isFocused()) { | |||
this.wrapperRef.current.focus(); |
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.
this.wrapperRef.current.focus(); | |
this.escapeCell(e); |
Please can we use escapeCell
, at the end of the day thats what is required. We need to escape the cell. Manually focussing does the exact same thing, but this way its obvious what we are doing and why. With the other approach its unclear. I.e. we know hitting escape will render the markdown, hence we're merely using existing behaviour.
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.
ok
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.
Also, I would remove the comments as it isn't necessary, at least thats my opinion, cuz to me its a little confusing (cuz we want to focus the cell however isFocused
is already true for the nativeCell
- i.e. contradictory).
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.
The comment now says: // Escape the current cell if it is markdown to make it render
Kudos, SonarCloud Quality Gate passed!
|
For #10006
package-lock.json
has been regenerated by runningnpm install
(if dependencies have changed).