question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: unable to remove header formatting in a specific scenario

See original GitHub issue

Is your feature request related to a problem? Please describe. In the markdown editor toolbar, there is no easy way to remove heading level stylings once applied. From what I can tell, the only way to remove a heading level styling from text is to switch to the raw markdown mode and remove the # formatting there.

Describe the solution you’d like Add a toolbar option to remove a heading styling if applied to selected text. I can thing of 3 ways this could be implemented.

  1. When a heading level option in the dropdown is applied/active, clicking the dropdown item again toggles the formatting off.
  2. Add a new heading dropdown option “Remove”
  3. Add a new toolbar button that more generally removes any applied markdown formatting from a selection.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bytranglecommented, Jul 28, 2021

Good question. Interestingly, the List and Quote blocks are not affected because they are handled by different methods that use a different logic. For example:

<h1>Heading 1</h1>
<p>paragraph</p>

If you triple click Heading 1, the selection will be <h1> to </p>. editor.value.blocks will contain two blocks, heading-one and paragraph.

Then click either List or Quote button. The toggleQuoteblock and toggleList only look for editor.value.startBlock, which will always be the first block of the selection and then do the transformation.

In contrast, when clicking a Heading button, we look for editor.value.blocks and check if every single block inside it is of the same heading type with a helper method everyBlock. Of course they aren’t, so this method returns false.

If everyBlock returns true, we pass defaultType = 'paragraph' to editor.setBlocks. But it returns false, so we pass the value of heading editor.setBlocks. So editor.setBlocks('heading 1') to a heading-one block doesn’t change the same.

toggleBlock(editor, type) {
  switch(type) {
    case 'heading one':
    // ...
      return editor.setBlocks(editor.everyBlock(type) ? defaultType : type)
    // ...
  }
}

You may wonder: How about the paragraph block after <h1>? Does it get turned into heading-one? As I’ve said, editor.value.blocks contains both blocks, but when calling editor.setBlocks, Slate still correctly identifies “Heading 1” as the only block that gets selected. Hence the paragraph block is untouched.

I don’t know why it behaves that way, but this is probably a reason why this triple-click issue has flown under the radar for so long.

But thanks to your inquiry, I think I’ve discovered an economical way to resolve this issue.

1reaction
patrickcatecommented, Jul 25, 2021

Here’s a video showing the issue. When I’m selecting the entire line I’m triple clicking the text.

https://user-images.githubusercontent.com/6277206/126909999-642ca4d8-9ec7-4d11-8a6f-dfd6dff50ebd.mov

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove header and footer from a single ... - YouTube
Let's learn a clean and simple way to delete header and footer from a particular page in a Word document. The trick is...
Read more >
Correct way to remove header and/or footer in Word - YouTube
Want to remove header and footer in Ms Word? There are many ways to ... try restarting your device. Your browser can't play...
Read more >
Word VBA>New to Macros: Cannot remove Header/Footer
Double-click on the module and paste in your code in the VBA code area. If all looks good, no red text, press F5...
Read more >
Can't Delete Header and Footer - Microsoft Community
You cannot actually remove headers and footers; they are a part of Word's document structure. You can remove any content from them other...
Read more >
Excel header and footer: how to add, change and remove
Header and footer in Excel: how to insert, edit and remove ... a built-in header or footer, you cannot control the location of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found