Disable Ctrl-X / Cmd-X cut unselected paragraph

In Windows 10 and possibly other environments, Ctrl-X cuts the current paragraph that the cursor is in, even if no text is selected. This is a non-standard shortcut that can accidentally obliterate paragraphs without the user even realizing what happened, so there should be a toggle to optionally turn it off. Maybe turn it into a Hotkey?

3 Likes

Related

I would absolutly support this feature request!

1 Like

Steps to reproduce

  1. Update to latest macOS (15.0 (24A335))
  2. Install obsidian
  3. Open sandbox vault
  4. Try to cut a line without having selected any text (cmd + x)
  5. The text at cursor will all be removed - the cut command should require text to be selected
  6. This is a problem if working on a vault and the user accidentally bumps cmd + x. This is more common than one might expect. I have lost bits of my vault and had to go back through version history (which I luckily have).

Did you follow the troubleshooting guide? [Y/N]

Yes, and reproduced in the sandbox vault.

Expected result

If a user accidentally presses cmd + x nothing should happen. This can be achieved by the user having to select text. The selected text should be cut but if the user has no text selected nothing should happen. This current bug is making the hotkey cmd + d redundant and does not seem to be a feature.

Actual result

If the user has no text selected the entire line is cut.

Environment

[EDITED: originally pasted wrong debug information before I tried to reproduce the error in the sandbox vault on newest release directly from obsidian.md]
SYSTEM INFO:
Obsidian version: v1.6.7
Installer version: v1.6.7
Operating system: Darwin Kernel Version 24.0.0: Mon Aug 12 20:51:54 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6000 24.0.0
Login status: not logged in
Insider build toggle: off
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: on

RECOMMENDATIONS:
none


Additional information

Can send video if this does not make sense. Please advise if more information is requested.

1 Like

As a temporary or permanent workaround, users can reassign ‘Cut’ (in System Settings > App Shortcuts) to a more secure keyboard shortcut. Not ideal, but …

Users shouldn’t have to work around an app re-assigning a basic shortcut to something weird.

2 Likes

According to the help pages, this is a feature not a bug.

There is a old feature request about this:

1 Like

It’s exactly as Hampton described.

1 Like

My point was that it goes against literally 40 years of Mac convention to have CMD-x cut an unselected line. It’s bad behavior and shouldn’t happen.

1 Like

I think the opposite. Cmd + X is one of the best Obsidian features.

1 Like

The feature is fine. Just find another shortcut that isn’t literally one of the oldest on a Mac.

2 Likes

It is actually so annoying… the other posts about it do mention it as a so-called feature (I must have missed them). This might be the expected behaviour for programming environments. However, Obsidian is all about taking notes. No one wants to find half their notes missing because of a feature which is different to most other note taking solutions.

Thank you for pointing out that this is not a bug. But it really is annoying. Can we move this thread to feature requests or something more appropriate. At least an option to make it behave the way most people would expect. Turns out I am not the only one finding notes missing when I thought they were secure months after the fact.

3 Likes

This, and the fact that it is not an expected behaviour for a note-taking app. I think people who want this behaviour would install a plugin or find a setting to change the behaviour if it was similar to other note taking solutions.

1 Like

moved this conversation to the FR thread.

If you are not aware of this feature, I understand you may be surprised the first time ctrl/cmd-x cuts an unselected paragraph (which is not deleted but placed in the clipboard).

However, I don’t quite understand how you can accidentally press cmd-x and do so multiple times even.

Well it has happened to other people so maybe accidents happen :person_shrugging:

1 Like

I would also love to have a setting to disable this feature (copying the whole line when there’s no selection).

It happens to me regularly that I’m trying to paste something into Obsidian and I accidentally hit ctrl C instead of ctrl V, and then when I do hit ctrl V I just get a duplicate of the line, rather than the thing I meant to paste. Usually you just have to go back and recopy the text, which is mildly frustrating, but the consequences get worse if you copied text from somewhere that is difficult or impossible to get back to (e.x. if you cut text from some file, save and close it, and then accidentally hit ctrl + C when pasting into Obsidian, it may be difficult or impossible to recover the lost text).

This feature has often been an inconvenience to me, and never helpful (it’s just too easy to select a whole line and copy it with a few keystrokes), so I would love to be able to turn it off.

For reference, there have been at least a couple of other feature requests requesting this same thing too:

As evidence that this feature how it’s currently implemented violates the principle of least surprise, there are also multiple instances of people asking in the help forum about this and assuming it is a bug:

