From 0e4d1d8493564ce908b002d8e9dddc105184039e Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 31 Mar 2014 21:39:31 +0000 Subject: Add setb -a to append and a copy mode append command, from J Raynor with minor changes. --- window-copy.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'window-copy.c') diff --git a/window-copy.c b/window-copy.c index 76c9c3ce..7d7f3a20 100644 --- a/window-copy.c +++ b/window-copy.c @@ -58,6 +58,7 @@ void window_copy_copy_buffer(struct window_pane *, int, void *, size_t); void window_copy_copy_pipe( struct window_pane *, struct session *, int, const char *); void window_copy_copy_selection(struct window_pane *, int); +void window_copy_append_selection(struct window_pane *, int); void window_copy_clear_selection(struct window_pane *); void window_copy_copy_line( struct window_pane *, char **, size_t *, u_int, u_int, u_int); @@ -414,6 +415,13 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) cmd = mode_key_lookup(&data->mdata, key, &arg); switch (cmd) { + case MODEKEYCOPY_APPENDSELECTION: + if (sess != NULL) { + window_copy_append_selection(wp, data->numprefix); + window_pane_reset_mode(wp); + return; + } + break; case MODEKEYCOPY_CANCEL: window_pane_reset_mode(wp); return; @@ -1491,6 +1499,46 @@ window_copy_copy_selection(struct window_pane *wp, int idx) window_copy_copy_buffer(wp, idx, buf, len); } +void +window_copy_append_selection(struct window_pane *wp, int idx) +{ + char *buf; + struct paste_buffer *pb; + size_t len; + u_int limit; + struct screen_write_ctx ctx; + + buf = window_copy_get_selection(wp, &len); + if (buf == NULL) + return; + + if (options_get_number(&global_options, "set-clipboard")) { + screen_write_start(&ctx, wp, NULL); + screen_write_setselection(&ctx, buf, len); + screen_write_stop(&ctx); + } + + if (idx == -1) + idx = 0; + + if (idx == 0 && paste_get_top(&global_buffers) == NULL) { + limit = options_get_number(&global_options, "buffer-limit"); + paste_add(&global_buffers, buf, len, limit); + return; + } + + pb = paste_get_index(&global_buffers, idx); + if (pb != NULL) { + buf = xrealloc(buf, 1, len + pb->size); + memmove(buf + pb->size, buf, len); + memcpy(buf, pb->data, pb->size); + len += pb->size; + } + + if (paste_replace(&global_buffers, idx, buf, len) != 0) + free(buf); +} + void window_copy_copy_line(struct window_pane *wp, char **buf, size_t *off, u_int sy, u_int sx, u_int ex) -- cgit From acef311fe356f408690e9f94727ed63a934b742f Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 3 Apr 2014 08:20:29 +0000 Subject: Work out mouse scroll wheel effect when the mouse is first detected and store it in struct mouse_event, reduce the scroll size the 3 but allow shift to reduce it to 1 and meta and ctrl to multiply by 3 if the terminal supports them, also support wheel in choose mode. From Marcel Partap. --- window-copy.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'window-copy.c') diff --git a/window-copy.c b/window-copy.c index 7d7f3a20..6e4d6704 100644 --- a/window-copy.c +++ b/window-copy.c @@ -871,18 +871,19 @@ window_copy_mouse( /* If mouse wheel (buttons 4 and 5), scroll. */ if (m->event == MOUSE_EVENT_WHEEL) { - if (m->wheel == MOUSE_WHEEL_UP) { - for (i = 0; i < 5; i++) + for (i = 0; i < m->scroll; i++) { + if (m->wheel == MOUSE_WHEEL_UP) window_copy_cursor_up(wp, 1); - } else if (m->wheel == MOUSE_WHEEL_DOWN) { - for (i = 0; i < 5; i++) + else { window_copy_cursor_down(wp, 1); - /* - * We reached the bottom, leave copy mode, - * but only if no selection is in progress. - */ - if (data->oy == 0 && !s->sel.flag) - goto reset_mode; + + /* + * We reached the bottom, leave copy mode, but + * only if no selection is in progress. + */ + if (data->oy == 0 && !s->sel.flag) + goto reset_mode; + } } return; } -- cgit