From b2cf74bb4a8286c5a191c54e947c0b2c9bb7cf96 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 11 Dec 2022 19:30:02 +0100 Subject: Implement bracketed paste Text pasted into Kakoune's normal mode is interpreted as command sequence, which is probably never what the user wants. Text pasted during insert mode will be inserted fine but may trigger auto-indentation hooks which is likely not what users want. Bracketed paste is pair of escape codes sent by terminals that allow applications to distinguish between pasted text and typed text. Let's use this feature to always insert pasted text verbatim, skipping keymap lookup and the InsertChar hook. In future, we could add a dedicated Paste hook. We need to make a decision on whether to paste before or after the selection. I chose "before" because that's what I'm used to. TerminalUI::set_on_key has EventManager::instance().force_signal(0); I'm not sure if we want the same for TerminalUI::set_on_paste? I assume it doesn't matter because they are always called in tandem. Closes #2465 --- src/user_interface.hh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/user_interface.hh') diff --git a/src/user_interface.hh b/src/user_interface.hh index 5bab3e89..643f0d1d 100644 --- a/src/user_interface.hh +++ b/src/user_interface.hh @@ -43,6 +43,7 @@ enum class CursorMode }; using OnKeyCallback = std::function; +using OnPasteCallback = std::function; class UserInterface { @@ -78,6 +79,7 @@ public: virtual void refresh(bool force) = 0; virtual void set_on_key(OnKeyCallback callback) = 0; + virtual void set_on_paste(OnPasteCallback callback) = 0; using Options = HashMap; virtual void set_ui_options(const Options& options) = 0; -- cgit v1.2.3