I know VSCode also has this feature and I think it might even be enabled by default, but crucially they also have a setting to turn it off, which I make use of, and so do most of the people I asked in an informal survey of my coworkers just now.

1 Like

However, I don’t quite understand how you can accidentally press cmd-x and do so multiple times even.

It’s easy, you have mobility/medical problems where your hand twitches and press the key twice or holds it too long and while an autocorrect could possibly fix that for multiple letters/misspelled words, it can’t fix it for shortcuts. There are mouse click settings for this type of thing, but I’ve never come across a single thing that would fix it for something like a specific shortcut… especially when it’d be so easy to just… have two short cuts or a toggle…

Or you have a faulty laptop keyboard that frequently registers keypresses two or three times at random intervals. Or both! I can’t afford new equipment right now and this is the single largest issue caused by my faulty keyboard in any app where it exists.

Or even the computer suddenly slows down and you don’t realize and think it didn’t register your key press and so you do it again and then boom…

Seriously, it’s so easy for it to happen and without you noticing until you go wherever to paste things and then it might be too late to undo. I spend so much goshdarn time undoing repeated ctl-x deleting things or having to ctl-c and then go back to delete the original to work around this. Please let us have a toggle feature or even bit of code to put into a json or something for this. It’s an accessibility issue, and just cause other people enjoy it and wish to use it doesn’t mean it isn’t an incredibly destructive and problematic thing for other users. The point about it not being standard behavior for that shortcut in a note taking apps is especially apt in the obsidian environment. Can you imagine the outcry if google docs or some such implemented this? I have only ever encountered it in sublime text, vscode, and… obsidian…

2 Likes

Thanks for putting into words what I was unable to do. The comment which was akin to blaming me for the issue made me look for alternatives to Obsidian. I was so done after receiving such a snarky comment which made me feel like I was the issue. I basically gave up on the issue.

I was thinking along the lines of why mess with a standard feature like cut, copy, or paste. They are such basic functions in note taking and word processing solution. If people want to make the standard different then that’s where the plugins should step in. With this ‘feature’ I am unable to even return it to the expected behaviour unless I follow something like Hampton said. I have disabled cut entirely for Obsidian which leaves me now having to 1) copy the text I select and then 2) delete it. Which is literally what cut does in every other program I use.

Can I also point out that on my keyboard (a Macbook Pro) Cmd is literally millimetres away from the X-key. This means I could be trying to press Cmd for a different reason and be so distracted that I do not see text go missing.

2 Likes

I’d never do that because of the app’s customization abilities.

You can remove the custom Mac setting for CMD+X and use the following Templater snippet for an alternative approach:

<%*
// Get the active editor and selection
const editor = app.workspace.activeLeaf.view.editor;
const selection = editor.getSelection();

// If no text is selected, do nothing
if (!selection) return;

// If text is selected, cut it and notify the user
editor.replaceSelection(""); // Cut the selected text
navigator.clipboard.writeText(selection).then(() => {
    new Notice(`Text cut to clipboard:\n${selection}`, 3000); // Notify for 3000ms
}).catch(err => {
    console.error('Could not copy text: ', err);
});
_%>

Save the snippet in the folder where the Templater plugin expects your templates.
Then bind CMD+X to the command (snippet).

Currently, the code alerts the user that the clipboard was populated and shows the exact lines of text.
This can help the user to get used to the fact that they are using an override function. If the notices get annoying, add // in front of these lines (or delete them) (I’m adding them here for you now):

navigator.clipboard.writeText(selection); //.then(() => {
//     new Notice(`Text cut to clipboard:\n${selection}`, 3000); // Notify for 3000ms
// }).catch(err => {
//     console.error('Could not copy text: ', err);
// });

Most importantly, what using the snippet achieves is that pressing CTRL (CMD) + X on unselected text does nothing. So users are safe.
Repeat the same thing for all your vaults.

2 Likes

+1 to making this configurable.


But for now, I’ll offer another workaround that I find indispensable! I use a clipboard history tool, so that anything I copy or cut ends up in a collection that I can search and access for days or weeks.

This might be built into Windows these days if you hit Windows-V instead of Ctrl-V. And on MacOS, I use Alfred app’s clipboard history.

Even without this Ctrl-X/Cmd-X issue, I use this history ALL the time. Not just for accidental cuts, but for when I need to copy 2 or 3 things somewhere, or recall a common paste multiple times.

3 Likes