From 639a61abd86c7db3e47f2cd70fc16b7d6c6afaf4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 31 Jul 2020 17:02:53 +0200 Subject: config: add 'pipe-selected' key binding This works just like pipe-visible and pipe-scrollback, but pipes the user-selected text, if any, to the external tool. Closes #51 --- selection.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index ffe06c27..8dd93028 100644 --- a/selection.c +++ b/selection.c @@ -204,9 +204,12 @@ extract_one_const_wrapper(struct terminal *term, return extract_one(term, row, cell, col, data); } -static char * -extract_selection(const struct terminal *term) +char * +selection_to_text(const struct terminal *term) { + if (term->selection.end.row == -1) + return NULL; + struct extraction_context *ctx = extract_begin(term->selection.kind); if (ctx == NULL) return NULL; @@ -873,7 +876,7 @@ selection_to_clipboard(struct seat *seat, struct terminal *term, uint32_t serial return; /* Get selection as a string */ - char *text = extract_selection(term); + char *text = selection_to_text(term); if (!text_to_clipboard(seat, term, text, serial)) free(text); } @@ -1074,7 +1077,7 @@ selection_to_primary(struct seat *seat, struct terminal *term, uint32_t serial) return; /* Get selection as a string */ - char *text = extract_selection(term); + char *text = selection_to_text(term); if (!text_to_primary(seat, term, text, serial)) free(text); } -- cgit v1.3