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.

How to set block data?

See original GitHub issue

I want to insert a code block and specify the language of the code block like JavaScript for code highlight (I use decorator to make it), but since I use RichUtils.toggleBlockType, how can I add block data on that? Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

8reactions
agungsbcommented, Jun 16, 2019

Any concrete example on how to do this?

2reactions
mcbattirolacommented, Jun 23, 2021

Any concrete example on how to do this?

It’s been a while but maybe its useful to someone

I was trying to set data on a block as soon as the user leave it.

const setBlockLock = (editorState, block, isLocked) => {
  // save the actual selection to use later
  const userSelection = editorState.getSelection()

  const newData = isLocked ? block.data.set("locked", isLocked) : block.data.delete("locked")    

  // create a new selection with the block I want to change
  const selection = SelectionState.createEmpty(block.key)

  const newContent = Modifier.setBlockData(editorState.getCurrentContent(), selection, newData)

  const newEditor = EditorState.push(editorState, newContent, 'change-block-data')

  // return a new editor state, applying the selection we stored before
  return EditorState.forceSelection(newEditor, userSelection)
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Solved] How to set block data? - Bukkit Forums
Try switching around these 2: Code: world.getBlockAt(loc).setData((byte)1); world.getBlockAt(loc).setType(m);. That way it sets the block type ...
Read more >
Commands/blockdata - Minecraft Wiki - Fandom
Specifies the data tag elements to be added to, or overwrite elements of, the specified block. Must be a compound NBT tag (for...
Read more >
Solved - how to set block data? - SpigotMC
I'm trying to spawn a particle of BLOCK_CRACK and till today I used only MaterialData() for that stuff, but now I need to...
Read more >
How to Use the BlockData Command in Minecraft - DigMinecraft
2. Type the Command ... Type the command in the chat window. As you are typing, you will see the command appear in...
Read more >
syntax /setblock command_block [how do I include block data ...
syntax /setblock command_block [how do I include block data and commands?] Follow Followed by 12 people. User Avatar Image.
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