Skip to content

Commit

Permalink
Add undo and redo commands
Browse files Browse the repository at this point in the history
  • Loading branch information
timhor committed May 24, 2023
1 parent 5c688fc commit e96c0f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ This [Obsidian](https://obsidian.md) plugin adds keyboard shortcuts (hotkeys) co
| Toggle line numbers | Not set |
| Indent using tabs | Not set |
| Indent using spaces | Not set |
| Undo | Not set |
| Redo | Not set |

\* On macOS, replace `Ctrl` with `Cmd` and `Alt` with `Opt`

Expand All @@ -57,13 +59,19 @@ This [Obsidian](https://obsidian.md) plugin adds keyboard shortcuts (hotkeys) co

### Multiple Cursors

These shortcuts also work with [multiple cursors](https://help.obsidian.md/How+to/Multiple+cursors), with the exception of:
Most\* of these shortcuts work with [multiple cursors](https://help.obsidian.md/How+to/Multiple+cursors). However, undo and redo will not work intuitively in Live Preview – actions will be handled individually for each cursor, rather than grouped together. Work is underway to incrementally migrate them to the newer Obsidian editor API so they are grouped, and has been completed for the following:

- Insert line above
- Insert line below
- Delete line

As a workaround, you can also switch back to the legacy editor in Settings as all actions will be grouped in that case.

\* These shortcuts currently do not support multiple cursors:

- Expand selection to quotes or brackets
- Go to next/previous heading

However, if you're using Live Preview, undo and redo will not work intuitively – actions will be handled individually for each cursor, rather than grouped together. If this becomes an issue for you, you can switch back to the legacy editor in Settings as a workaround as actions will be grouped in that case.

## Installing the plugin

Refer to the official installation instructions for third-party plugins [here](https://help.obsidian.md/Extending+Obsidian/Community+plugins).
Expand Down
12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,18 @@ export default class CodeEditorShortcuts extends Plugin {
callback: () => setVaultConfig(this.app, 'useTab', false),
});

this.addCommand({
id: 'undo',
name: 'Undo',
editorCallback: (editor) => editor.undo(),
});

this.addCommand({
id: 'redo',
name: 'Redo',
editorCallback: (editor) => editor.redo(),
});

this.registerSelectionChangeListeners();

this.addSettingTab(new SettingTab(this.app, this));
Expand Down

0 comments on commit e96c0f0

Please sign in to comment.