mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23:38:48 +00:00
Support middle-click paste, based on a diff from Ailin Nemui.
This commit is contained in:
parent
24d7d073ff
commit
47c097cb51
@ -31,7 +31,7 @@
|
||||
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_paste_buffer_filter(struct window_pane *,
|
||||
const char *, size_t, const char *, int bracket);
|
||||
const char *, size_t, const char *, int);
|
||||
|
||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
"paste-buffer", "pasteb",
|
||||
@ -87,9 +87,8 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
else
|
||||
sepstr = "\r";
|
||||
}
|
||||
pflag = args_has(args, 'p') &&
|
||||
(wp->screen->mode & MODE_BRACKETPASTE);
|
||||
cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr, pflag);
|
||||
pflag = (wp->screen->mode & MODE_BRACKETPASTE);
|
||||
paste_send_pane(pb, wp, sepstr, args_has(args, 'p') && pflag);
|
||||
}
|
||||
|
||||
/* Delete the buffer if -d. */
|
||||
@ -102,30 +101,3 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Add bytes to a buffer and filter '\n' according to separator. */
|
||||
void
|
||||
cmd_paste_buffer_filter(struct window_pane *wp,
|
||||
const char *data, size_t size, const char *sep, int bracket)
|
||||
{
|
||||
const char *end = data + size;
|
||||
const char *lf;
|
||||
size_t seplen;
|
||||
|
||||
if (bracket)
|
||||
bufferevent_write(wp->event, "\033[200~", 6);
|
||||
|
||||
seplen = strlen(sep);
|
||||
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||
if (lf != data)
|
||||
bufferevent_write(wp->event, data, lf - data);
|
||||
bufferevent_write(wp->event, sep, seplen);
|
||||
data = lf + 1;
|
||||
}
|
||||
|
||||
if (end != data)
|
||||
bufferevent_write(wp->event, data, end - data);
|
||||
|
||||
if (bracket)
|
||||
bufferevent_write(wp->event, "\033[201~", 6);
|
||||
}
|
||||
|
15
input-keys.c
15
input-keys.c
@ -202,8 +202,9 @@ input_key(struct window_pane *wp, int key)
|
||||
void
|
||||
input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
|
||||
{
|
||||
char buf[10];
|
||||
size_t len;
|
||||
char buf[10];
|
||||
size_t len;
|
||||
struct paste_buffer *pb;
|
||||
|
||||
if (wp->screen->mode & ALL_MOUSE_MODES) {
|
||||
if (wp->screen->mode & MODE_MOUSE_UTF8) {
|
||||
@ -223,13 +224,19 @@ input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((m->xb & 3) != 1 &&
|
||||
if (m->button == 1 && (m->event & MOUSE_EVENT_CLICK) &&
|
||||
options_get_number(&wp->window->options, "mode-mouse") == 1) {
|
||||
pb = paste_get_top(&global_buffers);
|
||||
if (pb != NULL) {
|
||||
paste_send_pane(pb, wp, "\r",
|
||||
wp->screen->mode & MODE_BRACKETPASTE);
|
||||
}
|
||||
} else if ((m->xb & 3) != 1 &&
|
||||
options_get_number(&wp->window->options, "mode-mouse") == 1) {
|
||||
if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
|
||||
window_copy_init_from_pane(wp);
|
||||
if (wp->mode->mouse != NULL)
|
||||
wp->mode->mouse(wp, s, m);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
26
paste.c
26
paste.c
@ -167,3 +167,29 @@ paste_print(struct paste_buffer *pb, size_t width)
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* Paste into a window pane, filtering '\n' according to separator. */
|
||||
void
|
||||
paste_send_pane (struct paste_buffer *pb, struct window_pane *wp,
|
||||
const char *sep, int bracket)
|
||||
{
|
||||
const char *data = pb->data, *end = data + pb->size, *lf;
|
||||
size_t seplen;
|
||||
|
||||
if (bracket)
|
||||
bufferevent_write(wp->event, "\033[200~", 6);
|
||||
|
||||
seplen = strlen(sep);
|
||||
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||
if (lf != data)
|
||||
bufferevent_write(wp->event, data, lf - data);
|
||||
bufferevent_write(wp->event, sep, seplen);
|
||||
data = lf + 1;
|
||||
}
|
||||
|
||||
if (end != data)
|
||||
bufferevent_write(wp->event, data, end - data);
|
||||
|
||||
if (bracket)
|
||||
bufferevent_write(wp->event, "\033[201~", 6);
|
||||
}
|
||||
|
9
tmux.h
9
tmux.h
@ -1682,8 +1682,8 @@ const char *tty_term_string2(
|
||||
struct tty_term *, enum tty_code_code, int, int);
|
||||
const char *tty_term_ptr1(
|
||||
struct tty_term *, enum tty_code_code, const void *);
|
||||
const char *tty_term_ptr2(
|
||||
struct tty_term *, enum tty_code_code, const void *, const void *);
|
||||
const char *tty_term_ptr2(struct tty_term *, enum tty_code_code,
|
||||
const void *, const void *);
|
||||
int tty_term_number(struct tty_term *, enum tty_code_code);
|
||||
int tty_term_flag(struct tty_term *, enum tty_code_code);
|
||||
|
||||
@ -1704,6 +1704,9 @@ int paste_free_index(struct paste_stack *, u_int);
|
||||
void paste_add(struct paste_stack *, char *, size_t, u_int);
|
||||
int paste_replace(struct paste_stack *, u_int, char *, size_t);
|
||||
char *paste_print(struct paste_buffer *, size_t);
|
||||
void paste_send_pane(struct paste_buffer *, struct window_pane *,
|
||||
const char *, int);
|
||||
|
||||
|
||||
/* clock.c */
|
||||
extern const char clock_table[14][5][5];
|
||||
@ -1906,7 +1909,7 @@ void server_unlink_window(struct session *, struct winlink *);
|
||||
void server_destroy_pane(struct window_pane *);
|
||||
void server_destroy_session_group(struct session *);
|
||||
void server_destroy_session(struct session *);
|
||||
void server_check_unattached (void);
|
||||
void server_check_unattached(void);
|
||||
void server_set_identify(struct client *);
|
||||
void server_clear_identify(struct client *);
|
||||
void server_update_event(struct client *);
|
||||
|
Loading…
Reference in New Issue
Block a user