summaryrefslogtreecommitdiff
path: root/src/remote.cc
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2022-12-11 19:30:02 +0100
committerJohannes Altmanninger <aclopte@gmail.com>2023-03-11 16:21:57 +0100
commitb2cf74bb4a8286c5a191c54e947c0b2c9bb7cf96 (patch)
treee1a41d87f4b1379f96356c43fa52dc9fb784f36b /src/remote.cc
parentad36585b7ad236bea7d1c02b0679ae371c3c2a9e (diff)
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
Diffstat (limited to 'src/remote.cc')
-rw-r--r--src/remote.cc32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/remote.cc b/src/remote.cc
index 50dda1b0..5b97f985 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -43,6 +43,7 @@ enum class MessageType : uint8_t
SetOptions,
Exit,
Key,
+ Paste,
};
class MsgWriter
@@ -413,6 +414,9 @@ public:
void set_on_key(OnKeyCallback callback) override
{ m_on_key = std::move(callback); }
+ void set_on_paste(OnPasteCallback callback) override
+ { m_on_paste = std::move(callback); }
+
void set_ui_options(const Options& options) override;
void exit(int status);
@@ -430,6 +434,7 @@ private:
MsgReader m_reader;
DisplayCoord m_dimensions;
OnKeyCallback m_on_key;
+ OnPasteCallback m_on_paste;
RemoteBuffer m_send_buffer;
};
@@ -479,17 +484,25 @@ RemoteUI::RemoteUI(int socket, DisplayCoord dimensions)
if (not m_reader.ready())
continue;
- if (m_reader.type() != MessageType::Key)
+ if (m_reader.type() == MessageType::Key)
+ {
+ auto key = m_reader.read<Key>();
+ m_reader.reset();
+ if (key.modifiers == Key::Modifiers::Resize)
+ m_dimensions = key.coord();
+ m_on_key(key);
+ }
+ else if (m_reader.type() == MessageType::Paste)
+ {
+ auto content = m_reader.read<String>();
+ m_reader.reset();
+ m_on_paste(content);
+ }
+ else
{
m_socket_watcher.close_fd();
return;
}
-
- auto key = m_reader.read<Key>();
- m_reader.reset();
- if (key.modifiers == Key::Modifiers::Resize)
- m_dimensions = key.coord();
- m_on_key(key);
}
}
catch (const disconnected& err)
@@ -660,6 +673,11 @@ RemoteClient::RemoteClient(StringView session, StringView name, std::unique_ptr<
msg.write(key);
m_socket_watcher->events() |= FdEvents::Write;
});
+ m_ui->set_on_paste([this](StringView content){
+ MsgWriter msg(m_send_buffer, MessageType::Paste);
+ msg.write(content);
+ m_socket_watcher->events() |= FdEvents::Write;
+ });
m_socket_watcher.reset(new FDWatcher{sock, FdEvents::Read | FdEvents::Write, EventMode::Urgent,
[this, reader = MsgReader{}](FDWatcher& watcher, FdEvents events, EventMode) mutable {