Skip to content

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

Merged
merged 4 commits into from
Apr 15, 2020

Conversation

DavidKutu
Copy link

For #10006

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR).
  • Title summarizes what is changing.
  • Has a news entry file (remember to thank yourself!).
  • Appropriate comments and documentation strings in the code.
  • Has sufficient logging.
  • Has telemetry for enhancements.
  • Unit tests & system/integration tests are added/updated.
  • Test plan is updated as appropriate.
  • package-lock.json has been regenerated by running npm install (if dependencies have changed).
  • The wiki is updated with any design decisions/details.

@@ -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();
Copy link

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.

Copy link
Author

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'?

Copy link

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)

Copy link

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)

Copy link
Author

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

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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.

Copy link
Author

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.

Copy link

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

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

🕐

@codecov-io
Copy link

codecov-io commented Apr 14, 2020

Codecov Report

Merging #11162 into master will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/datascience-ui/react-common/arePathsSame.ts 75.00% <0.00%> (-12.50%) ⬇️
src/client/common/utils/platform.ts 64.70% <0.00%> (-11.77%) ⬇️
src/client/linters/pydocstyle.ts 86.66% <0.00%> (-2.23%) ⬇️
src/client/datascience/debugLocationTracker.ts 76.56% <0.00%> (-1.57%) ⬇️
...client/datascience/kernel-launcher/kernelFinder.ts 75.70% <0.00%> (-0.94%) ⬇️
src/client/common/process/proc.ts 14.49% <0.00%> (-0.73%) ⬇️
...ient/interpreter/locators/services/condaService.ts 85.55% <0.00%> (-0.08%) ⬇️
src/client/datascience/webViewHost.ts 9.31% <0.00%> (-0.06%) ⬇️
src/client/testing/main.ts 14.38% <0.00%> (ø)
src/client/common/editor.ts 8.25% <0.00%> (ø)
... and 174 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eab579f...c7a16b8. Read the comment docs.

Copy link

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link

@DonJayamanne DonJayamanne left a 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();

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();

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Author

Choose a reason for hiding this comment

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

ok

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).

Copy link
Author

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

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@DavidKutu DavidKutu requested a review from DonJayamanne April 15, 2020 17:32
@DavidKutu DavidKutu merged commit 02ff345 into master Apr 15, 2020
@DavidKutu DavidKutu deleted the davidkutu/latexNotRendering branch April 15, 2020 18:51
@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants