Edit code-block contents without refreshing block?

Hello! Developer of the plugin Ink here. My plugin embeds a react instance as a replacement for a code block (So I use the registerMarkdownCodeBlockProcessor() function. When the user manipulates the contents of the block, I need to update the data stored in the code block. The code block looks like this: (I’ve replaced the backticks with apostrophes so it displays correctly here)

'''handdrawn-ink
{
    "versionAtEmbed": "0.2.6",
    "filepath": "Ink/Drawing/2024.11.23 - 15.18pm.drawing",
    "height": 406
}
'''

To update it, I’m using the following code, which just replaces the contents.

const embedStart: EditorPosition = {
   line: sectionInfo.lineStart + 1,
   ch: 0,
}
const embedEnd: EditorPosition = {
   line: sectionInfo.lineEnd - 1,
   ch: 1, // To allow for the closing } bracket
}
    
cmEditor.replaceRange( stringifyEmbedData(embedData), embedStart, embedEnd );

However, this causes the whole block to reload. Is there a way to do it without reloading the block? (All I need to change is the height value at this point in time)

Hi, just to inquire, have you already made progress on this point? If so would you be willing to share?

Unfortunately not. For now I’ve had to delay updating the code block until the user clicks save/lock on the embed.

This isn’t ideal as it prevents me auto-saving for them, but at least the refresh feels seemless to them.

1 Like