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.

Quickest way to wrap just selected text in a block?

See original GitHub issue

I know there is probably a way to do this easily, however I am getting tripped up with transforms and selections.

I know about wrapBlock() however it wraps the entire block and not just the selection. I desire functionality like wrapInline() where only the portion of the block that is in the selection is wrapped. How might I accomplish this in a single transform?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tyler-johnsoncommented, Jul 27, 2016

Ah yes the .splitBlockAtRange(selection.collapseToEnd()) is what I believe I was missing. I will make another attempt at this tomorrow. I am still a novice at this immutability stuff and it didn’t occur to me that I could transform the content without moving the selection around. Thanks.

As for the use case, I am looking for alternative ways to solve #178. I was thinking that perhaps the popup could be embedded in the document next to the inline text it is linked to. Since the popup content will require block nodes, I assumed that all the parent nodes would need to be block nodes as well. Truthfully an Inline node would fit better. So I guess this leads to another question: Can Inline nodes contain Block nodes as children?


Personally I think the functionality of wrapBlock and wrapInline are to be expected as the documentation describes them as “Wrap the {Inline/Block} nodes in the current selection”. To me that says that no splitting of blocks or inlines will take place at the selection boundaries and new nodes will simply wrap the existing ones. Additionally, it makes sense that wrapInline would split Text nodes when there are no inline nodes to wrap. I would expect the same functionality from wrapBlock if the document just had text nodes but it seems like documents always contain blocks.

Perhaps you could add two new methods with names like wrapRangeWithBlock and wrapRangeWithInline? Interestingly these could have the added benefit of wrapping inside the current block or inline instead of wrapping on the outside (assuming that’s how wrapBlock and wrapInline work currently).

0reactions
tyler-johnsoncommented, Jul 28, 2016

Okay no problem thanks for clarifying this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrapping and breaking text - CSS: Cascading Style Sheets
Wrapping and breaking text. This guide explains the various ways in which overflowing text can be managed in CSS.
Read more >
Wrap text in a cell in Excel for Mac - Microsoft Support
Select the cells that you want to format. · On the Home tab, click Wrap Text. On the Home tab, select Wrap Text...
Read more >
Deep Dive into Text Wrapping and Word Breaking
Putting overflow-wrap: break-word on an element will allow text to break mid-word if needed. It'll first try to keep a word unbroken by...
Read more >
How to Wrap Text in Excel - YouTube
In today's tutorial, we'll see how to wrap text in Excel. This function can help you keep even longer texts within the boundaries...
Read more >
How do I wrap text in a pre tag? - html - Stack Overflow
I just inspected the stackoverflow code blocks and they wrap in a <code> tag wrapped in <pre> tag with css ... code {...
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