Copying or cutting when nothing is highlighted

Hi everyone,

New to forum - :wave::wave: Hope the following is sufficiently clear!

What I’m trying to do

NOT copy/cut anything when nothing is highlighted on Obsidian.

Things I have tried

Cmd+C or +X anywhere on editor causes whole block (from preceding line break to next line break) to be copied or cut.

Gone through settings, forum, discord and documentation - so far no luck at finding how to disable this behaviour of Cmd+C or Cmd+X.

Purpose / Further background

To create keyboard shortcut(s) for text formatting via Keyboard Maestro macro. Specifically, the macro should insert at cursor, or wrap highlighted text, in <font style="color: #"></font>.

To achieve this, the macro has to identify whether any text is highlighted. Simplest way is to check whether Cmd+C is available (not applicable here since the option is always available in Obsidian). Second best is to cut or copy and test if there is any text from action. As Obsidian always cuts or copies the whole block, this method always yields a (false) positive.

For now, the closest stopgap is to regex for any line break. However:

  • there are times when a line break is highlighted for formatting, causing a false false, which overwrites all highlighted contents with formatting tags, or
  • at the end line / block, a false positive is always returned (since there is no line break at the end), causing macro to wrap all of end line / block in the tags instead of inserting tag pair.

=======

Any help would be greatly appreciated. Thanks all!

Hmm, this is indeed how Obsidian behaves, I think its a bug.

If put my cursor anywhere on a text line and Ctrl+c or Ctrl+x, Obsidian is copying or cutting the whole line.

Not a bug! Lovely, very useful feature. Found in some programming-focused text editors. Not sure how many because I first learned about it in Obsidian. I do know it’s in VS Code too, for instance. But OP is right, in Obsidian it’s not documented anywhere other than a few random posts here in the forum.

1 Like

Not to try and be an echo chamber, but this is something I’ve seen happen in literally every text editor I’ve ever used.

There’s likely some way to prevent this with custom JS or some special keybinding settings, but I wouldn’t even know where to begin with that. Either way, you’d have to do something rather custom in order to stop this behavior.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.