Add the ability to change / disable pre-implemented keyboard shortcuts. #196

Open
opened 2019-09-10 07:11:49 -05:00 by Nickelony · 2 comments
Nickelony commented 2019-09-10 07:11:49 -05:00 (Migrated from github.com)

I'd love to see the ability to remap / disable some pre-implemented keyboard shortcuts such as CTRL+Z, CTRL+Y etc.

Usage example: In my application, I want to run some methods before and after the base.Undo() event, which is called by the CTRL+Z shortcut, but sadly, there's no way to catch it.

Another idea would be to add a Undone / Redone event to the editor, but I think shortcut remapping would also do the trick.

I'd love to see the ability to remap / disable some pre-implemented keyboard shortcuts such as CTRL+Z, CTRL+Y etc. **Usage example:** In my application, I want to run some methods before and after the base.Undo() event, which is called by the CTRL+Z shortcut, but sadly, there's no way to catch it. Another idea would be to add a **Undone** / **Redone** event to the editor, but I think shortcut remapping would also do the trick.
rcbellamy commented 2022-08-14 10:59:35 -05:00 (Migrated from github.com)

I'd really like to use AvalonEdit in my application, but I need to handle Undo/Redo outside the scope of any one control. Is there a way to get AvalonEdit to stop intercepting Ctrl-Z when it has focus so that my window-level input binding handles it? Otherwise I don't think it's going to be possible for me to use AvalonEdit at all.

I'd really like to use AvalonEdit in my application, but I need to handle Undo/Redo outside the scope of any one control. Is there a way to get AvalonEdit to stop intercepting Ctrl-Z when it has focus so that my window-level input binding handles it? Otherwise I don't think it's going to be possible for me to use AvalonEdit at all.
siegfriedpammer commented 2022-08-14 13:07:24 -05:00 (Migrated from github.com)
		var handler = (TextAreaDefaultInputHandler)textEditor.TextArea.ActiveInputHandler;
		handler.Detach();
		RemoveBinding(ApplicationCommands.Undo);
		RemoveBinding(ApplicationCommands.Redo);
		handler.Attach();

		void RemoveBinding(ICommand command)
		{
			foreach (var binding in handler.InputBindings.ToList()) {
				if (binding.Command == command)
					handler.InputBindings.Remove(binding);
			}
			foreach (var binding in handler.CommandBindings.ToList()) {
				if (binding.Command == command)
					handler.CommandBindings.Remove(binding);
			}
		}

Hope this helps...

Alternatively, you could implement your own TextAreaInputHandler(s)...

var handler = (TextAreaDefaultInputHandler)textEditor.TextArea.ActiveInputHandler; handler.Detach(); RemoveBinding(ApplicationCommands.Undo); RemoveBinding(ApplicationCommands.Redo); handler.Attach(); void RemoveBinding(ICommand command) { foreach (var binding in handler.InputBindings.ToList()) { if (binding.Command == command) handler.InputBindings.Remove(binding); } foreach (var binding in handler.CommandBindings.ToList()) { if (binding.Command == command) handler.CommandBindings.Remove(binding); } } Hope this helps... Alternatively, you could implement your own TextAreaInputHandler(s)...
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/AvalonEdit#196
No description provided.