obsidian-shiki-plugin icon indicating copy to clipboard operation
obsidian-shiki-plugin copied to clipboard

Enable direct editing of codeblocks

Open niwazukihon opened this issue 1 year ago • 11 comments

Is your feature request related to a problem? Please describe. After enabling the plugin, codeblocks can no longer be directly edited. This is mentioned in #1. I also don't see any "edit button" mentioned in that issue.

Currently if I need to edit a codeblock, which I do very often, I need to place the cursor above the codeblock and hit down arrow to enter it and then edit. It's inconvenient. I also rarely copy the entire codeblock and mostly copy individual commands.

Describe the solution you'd like I want an option to revert to the default behavior, maybe remove the copy button as well. Thank you.

Additional context

niwazukihon avatar Sep 06 '24 03:09 niwazukihon

Live preview has this button in the upper right corner of the code block that can be used to edit it. image

mProjectsCode avatar Sep 06 '24 17:09 mProjectsCode

I don't see the edit button (any language), but clicking the top right corner does select all content in the codeblock. It's better than before. Would be great to be able to edit directly tho.

niwazukihon avatar Sep 06 '24 18:09 niwazukihon

It's better than before. Would be great to be able to edit directly tho.

That's not planned. Clicking into the code of a code block should not switch to editing the code block. Instead, it should let you select the code.

mProjectsCode avatar Sep 06 '24 18:09 mProjectsCode

It's better than before. Would be great to be able to edit directly tho.

That's not planned. Clicking into the code of a code block should not switch to editing the code block. Instead, it should let you select the code.

Hi @mProjectsCode Thanks for your contribution on this plugin!

Actually, I agree with @niwazukihon . It is more convenient to directly editing the code block than selecting the edit button. It could be better to have an option for those who prefer direct editing.

HildaJ avatar Sep 14 '24 05:09 HildaJ

A setting for this sounds good, but the bigger problem is that I don't know how to switch the code block to editing, as Obsidian induces the current behavior.

mProjectsCode avatar Sep 15 '24 15:09 mProjectsCode

For reference, I am now trying to switch from the plugin cm editor syntax highlight to Shiki. For the former, code in the code blocks was editable, although it doesn't support as many syntaxes as Shiki does and is not maintained anymore.

I understand that it could be tricky to add this feature. Thanks for your prompt reply!

HildaJ avatar Sep 16 '24 11:09 HildaJ

By default codeblock becomes editable on click, would be nice to have such feature with this plugin

Real-Gecko avatar Nov 09 '24 08:11 Real-Gecko

If there were a feature to directly edit code blocks, it would be perfect. Currently, you still need to click the "Edit this block" button in the upper right corner.

I tried writing a plugin myself that would "click" the "Edit this block" button when double-clicking a code block, thinking it would solve this problem. However, the improvement was quite limited because clicking this button selects all the code in the code block. Even worse, when the code block is long (exceeding the screen), clicking the button to enter edit mode can cause unexpected movement of the vertical scroll bar, which is very inconvenient.

guogangj avatar Oct 14 '25 13:10 guogangj

If there were a feature to directly edit code blocks, it would be perfect. Currently, you still need to click the "Edit this block" button in the upper right corner.

I tried writing a plugin myself that would "click" the "Edit this block" button when double-clicking a code block, thinking it would solve this problem. However, the improvement was quite limited because clicking this button selects all the code in the code block. Even worse, when the code block is long (exceeding the screen), clicking the button to enter edit mode can cause unexpected movement of the vertical scroll bar, which is very inconvenient.

I took a look, and it seems that clicking "Edit this block" to enter edit mode is a feature of "Expressive Code," and has nothing to do with this plugin. But I couldn't find any relevant documentation about this in the "Expressive Code" documentation. This is a bit troublesome... This problem doesn't seem so easy to solve.

guogangj avatar Oct 14 '25 14:10 guogangj

I took a look, and it seems that clicking "Edit this block" to enter edit mode is a feature of "Expressive Code," and has nothing to do with this plugin. But I couldn't find any relevant documentation about this in the "Expressive Code" documentation. This is a bit troublesome... This problem doesn't seem so easy to solve.

No. The edit button is a feature of base Obsidian.

mProjectsCode avatar Oct 14 '25 14:10 mProjectsCode

The fork here seems to work. (Although I wish that it doesn't select all the code when double clicked.) One can build locally and copy the files to the .obsidian/plugins folder or use this plugin and github actions to install it just like a regular plugin.

niwazukihon avatar Oct 28 '25 05:10 niwazukihon