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

improve: Hide code by default for Markdown cells #2507

Merged
merged 10 commits into from
Oct 10, 2024
Merged

Conversation

wasimsandhu
Copy link
Collaborator

@wasimsandhu wasimsandhu commented Oct 6, 2024

📝 Summary

Create Markdown cells on the frontend with hide_code set to true by default. Closes #2389.

🔍 Description of Changes

With @akshayka's change in #2504, this makes it so that the code editor for a Markdown cell is shown when editing, but hidden when the cell is not focused.

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • I have added tests for the changes made.
  • I have run the code and verified that it works as expected.

@wasimsandhu wasimsandhu added the enhancement New feature or request label Oct 6, 2024
@wasimsandhu wasimsandhu self-assigned this Oct 6, 2024
Copy link

vercel bot commented Oct 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 0:22am
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 0:22am

@wasimsandhu
Copy link
Collaborator Author

wasimsandhu commented Oct 6, 2024

While testing this, I noticed that I can't click the Delete button for a hidden Markdown cell anymore. The "show code / hide code" overlay keeps getting triggered instead. Tried messing around with the z-index but couldn't get it to work.

Screenshot 2024-10-06 at 12 02 29 PM

@akshayka
Copy link
Contributor

akshayka commented Oct 6, 2024

I imagined this being config driven, with new markdown cells defaulting to hide_code=True, but this may work. Let me play with it and see how it feels.

@wasimsandhu
Copy link
Collaborator Author

Yeah we should probably just do that for behavioral consistency.

@akshayka
Copy link
Contributor

akshayka commented Oct 6, 2024

While testing this, I noticed that I can't click the Delete button for a hidden Markdown cell anymore. The "show code / hide code" overlay keeps getting triggered instead. Tried messing around with the z-index but couldn't get it to work.

Oh that must be a consequence of #2504 ...

@wasimsandhu I have a fix for this, will create a separate PR.

Copy link
Contributor

@mscolnick mscolnick left a comment

Choose a reason for hiding this comment

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

i love the few line changes like this that bring such good QOL improvements.

@@ -241,6 +242,10 @@ const {
}
}

const isMarkdown = newCellCode
? LanguageAdapters.markdown().isSupported(newCellCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

isSupported returns true for empty string ""., maybe we could check its not empty as well, or add a function isMarkdown

@wasimsandhu
Copy link
Collaborator Author

@akshayka Not sure why I thought this change was on the frontend only. Every new Markdown cell that is created now has config.hide_code set to True by default, which will get serialized like normal in the notebook file.

Comment on lines 342 to 343
editorViewParentRef.current?.addEventListener(
editorViewRef.current?.contentDOM.addEventListener(
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, looks like my fix in #2508 got reverted. Is this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

Following up with a fix, blur -> focusout

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes sorry, I left a comment on that PR but forgot to put one here. And thanks, that did the trick!

Copy link
Collaborator Author

@wasimsandhu wasimsandhu Oct 9, 2024

Choose a reason for hiding this comment

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

Well actually, it looks like you can't delete cells with the button again... Should we just move it somewhere else?

// For a newly created Markdown cell, which defaults to
// hidden code, we temporarily show the code editor
useEffect(() => {
if (!(isMarkdown(code) && code === `mo.md(r"""\n""")`)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do if (code === new MarkdownLanguageAdapter().defaultCode)

return;
}
temporarilyShowCode();
}, [code, temporarilyShowCode]);
Copy link
Contributor

Choose a reason for hiding this comment

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

i might be better to just remove temporarilyShowCode and add the eslint disable. clearer that it only react to code changes

@wasimsandhu wasimsandhu merged commit 9a674dc into main Oct 10, 2024
24 checks passed
@wasimsandhu wasimsandhu deleted the wasim/hide-md-editor branch October 10, 2024 05:12
akshayka added a commit that referenced this pull request Oct 10, 2024
This reverts commit 9a674dc.

The logic for temporarily showing code for markdown cells is incorrect
and causing all hidden cells to not render as hidden
akshayka added a commit that referenced this pull request Oct 10, 2024
)

This reverts commit 9a674dc.

The logic for temporarily showing code for markdown cells is incorrect
and causing all hidden cells to not render as hidden.

We can fix and restore in a follow up
mscolnick pushed a commit that referenced this pull request Dec 3, 2024
## 📝 Summary

<!--
Provide a concise summary of what this pull request is addressing.

If this PR fixes any issues, list them here by number (e.g., Fixes
#123).
-->
Follow up on #2507 .
<img width="834" alt="Screenshot 2024-12-03 at 9 02 17 PM"
src="https://github.com/user-attachments/assets/7f17749f-01aa-42ef-b2de-ee4c58c2bed5">

## 🔍 Description of Changes

<!--
Detail the specific changes made in this pull request. Explain the
problem addressed and how it was resolved. If applicable, provide before
and after comparisons, screenshots, or any relevant details to help
reviewers understand the changes easily.
-->
- There were also some UI bugs from before that are fixed here. (I
didn't account for Cell Output below the cell 🙏)

## 📋 Checklist

- [X] I have read the [contributor
guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md).
- [ ] For large changes, or changes that affect the public API: this
change was discussed or approved through an issue, on
[Discord](https://marimo.io/discord?ref=pr), or the community
[discussions](https://github.com/marimo-team/marimo/discussions) (Please
provide a link if applicable).
- [ ] I have added tests for the changes made.
- [X] I have run the code and verified that it works as expected.

## 📜 Reviewers

<!--
Tag potential reviewers from the community or maintainers who might be
interested in reviewing this pull request.

Your PR will be reviewed more quickly if you can figure out the right
person to tag with @ -->

@akshayka OR @mscolnick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide markdown duplication in 'edit' view.
3 participants