2010-03-22 19:13:28 +00:00
|
|
|
/* $OpenBSD$ */
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2013-11-09 00:48:57 +00:00
|
|
|
#include <ctype.h>
|
2019-12-27 18:42:49 +00:00
|
|
|
#include <regex.h>
|
2009-08-18 07:08:26 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <string.h>
|
2020-05-16 14:22:51 +00:00
|
|
|
#include <time.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2020-06-11 19:43:34 +00:00
|
|
|
struct window_copy_mode_data;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
static const char *window_copy_key_table(struct window_mode_entry *);
|
|
|
|
static void window_copy_command(struct window_mode_entry *, struct client *,
|
2018-12-18 13:20:44 +00:00
|
|
|
struct session *, struct winlink *, struct args *,
|
|
|
|
struct mouse_event *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static struct screen *window_copy_init(struct window_mode_entry *,
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
struct cmd_find_state *, struct args *);
|
2019-03-08 10:34:20 +00:00
|
|
|
static struct screen *window_copy_view_init(struct window_mode_entry *,
|
|
|
|
struct cmd_find_state *, struct args *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_free(struct window_mode_entry *);
|
|
|
|
static void window_copy_resize(struct window_mode_entry *, u_int, u_int);
|
|
|
|
static void window_copy_formats(struct window_mode_entry *,
|
|
|
|
struct format_tree *);
|
|
|
|
static void window_copy_pageup1(struct window_mode_entry *, int);
|
|
|
|
static int window_copy_pagedown(struct window_mode_entry *, int, int);
|
|
|
|
static void window_copy_next_paragraph(struct window_mode_entry *);
|
|
|
|
static void window_copy_previous_paragraph(struct window_mode_entry *);
|
|
|
|
static void window_copy_redraw_selection(struct window_mode_entry *, u_int);
|
|
|
|
static void window_copy_redraw_lines(struct window_mode_entry *, u_int,
|
|
|
|
u_int);
|
|
|
|
static void window_copy_redraw_screen(struct window_mode_entry *);
|
|
|
|
static void window_copy_write_line(struct window_mode_entry *,
|
2016-10-11 13:21:59 +00:00
|
|
|
struct screen_write_ctx *, u_int);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_write_lines(struct window_mode_entry *,
|
2016-10-11 13:21:59 +00:00
|
|
|
struct screen_write_ctx *, u_int, u_int);
|
2020-06-11 19:43:34 +00:00
|
|
|
static char *window_copy_match_at_cursor(struct window_copy_mode_data *);
|
2020-06-04 20:41:57 +00:00
|
|
|
static void window_copy_scroll_to(struct window_mode_entry *, u_int, u_int,
|
|
|
|
int);
|
2016-10-11 13:21:59 +00:00
|
|
|
static int window_copy_search_compare(struct grid *, u_int, u_int,
|
|
|
|
struct grid *, u_int, int);
|
|
|
|
static int window_copy_search_lr(struct grid *, struct grid *, u_int *,
|
|
|
|
u_int, u_int, u_int, int);
|
|
|
|
static int window_copy_search_rl(struct grid *, struct grid *, u_int *,
|
|
|
|
u_int, u_int, u_int, int);
|
2020-06-11 19:43:34 +00:00
|
|
|
static int window_copy_last_regex(struct grid *, u_int, u_int, u_int,
|
|
|
|
u_int, u_int *, u_int *, const char *, const regex_t *,
|
|
|
|
int);
|
2021-04-01 06:46:12 +00:00
|
|
|
static int window_copy_search_mark_at(struct window_copy_mode_data *,
|
|
|
|
u_int, u_int, u_int *);
|
2019-12-27 18:42:49 +00:00
|
|
|
static char *window_copy_stringify(struct grid *, u_int, u_int, u_int,
|
|
|
|
char *, u_int *);
|
2020-06-11 19:43:34 +00:00
|
|
|
static void window_copy_cstrtocellpos(struct grid *, u_int, u_int *,
|
|
|
|
u_int *, const char *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static int window_copy_search_marks(struct window_mode_entry *,
|
2020-06-04 20:41:57 +00:00
|
|
|
struct screen *, int, int);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_clear_marks(struct window_mode_entry *);
|
2016-10-11 13:21:59 +00:00
|
|
|
static int window_copy_is_lowercase(const char *);
|
2021-02-22 08:31:19 +00:00
|
|
|
static void window_copy_search_back_overlap(struct grid *, regex_t *,
|
|
|
|
u_int *, u_int *, u_int *, u_int);
|
2019-03-07 20:24:21 +00:00
|
|
|
static int window_copy_search_jump(struct window_mode_entry *,
|
|
|
|
struct grid *, struct grid *, u_int, u_int, u_int, int, int,
|
2021-04-01 06:46:12 +00:00
|
|
|
int, int);
|
|
|
|
static int window_copy_search(struct window_mode_entry *, int, int);
|
|
|
|
static int window_copy_search_up(struct window_mode_entry *, int);
|
|
|
|
static int window_copy_search_down(struct window_mode_entry *, int);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_goto_line(struct window_mode_entry *, const char *);
|
|
|
|
static void window_copy_update_cursor(struct window_mode_entry *, u_int,
|
|
|
|
u_int);
|
|
|
|
static void window_copy_start_selection(struct window_mode_entry *);
|
|
|
|
static int window_copy_adjust_selection(struct window_mode_entry *,
|
|
|
|
u_int *, u_int *);
|
2020-03-19 13:28:52 +00:00
|
|
|
static int window_copy_set_selection(struct window_mode_entry *, int, int);
|
|
|
|
static int window_copy_update_selection(struct window_mode_entry *, int,
|
|
|
|
int);
|
|
|
|
static void window_copy_synchronize_cursor(struct window_mode_entry *, int);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void *window_copy_get_selection(struct window_mode_entry *, size_t *);
|
2019-04-02 09:03:39 +00:00
|
|
|
static void window_copy_copy_buffer(struct window_mode_entry *,
|
|
|
|
const char *, void *, size_t);
|
2021-02-08 14:46:53 +00:00
|
|
|
static void window_copy_pipe(struct window_mode_entry *,
|
|
|
|
struct session *, const char *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_copy_pipe(struct window_mode_entry *,
|
2019-04-02 09:03:39 +00:00
|
|
|
struct session *, const char *, const char *);
|
|
|
|
static void window_copy_copy_selection(struct window_mode_entry *,
|
|
|
|
const char *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_append_selection(struct window_mode_entry *);
|
|
|
|
static void window_copy_clear_selection(struct window_mode_entry *);
|
|
|
|
static void window_copy_copy_line(struct window_mode_entry *, char **,
|
|
|
|
size_t *, u_int, u_int, u_int);
|
|
|
|
static int window_copy_in_set(struct window_mode_entry *, u_int, u_int,
|
2016-10-11 13:21:59 +00:00
|
|
|
const char *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static u_int window_copy_find_length(struct window_mode_entry *, u_int);
|
|
|
|
static void window_copy_cursor_start_of_line(struct window_mode_entry *);
|
|
|
|
static void window_copy_cursor_back_to_indentation(
|
|
|
|
struct window_mode_entry *);
|
|
|
|
static void window_copy_cursor_end_of_line(struct window_mode_entry *);
|
|
|
|
static void window_copy_other_end(struct window_mode_entry *);
|
|
|
|
static void window_copy_cursor_left(struct window_mode_entry *);
|
2020-09-22 08:41:27 +00:00
|
|
|
static void window_copy_cursor_right(struct window_mode_entry *, int);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_cursor_up(struct window_mode_entry *, int);
|
|
|
|
static void window_copy_cursor_down(struct window_mode_entry *, int);
|
|
|
|
static void window_copy_cursor_jump(struct window_mode_entry *);
|
|
|
|
static void window_copy_cursor_jump_back(struct window_mode_entry *);
|
|
|
|
static void window_copy_cursor_jump_to(struct window_mode_entry *);
|
|
|
|
static void window_copy_cursor_jump_to_back(struct window_mode_entry *);
|
|
|
|
static void window_copy_cursor_next_word(struct window_mode_entry *,
|
2016-10-11 13:21:59 +00:00
|
|
|
const char *);
|
2020-02-24 09:53:59 +00:00
|
|
|
static void window_copy_cursor_next_word_end_pos(struct window_mode_entry *,
|
|
|
|
const char *, u_int *, u_int *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_cursor_next_word_end(struct window_mode_entry *,
|
2020-03-20 13:12:04 +00:00
|
|
|
const char *, int);
|
2020-02-24 09:53:59 +00:00
|
|
|
static void window_copy_cursor_previous_word_pos(struct window_mode_entry *,
|
|
|
|
const char *, int, u_int *, u_int *);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_cursor_previous_word(struct window_mode_entry *,
|
2019-08-01 14:30:31 +00:00
|
|
|
const char *, int);
|
2019-03-07 20:24:21 +00:00
|
|
|
static void window_copy_scroll_up(struct window_mode_entry *, u_int);
|
|
|
|
static void window_copy_scroll_down(struct window_mode_entry *, u_int);
|
2021-01-22 10:24:52 +00:00
|
|
|
static void window_copy_rectangle_set(struct window_mode_entry *, int);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void window_copy_move_mouse(struct mouse_event *);
|
|
|
|
static void window_copy_drag_update(struct client *, struct mouse_event *);
|
2019-04-25 06:34:57 +00:00
|
|
|
static void window_copy_drag_release(struct client *, struct mouse_event *);
|
2020-05-16 16:10:28 +00:00
|
|
|
static void window_copy_jump_to_mark(struct window_mode_entry *);
|
2021-02-22 06:53:04 +00:00
|
|
|
static void window_copy_acquire_cursor_up(struct window_mode_entry *,
|
|
|
|
u_int, u_int, u_int, u_int, u_int);
|
|
|
|
static void window_copy_acquire_cursor_down(struct window_mode_entry *,
|
|
|
|
u_int, u_int, u_int, u_int, u_int, u_int, int);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
const struct window_mode window_copy_mode = {
|
2017-05-07 22:27:57 +00:00
|
|
|
.name = "copy-mode",
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
.init = window_copy_init,
|
|
|
|
.free = window_copy_free,
|
|
|
|
.resize = window_copy_resize,
|
|
|
|
.key_table = window_copy_key_table,
|
|
|
|
.command = window_copy_command,
|
2019-03-07 19:01:21 +00:00
|
|
|
.formats = window_copy_formats,
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
const struct window_mode window_view_mode = {
|
|
|
|
.name = "view-mode",
|
|
|
|
|
|
|
|
.init = window_copy_view_init,
|
|
|
|
.free = window_copy_free,
|
|
|
|
.resize = window_copy_resize,
|
|
|
|
.key_table = window_copy_key_table,
|
|
|
|
.command = window_copy_command,
|
|
|
|
.formats = window_copy_formats,
|
|
|
|
};
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
enum {
|
2009-08-18 07:08:26 +00:00
|
|
|
WINDOW_COPY_OFF,
|
|
|
|
WINDOW_COPY_SEARCHUP,
|
|
|
|
WINDOW_COPY_SEARCHDOWN,
|
2010-03-22 19:10:42 +00:00
|
|
|
WINDOW_COPY_JUMPFORWARD,
|
2016-10-11 07:23:34 +00:00
|
|
|
WINDOW_COPY_JUMPBACKWARD,
|
2011-12-04 16:18:01 +00:00
|
|
|
WINDOW_COPY_JUMPTOFORWARD,
|
2016-10-11 07:23:34 +00:00
|
|
|
WINDOW_COPY_JUMPTOBACKWARD,
|
2009-08-18 07:08:26 +00:00
|
|
|
};
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
enum {
|
|
|
|
WINDOW_COPY_REL_POS_ABOVE,
|
|
|
|
WINDOW_COPY_REL_POS_ON_SCREEN,
|
|
|
|
WINDOW_COPY_REL_POS_BELOW,
|
|
|
|
};
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
enum window_copy_cmd_action {
|
|
|
|
WINDOW_COPY_CMD_NOTHING,
|
|
|
|
WINDOW_COPY_CMD_REDRAW,
|
|
|
|
WINDOW_COPY_CMD_CANCEL,
|
|
|
|
};
|
|
|
|
|
2020-06-04 10:24:14 +00:00
|
|
|
enum window_copy_cmd_clear {
|
|
|
|
WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
|
|
|
WINDOW_COPY_CMD_CLEAR_NEVER,
|
|
|
|
WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
|
|
|
};
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
struct window_copy_cmd_state {
|
|
|
|
struct window_mode_entry *wme;
|
|
|
|
struct args *args;
|
|
|
|
struct mouse_event *m;
|
2019-04-02 09:03:39 +00:00
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
struct client *c;
|
|
|
|
struct session *s;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct winlink *wl;
|
2019-03-26 21:01:19 +00:00
|
|
|
};
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
/*
|
2016-11-24 13:38:44 +00:00
|
|
|
* Copy mode's visible screen (the "screen" field) is filled from one of two
|
|
|
|
* sources: the original contents of the pane (used when we actually enter via
|
|
|
|
* the "copy-mode" command, to copy the contents of the current pane), or else
|
|
|
|
* a series of lines containing the output from an output-writing tmux command
|
|
|
|
* (such as any of the "show-*" or "list-*" commands).
|
2010-04-06 21:35:44 +00:00
|
|
|
*
|
2016-11-24 13:38:44 +00:00
|
|
|
* In either case, the full content of the copy-mode grid is pointed at by the
|
|
|
|
* "backing" field, and is copied into "screen" as needed (that is, when
|
|
|
|
* scrolling occurs). When copy-mode is backed by a pane, backing points
|
|
|
|
* directly at that pane's screen structure (&wp->base); when backed by a list
|
|
|
|
* of output-lines from a command, it points at a newly-allocated screen
|
|
|
|
* structure (which is deallocated when the mode ends).
|
2010-04-06 21:35:44 +00:00
|
|
|
*/
|
2009-06-01 22:58:49 +00:00
|
|
|
struct window_copy_mode_data {
|
2016-10-11 07:23:34 +00:00
|
|
|
struct screen screen;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
struct screen *backing;
|
|
|
|
int backing_written; /* backing display started */
|
2010-04-06 21:35:44 +00:00
|
|
|
|
2020-04-06 17:51:34 +00:00
|
|
|
int viewmode; /* view mode entered */
|
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
u_int oy; /* number of lines scrolled up */
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
u_int selx; /* beginning of selection */
|
2016-10-11 07:23:34 +00:00
|
|
|
u_int sely;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
u_int endselx; /* end of selection */
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int endsely;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CURSORDRAG_NONE, /* selection is independent of cursor */
|
|
|
|
CURSORDRAG_ENDSEL, /* end is synchronized with cursor */
|
|
|
|
CURSORDRAG_SEL, /* start is synchronized with cursor */
|
|
|
|
} cursordrag;
|
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
int modekeys;
|
|
|
|
enum {
|
|
|
|
LINE_SEL_NONE,
|
|
|
|
LINE_SEL_LEFT_RIGHT,
|
|
|
|
LINE_SEL_RIGHT_LEFT,
|
|
|
|
} lineflag; /* line selection mode */
|
2016-10-11 07:23:34 +00:00
|
|
|
int rectflag; /* in rectangle copy mode? */
|
|
|
|
int scroll_exit; /* exit on scroll to end? */
|
2020-03-12 13:19:20 +00:00
|
|
|
int hide_position; /* hide position marker */
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-02-24 09:53:59 +00:00
|
|
|
enum {
|
|
|
|
SEL_CHAR, /* select one char at a time */
|
|
|
|
SEL_WORD, /* select one word at a time */
|
|
|
|
SEL_LINE, /* select one line at a time */
|
|
|
|
} selflag;
|
|
|
|
|
|
|
|
const char *ws; /* word separators */
|
|
|
|
|
|
|
|
u_int dx; /* drag start position */
|
|
|
|
u_int dy;
|
|
|
|
|
|
|
|
u_int selrx; /* selection reset positions */
|
|
|
|
u_int selry;
|
|
|
|
u_int endselrx;
|
|
|
|
u_int endselry;
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
u_int cx;
|
|
|
|
u_int cy;
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
u_int lastcx; /* position in last line w/ content */
|
|
|
|
u_int lastsx; /* size of last line w/ content */
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-05-16 16:10:28 +00:00
|
|
|
u_int mx; /* mark position */
|
|
|
|
u_int my;
|
|
|
|
int showmark;
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
int searchtype;
|
2021-04-01 06:46:12 +00:00
|
|
|
int searchdirection;
|
2020-03-31 16:53:23 +00:00
|
|
|
int searchregex;
|
2016-10-11 07:23:34 +00:00
|
|
|
char *searchstr;
|
2020-05-16 15:11:52 +00:00
|
|
|
u_char *searchmark;
|
2020-05-16 15:38:14 +00:00
|
|
|
int searchcount;
|
|
|
|
int searchmore;
|
2020-12-28 09:36:26 +00:00
|
|
|
int searchall;
|
2017-01-06 11:57:03 +00:00
|
|
|
int searchx;
|
|
|
|
int searchy;
|
|
|
|
int searcho;
|
2020-05-16 15:11:52 +00:00
|
|
|
u_char searchgen;
|
2009-08-21 07:33:58 +00:00
|
|
|
|
2020-04-01 09:36:37 +00:00
|
|
|
int timeout; /* search has timed out */
|
2020-05-16 15:38:14 +00:00
|
|
|
#define WINDOW_COPY_SEARCH_TIMEOUT 10000
|
|
|
|
#define WINDOW_COPY_SEARCH_ALL_TIMEOUT 200
|
2020-04-01 09:36:37 +00:00
|
|
|
|
2021-02-22 06:53:04 +00:00
|
|
|
int jumptype;
|
|
|
|
struct utf8_data *jumpchar;
|
2019-04-25 06:34:57 +00:00
|
|
|
|
|
|
|
struct event dragtimer;
|
|
|
|
#define WINDOW_COPY_DRAG_REPEAT_TIME 50000
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2019-04-25 06:34:57 +00:00
|
|
|
static void
|
|
|
|
window_copy_scroll_timer(__unused int fd, __unused short events, void *arg)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = arg;
|
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct timeval tv = {
|
|
|
|
.tv_usec = WINDOW_COPY_DRAG_REPEAT_TIME
|
|
|
|
};
|
|
|
|
|
|
|
|
evtimer_del(&data->dragtimer);
|
|
|
|
|
|
|
|
if (TAILQ_FIRST(&wp->modes) != wme)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data->cy == 0) {
|
|
|
|
evtimer_add(&data->dragtimer, &tv);
|
|
|
|
window_copy_cursor_up(wme, 1);
|
|
|
|
} else if (data->cy == screen_size_y(&data->screen) - 1) {
|
|
|
|
evtimer_add(&data->dragtimer, &tv);
|
|
|
|
window_copy_cursor_down(wme, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 17:51:34 +00:00
|
|
|
static struct screen *
|
2020-04-15 17:50:02 +00:00
|
|
|
window_copy_clone_screen(struct screen *src, struct screen *hint, u_int *cx,
|
2020-04-20 06:08:37 +00:00
|
|
|
u_int *cy, int trim)
|
2020-04-06 17:51:34 +00:00
|
|
|
{
|
2020-04-15 17:50:02 +00:00
|
|
|
struct screen *dst;
|
|
|
|
const struct grid_line *gl;
|
2020-05-16 15:49:20 +00:00
|
|
|
u_int sy, wx, wy;
|
|
|
|
int reflow;
|
2020-04-06 17:51:34 +00:00
|
|
|
|
|
|
|
dst = xcalloc(1, sizeof *dst);
|
2020-04-10 07:44:26 +00:00
|
|
|
|
|
|
|
sy = screen_hsize(src) + screen_size_y(src);
|
2020-04-20 06:08:37 +00:00
|
|
|
if (trim) {
|
|
|
|
while (sy > screen_hsize(src)) {
|
|
|
|
gl = grid_peek_line(src->grid, sy - 1);
|
|
|
|
if (gl->cellused != 0)
|
|
|
|
break;
|
|
|
|
sy--;
|
|
|
|
}
|
2020-04-10 07:44:26 +00:00
|
|
|
}
|
2020-04-17 14:06:42 +00:00
|
|
|
log_debug("%s: target screen is %ux%u, source %ux%u", __func__,
|
|
|
|
screen_size_x(src), sy, screen_size_x(hint),
|
|
|
|
screen_hsize(src) + screen_size_y(src));
|
2020-04-15 17:50:02 +00:00
|
|
|
screen_init(dst, screen_size_x(src), sy, screen_hlimit(src));
|
2020-05-16 15:49:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure history is on for the backing grid so lines are not deleted
|
|
|
|
* during resizing.
|
|
|
|
*/
|
|
|
|
dst->grid->flags |= GRID_HISTORY;
|
2020-04-15 17:50:02 +00:00
|
|
|
grid_duplicate_lines(dst->grid, 0, src->grid, 0, sy);
|
2020-04-06 17:51:34 +00:00
|
|
|
|
2020-04-15 17:50:02 +00:00
|
|
|
dst->grid->sy = sy - screen_hsize(src);
|
|
|
|
dst->grid->hsize = screen_hsize(src);
|
|
|
|
dst->grid->hscrolled = src->grid->hscrolled;
|
2020-04-17 14:06:42 +00:00
|
|
|
if (src->cy > dst->grid->sy - 1) {
|
|
|
|
dst->cx = 0;
|
|
|
|
dst->cy = dst->grid->sy - 1;
|
|
|
|
} else {
|
|
|
|
dst->cx = src->cx;
|
|
|
|
dst->cy = src->cy;
|
|
|
|
}
|
2020-04-15 17:50:02 +00:00
|
|
|
|
2020-05-16 15:49:20 +00:00
|
|
|
if (cx != NULL && cy != NULL) {
|
|
|
|
*cx = dst->cx;
|
|
|
|
*cy = screen_hsize(dst) + dst->cy;
|
|
|
|
reflow = (screen_size_x(hint) != screen_size_x(dst));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reflow = 0;
|
|
|
|
if (reflow)
|
|
|
|
grid_wrap_position(dst->grid, *cx, *cy, &wx, &wy);
|
2020-04-15 17:50:02 +00:00
|
|
|
screen_resize_cursor(dst, screen_size_x(hint), screen_size_y(hint), 1,
|
2020-05-16 15:49:20 +00:00
|
|
|
0, 0);
|
|
|
|
if (reflow)
|
|
|
|
grid_unwrap_position(dst->grid, cx, cy, wx, wy);
|
2020-04-06 17:51:34 +00:00
|
|
|
|
|
|
|
return (dst);
|
|
|
|
}
|
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
static struct window_copy_mode_data *
|
|
|
|
window_copy_common_init(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct window_copy_mode_data *data;
|
2019-03-08 10:34:20 +00:00
|
|
|
struct screen *base = &wp->base;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
wme->data = data = xcalloc(1, sizeof *data);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
data->cursordrag = CURSORDRAG_NONE;
|
2018-08-01 15:22:40 +00:00
|
|
|
data->lineflag = LINE_SEL_NONE;
|
2020-03-15 20:44:19 +00:00
|
|
|
data->selflag = SEL_CHAR;
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2017-05-12 10:45:38 +00:00
|
|
|
if (wp->searchstr != NULL) {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = wp->searchregex;
|
2017-05-12 10:45:38 +00:00
|
|
|
data->searchstr = xstrdup(wp->searchstr);
|
|
|
|
} else {
|
|
|
|
data->searchtype = WINDOW_COPY_OFF;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = 0;
|
2017-05-12 10:45:38 +00:00
|
|
|
data->searchstr = NULL;
|
|
|
|
}
|
2017-01-06 11:57:03 +00:00
|
|
|
data->searchx = data->searchy = data->searcho = -1;
|
2020-12-28 09:36:26 +00:00
|
|
|
data->searchall = 1;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2010-03-22 19:10:42 +00:00
|
|
|
data->jumptype = WINDOW_COPY_OFF;
|
2021-02-22 06:53:04 +00:00
|
|
|
data->jumpchar = NULL;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
screen_init(&data->screen, screen_size_x(base), screen_size_y(base), 0);
|
2018-07-31 11:49:26 +00:00
|
|
|
data->modekeys = options_get_number(wp->window->options, "mode-keys");
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-04-25 06:34:57 +00:00
|
|
|
evtimer_set(&data->dragtimer, window_copy_scroll_timer, wme);
|
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
return (data);
|
2010-04-06 21:35:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
static struct screen *
|
|
|
|
window_copy_init(struct window_mode_entry *wme,
|
|
|
|
__unused struct cmd_find_state *fs, struct args *args)
|
2010-04-06 21:35:44 +00:00
|
|
|
{
|
2020-04-10 07:44:26 +00:00
|
|
|
struct window_pane *wp = wme->swp;
|
2019-03-08 10:34:20 +00:00
|
|
|
struct window_copy_mode_data *data;
|
2020-04-15 17:50:02 +00:00
|
|
|
struct screen *base = &wp->base;
|
2019-03-08 10:34:20 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2020-04-15 17:50:02 +00:00
|
|
|
u_int i, cx, cy;
|
2010-04-06 21:35:44 +00:00
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
data = window_copy_common_init(wme);
|
2020-04-20 06:08:37 +00:00
|
|
|
data->backing = window_copy_clone_screen(base, &data->screen, &cx, &cy,
|
|
|
|
wme->swp != wme->wp);
|
2020-04-14 18:33:01 +00:00
|
|
|
|
2020-05-16 15:49:20 +00:00
|
|
|
data->cx = cx;
|
2020-04-15 17:50:02 +00:00
|
|
|
if (cy < screen_hsize(data->backing)) {
|
2020-04-14 18:33:01 +00:00
|
|
|
data->cy = 0;
|
2020-04-15 17:50:02 +00:00
|
|
|
data->oy = screen_hsize(data->backing) - cy;
|
|
|
|
} else {
|
2020-05-16 15:49:20 +00:00
|
|
|
data->cy = cy - screen_hsize(data->backing);
|
2020-04-15 17:50:02 +00:00
|
|
|
data->oy = 0;
|
|
|
|
}
|
2010-04-06 21:35:44 +00:00
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
data->scroll_exit = args_has(args, 'e');
|
2020-03-12 13:19:20 +00:00
|
|
|
data->hide_position = args_has(args, 'H');
|
2019-03-08 10:34:20 +00:00
|
|
|
|
|
|
|
data->screen.cx = data->cx;
|
|
|
|
data->screen.cy = data->cy;
|
2020-05-16 16:10:28 +00:00
|
|
|
data->mx = data->cx;
|
|
|
|
data->my = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
data->showmark = 0;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start(&ctx, &data->screen);
|
2019-03-08 10:34:20 +00:00
|
|
|
for (i = 0; i < screen_size_y(&data->screen); i++)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, &ctx, i);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_stop(&ctx);
|
2019-03-08 10:34:20 +00:00
|
|
|
|
|
|
|
return (&data->screen);
|
2010-04-06 21:35:44 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
static struct screen *
|
|
|
|
window_copy_view_init(struct window_mode_entry *wme,
|
|
|
|
__unused struct cmd_find_state *fs, __unused struct args *args)
|
2010-04-06 21:35:44 +00:00
|
|
|
{
|
2019-03-08 10:34:20 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data;
|
2019-03-08 10:34:20 +00:00
|
|
|
struct screen *base = &wp->base;
|
|
|
|
struct screen *s;
|
2010-04-06 21:35:44 +00:00
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
data = window_copy_common_init(wme);
|
2020-04-06 17:51:34 +00:00
|
|
|
data->viewmode = 1;
|
2019-03-07 20:24:21 +00:00
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
data->backing = s = xmalloc(sizeof *data->backing);
|
|
|
|
screen_init(s, screen_size_x(base), screen_size_y(base), UINT_MAX);
|
2020-05-16 16:10:28 +00:00
|
|
|
data->mx = data->cx;
|
|
|
|
data->my = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
data->showmark = 0;
|
2019-03-07 19:34:22 +00:00
|
|
|
|
2019-03-08 10:34:20 +00:00
|
|
|
return (&data->screen);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_free(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-04-25 06:34:57 +00:00
|
|
|
evtimer_del(&data->dragtimer);
|
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
free(data->searchmark);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(data->searchstr);
|
2021-02-22 06:53:04 +00:00
|
|
|
free(data->jumpchar);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2020-04-06 17:51:34 +00:00
|
|
|
screen_free(data->backing);
|
|
|
|
free(data->backing);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2020-04-06 17:51:34 +00:00
|
|
|
screen_free(&data->screen);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(data);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
void
|
|
|
|
window_copy_add(struct window_pane *wp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
window_copy_vadd(wp, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_vadd(struct window_pane *wp, const char *fmt, va_list ap)
|
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *backing = data->backing;
|
|
|
|
struct screen_write_ctx back_ctx, ctx;
|
|
|
|
struct grid_cell gc;
|
2014-11-06 10:56:44 +00:00
|
|
|
u_int old_hsize, old_cy;
|
2010-04-06 21:35:44 +00:00
|
|
|
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
|
|
|
|
old_hsize = screen_hsize(data->backing);
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start(&back_ctx, backing);
|
2010-04-06 21:35:44 +00:00
|
|
|
if (data->backing_written) {
|
|
|
|
/*
|
|
|
|
* On the second or later line, do a CRLF before writing
|
|
|
|
* (so it's on a new line).
|
|
|
|
*/
|
|
|
|
screen_write_carriagereturn(&back_ctx);
|
2017-05-12 13:00:56 +00:00
|
|
|
screen_write_linefeed(&back_ctx, 0, 8);
|
2010-04-06 21:35:44 +00:00
|
|
|
} else
|
|
|
|
data->backing_written = 1;
|
2014-11-06 10:56:44 +00:00
|
|
|
old_cy = backing->cy;
|
2015-11-12 11:09:11 +00:00
|
|
|
screen_write_vnputs(&back_ctx, 0, &gc, fmt, ap);
|
2010-04-06 21:35:44 +00:00
|
|
|
screen_write_stop(&back_ctx);
|
|
|
|
|
|
|
|
data->oy += screen_hsize(data->backing) - old_hsize;
|
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, &data->screen);
|
2010-04-06 21:35:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the history has changed, draw the top line.
|
|
|
|
* (If there's any history at all, it has changed.)
|
|
|
|
*/
|
|
|
|
if (screen_hsize(data->backing))
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, 0, 1);
|
2010-04-06 21:35:44 +00:00
|
|
|
|
2014-11-06 10:56:44 +00:00
|
|
|
/* Write the new lines. */
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, old_cy, backing->cy - old_cy + 1);
|
2010-04-06 21:35:44 +00:00
|
|
|
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2016-05-01 13:39:05 +00:00
|
|
|
window_copy_pageup(struct window_pane *wp, int half_page)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
window_copy_pageup1(TAILQ_FIRST(&wp->modes), half_page);
|
2019-03-07 20:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_pageup1(struct window_mode_entry *wme, int half_page)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
2017-01-05 09:07:15 +00:00
|
|
|
u_int n, ox, oy, px, py;
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
ox = window_copy_find_length(wme, oy);
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
if (data->cx != ox) {
|
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
|
|
|
data->cx = data->lastcx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 22:11:43 +00:00
|
|
|
n = 1;
|
2016-05-01 13:39:05 +00:00
|
|
|
if (screen_size_y(s) > 2) {
|
|
|
|
if (half_page)
|
|
|
|
n = screen_size_y(s) / 2;
|
|
|
|
else
|
|
|
|
n = screen_size_y(s) - 2;
|
|
|
|
}
|
2016-03-18 14:27:24 +00:00
|
|
|
|
2018-08-20 13:51:09 +00:00
|
|
|
if (data->oy + n > screen_hsize(data->backing)) {
|
2010-04-06 21:35:44 +00:00
|
|
|
data->oy = screen_hsize(data->backing);
|
2018-08-20 13:51:09 +00:00
|
|
|
if (data->cy < n)
|
|
|
|
data->cy = 0;
|
|
|
|
else
|
|
|
|
data->cy -= n;
|
|
|
|
} else
|
2009-08-13 22:11:43 +00:00
|
|
|
data->oy += n;
|
2016-03-18 14:27:24 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->screen.sel == NULL || !data->rectflag) {
|
2017-01-05 09:07:15 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
px = window_copy_find_length(wme, py);
|
2017-01-05 09:07:15 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_end_of_line(wme);
|
2016-03-18 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 17:03:10 +00:00
|
|
|
if (data->searchmark != NULL && !data->timeout)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2016-03-18 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 17:33:51 +00:00
|
|
|
static int
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_pagedown(struct window_mode_entry *wme, int half_page,
|
|
|
|
int scroll_exit)
|
2016-03-18 14:27:24 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2016-03-18 14:27:24 +00:00
|
|
|
struct screen *s = &data->screen;
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int n, ox, oy, px, py;
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
ox = window_copy_find_length(wme, oy);
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
if (data->cx != ox) {
|
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
|
|
|
data->cx = data->lastcx;
|
|
|
|
|
|
|
|
n = 1;
|
2016-05-01 13:39:05 +00:00
|
|
|
if (screen_size_y(s) > 2) {
|
|
|
|
if (half_page)
|
|
|
|
n = screen_size_y(s) / 2;
|
|
|
|
else
|
|
|
|
n = screen_size_y(s) - 2;
|
|
|
|
}
|
2016-03-18 14:27:24 +00:00
|
|
|
|
2018-08-20 13:51:09 +00:00
|
|
|
if (data->oy < n) {
|
2016-03-18 14:27:24 +00:00
|
|
|
data->oy = 0;
|
2018-08-20 13:51:09 +00:00
|
|
|
if (data->cy + (n - data->oy) >= screen_size_y(data->backing))
|
|
|
|
data->cy = screen_size_y(data->backing) - 1;
|
|
|
|
else
|
|
|
|
data->cy += n - data->oy;
|
|
|
|
} else
|
2016-03-18 14:27:24 +00:00
|
|
|
data->oy -= n;
|
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->screen.sel == NULL || !data->rectflag) {
|
2016-11-24 13:38:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
px = window_copy_find_length(wme, py);
|
2016-11-24 13:38:44 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_end_of_line(wme);
|
2016-03-18 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 11:16:15 +00:00
|
|
|
if (scroll_exit && data->oy == 0)
|
2017-02-08 17:33:51 +00:00
|
|
|
return (1);
|
2020-04-02 17:03:10 +00:00
|
|
|
if (data->searchmark != NULL && !data->timeout)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2017-02-08 17:33:51 +00:00
|
|
|
return (0);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_previous_paragraph(struct window_mode_entry *wme)
|
2016-04-27 09:39:09 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2016-05-23 20:03:14 +00:00
|
|
|
u_int oy;
|
2016-04-27 09:39:09 +00:00
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
while (oy > 0 && window_copy_find_length(wme, oy) == 0)
|
2016-04-27 09:39:09 +00:00
|
|
|
oy--;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
while (oy > 0 && window_copy_find_length(wme, oy) > 0)
|
2016-04-27 09:39:09 +00:00
|
|
|
oy--;
|
|
|
|
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(wme, 0, oy, 0);
|
2016-04-27 09:39:09 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_next_paragraph(struct window_mode_entry *wme)
|
2016-04-27 09:39:09 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2016-04-27 09:39:09 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int maxy, ox, oy;
|
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
maxy = screen_hsize(data->backing) + screen_size_y(s) - 1;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
while (oy < maxy && window_copy_find_length(wme, oy) == 0)
|
2016-04-27 09:39:09 +00:00
|
|
|
oy++;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
while (oy < maxy && window_copy_find_length(wme, oy) > 0)
|
2016-04-27 09:39:09 +00:00
|
|
|
oy++;
|
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
ox = window_copy_find_length(wme, oy);
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(wme, ox, oy, 0);
|
2016-04-27 09:39:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 17:59:39 +00:00
|
|
|
char *
|
|
|
|
window_copy_get_word(struct window_pane *wp, u_int x, u_int y)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct grid *gd = data->screen.grid;
|
|
|
|
|
|
|
|
return (format_grid_word(gd, x, gd->hsize + y));
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
window_copy_get_line(struct window_pane *wp, u_int y)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct grid *gd = data->screen.grid;
|
|
|
|
|
|
|
|
return (format_grid_line(gd, gd->hsize + y));
|
|
|
|
}
|
|
|
|
|
2021-02-22 07:09:06 +00:00
|
|
|
static void *
|
2020-06-11 19:43:34 +00:00
|
|
|
window_copy_cursor_word_cb(struct format_tree *ft)
|
|
|
|
{
|
|
|
|
struct window_pane *wp = format_get_pane(ft);
|
|
|
|
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
return (window_copy_get_word(wp, data->cx, data->cy));
|
|
|
|
}
|
|
|
|
|
2021-02-22 07:09:06 +00:00
|
|
|
static void *
|
2020-06-11 19:43:34 +00:00
|
|
|
window_copy_cursor_line_cb(struct format_tree *ft)
|
|
|
|
{
|
|
|
|
struct window_pane *wp = format_get_pane(ft);
|
|
|
|
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
return (window_copy_get_line(wp, data->cy));
|
|
|
|
}
|
|
|
|
|
2021-02-22 07:09:06 +00:00
|
|
|
static void *
|
2020-06-11 19:43:34 +00:00
|
|
|
window_copy_search_match_cb(struct format_tree *ft)
|
|
|
|
{
|
|
|
|
struct window_pane *wp = format_get_pane(ft);
|
|
|
|
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
return (window_copy_match_at_cursor(data));
|
|
|
|
}
|
|
|
|
|
2019-03-07 19:01:21 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft)
|
2019-03-07 19:01:21 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2019-03-07 19:01:21 +00:00
|
|
|
|
|
|
|
format_add(ft, "scroll_position", "%d", data->oy);
|
|
|
|
format_add(ft, "rectangle_toggle", "%d", data->rectflag);
|
2019-10-19 19:20:14 +00:00
|
|
|
|
|
|
|
format_add(ft, "copy_cursor_x", "%d", data->cx);
|
|
|
|
format_add(ft, "copy_cursor_y", "%d", data->cy);
|
|
|
|
|
|
|
|
format_add(ft, "selection_present", "%d", data->screen.sel != NULL);
|
|
|
|
if (data->screen.sel != NULL) {
|
|
|
|
format_add(ft, "selection_start_x", "%d", data->selx);
|
|
|
|
format_add(ft, "selection_start_y", "%d", data->sely);
|
|
|
|
format_add(ft, "selection_end_x", "%d", data->endselx);
|
|
|
|
format_add(ft, "selection_end_y", "%d", data->endsely);
|
2020-02-20 07:34:57 +00:00
|
|
|
format_add(ft, "selection_active", "%d",
|
|
|
|
data->cursordrag != CURSORDRAG_NONE);
|
|
|
|
} else
|
|
|
|
format_add(ft, "selection_active", "%d", 0);
|
2019-10-23 07:42:05 +00:00
|
|
|
|
2020-06-11 19:43:34 +00:00
|
|
|
format_add(ft, "search_present", "%d", data->searchmark != NULL);
|
|
|
|
format_add_cb(ft, "search_match", window_copy_search_match_cb);
|
2019-10-23 07:42:05 +00:00
|
|
|
|
2020-06-11 19:43:34 +00:00
|
|
|
format_add_cb(ft, "copy_cursor_word", window_copy_cursor_word_cb);
|
|
|
|
format_add_cb(ft, "copy_cursor_line", window_copy_cursor_line_cb);
|
2019-03-07 19:01:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2020-04-15 19:06:49 +00:00
|
|
|
window_copy_size_changed(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
2020-04-15 19:06:49 +00:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
int search = (data->searchmark != NULL);
|
2009-08-13 19:35:20 +00:00
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_clear_selection(wme);
|
2019-07-08 20:29:11 +00:00
|
|
|
window_copy_clear_marks(wme);
|
2009-08-13 19:35:20 +00:00
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start(&ctx, s);
|
2020-04-16 05:22:08 +00:00
|
|
|
window_copy_write_lines(wme, &ctx, 0, screen_size_y(s));
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_stop(&ctx);
|
2009-08-13 19:35:20 +00:00
|
|
|
|
2020-04-01 09:36:37 +00:00
|
|
|
if (search && !data->timeout)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 0);
|
2017-01-06 11:57:03 +00:00
|
|
|
data->searchx = data->cx;
|
|
|
|
data->searchy = data->cy;
|
|
|
|
data->searcho = data->oy;
|
2020-04-15 19:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct screen *s = &data->screen;
|
2020-05-16 15:49:20 +00:00
|
|
|
struct grid *gd = data->backing->grid;
|
|
|
|
u_int cx, cy, wx, wy;
|
|
|
|
int reflow;
|
2020-04-15 19:06:49 +00:00
|
|
|
|
|
|
|
screen_resize(s, sx, sy, 0);
|
2020-05-16 15:49:20 +00:00
|
|
|
cx = data->cx;
|
|
|
|
cy = gd->hsize + data->cy - data->oy;
|
|
|
|
reflow = (gd->sx != sx);
|
|
|
|
if (reflow)
|
|
|
|
grid_wrap_position(gd, cx, cy, &wx, &wy);
|
|
|
|
screen_resize_cursor(data->backing, sx, sy, 1, 0, 0);
|
|
|
|
if (reflow)
|
|
|
|
grid_unwrap_position(gd, &cx, &cy, wx, wy);
|
|
|
|
|
|
|
|
data->cx = cx;
|
|
|
|
if (cy < gd->hsize) {
|
|
|
|
data->cy = 0;
|
|
|
|
data->oy = gd->hsize - cy;
|
|
|
|
} else {
|
|
|
|
data->cy = cy - gd->hsize;
|
|
|
|
data->oy = 0;
|
|
|
|
}
|
2017-01-05 09:07:15 +00:00
|
|
|
|
2020-04-15 19:06:49 +00:00
|
|
|
window_copy_size_changed(wme);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static const char *
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_key_table(struct window_mode_entry *wme)
|
2016-10-11 07:23:34 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
if (options_get_number(wp->window->options, "mode-keys") == MODEKEY_VI)
|
|
|
|
return ("copy-mode-vi");
|
|
|
|
return ("copy-mode");
|
|
|
|
}
|
|
|
|
|
2020-03-31 16:53:23 +00:00
|
|
|
static int
|
|
|
|
window_copy_expand_search_string(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
const char *argument;
|
|
|
|
char *expanded;
|
|
|
|
|
|
|
|
if (cs->args->argc == 2) {
|
|
|
|
argument = cs->args->argv[1];
|
|
|
|
if (*argument != '\0') {
|
|
|
|
if (args_has(cs->args, 'F')) {
|
|
|
|
expanded = format_single(NULL, argument, NULL,
|
|
|
|
NULL, NULL, wme->wp);
|
|
|
|
if (*expanded == '\0') {
|
|
|
|
free(expanded);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = expanded;
|
|
|
|
} else {
|
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_append_selection(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct session *s = cs->s;
|
|
|
|
|
|
|
|
if (s != NULL)
|
|
|
|
window_copy_append_selection(wme);
|
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_append_selection_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct session *s = cs->s;
|
|
|
|
|
|
|
|
if (s != NULL)
|
|
|
|
window_copy_append_selection(wme);
|
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_back_to_indentation(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_cursor_back_to_indentation(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_begin_selection(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct client *c = cs->c;
|
|
|
|
struct mouse_event *m = cs->m;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
if (m != NULL) {
|
|
|
|
window_copy_start_drag(c, m);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
data->lineflag = LINE_SEL_NONE;
|
2020-03-19 13:28:52 +00:00
|
|
|
data->selflag = SEL_CHAR;
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_start_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_stop_selection(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
data->cursordrag = CURSORDRAG_NONE;
|
2019-03-27 13:25:11 +00:00
|
|
|
data->lineflag = LINE_SEL_NONE;
|
2020-03-15 20:44:19 +00:00
|
|
|
data->selflag = SEL_CHAR;
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_bottom_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = screen_size_y(&data->screen) - 1;
|
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_cancel(__unused struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_clear_selection(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct client *c = cs->c;
|
2019-03-26 21:01:19 +00:00
|
|
|
struct session *s = cs->s;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct winlink *wl = cs->wl;
|
|
|
|
struct window_pane *wp = wme->wp;
|
2019-03-26 21:01:19 +00:00
|
|
|
u_int np = wme->prefix;
|
2019-04-02 09:03:39 +00:00
|
|
|
char *prefix = NULL;
|
|
|
|
|
|
|
|
if (cs->args->argc == 2)
|
|
|
|
prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
window_copy_start_selection(wme);
|
|
|
|
for (; np > 1; np--)
|
|
|
|
window_copy_cursor_down(wme, 0);
|
|
|
|
window_copy_cursor_end_of_line(wme);
|
|
|
|
|
|
|
|
if (s != NULL) {
|
2019-04-02 09:03:39 +00:00
|
|
|
window_copy_copy_selection(wme, prefix);
|
|
|
|
|
|
|
|
free(prefix);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
2019-04-02 09:03:39 +00:00
|
|
|
|
|
|
|
free(prefix);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_copy_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct client *c = cs->c;
|
2019-03-26 21:01:19 +00:00
|
|
|
struct session *s = cs->s;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct winlink *wl = cs->wl;
|
|
|
|
struct window_pane *wp = wme->wp;
|
2020-03-19 13:28:52 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2019-03-26 21:01:19 +00:00
|
|
|
u_int np = wme->prefix;
|
2019-04-02 09:03:39 +00:00
|
|
|
char *prefix = NULL;
|
|
|
|
|
|
|
|
if (cs->args->argc == 2)
|
|
|
|
prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
|
2019-03-26 21:01:19 +00:00
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
data->selflag = SEL_CHAR;
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cursor_start_of_line(wme);
|
|
|
|
window_copy_start_selection(wme);
|
|
|
|
for (; np > 1; np--)
|
|
|
|
window_copy_cursor_down(wme, 0);
|
|
|
|
window_copy_cursor_end_of_line(wme);
|
|
|
|
|
|
|
|
if (s != NULL) {
|
2019-04-02 09:03:39 +00:00
|
|
|
window_copy_copy_selection(wme, prefix);
|
|
|
|
|
|
|
|
free(prefix);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
2019-04-02 09:03:39 +00:00
|
|
|
|
|
|
|
free(prefix);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_selection_no_clear(struct window_copy_cmd_state *cs)
|
2019-03-26 21:01:19 +00:00
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct client *c = cs->c;
|
2019-03-26 21:01:19 +00:00
|
|
|
struct session *s = cs->s;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct winlink *wl = cs->wl;
|
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
char *prefix = NULL;
|
|
|
|
|
|
|
|
if (cs->args->argc == 2)
|
|
|
|
prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
if (s != NULL)
|
2019-04-02 09:03:39 +00:00
|
|
|
window_copy_copy_selection(wme, prefix);
|
|
|
|
|
|
|
|
free(prefix);
|
2019-04-23 09:39:07 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_copy_selection(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_cmd_copy_selection_no_clear(cs);
|
|
|
|
window_copy_clear_selection(wme);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_copy_selection_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2019-04-02 09:03:39 +00:00
|
|
|
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_selection_no_clear(cs);
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_cursor_down(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_down(wme, 0);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2019-09-09 08:01:21 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_cursor_down_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix, cy;
|
|
|
|
|
|
|
|
cy = data->cy;
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_down(wme, 0);
|
|
|
|
if (cy == data->cy && data->oy == 0)
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_cursor_left(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_left(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_cursor_right(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
2020-09-22 08:41:27 +00:00
|
|
|
window_copy_cursor_right(wme, 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_cursor_up(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_up(wme, 0);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_end_of_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_cursor_end_of_line(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_halfpage_down(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (window_copy_pagedown(wme, 1, data->scroll_exit))
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_halfpage_down_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (window_copy_pagedown(wme, 1, 1))
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_halfpage_up(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_pageup1(wme, 1);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_history_bottom(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2020-04-09 14:30:28 +00:00
|
|
|
struct screen *s = data->backing;
|
2019-05-07 19:46:17 +00:00
|
|
|
u_int oy;
|
|
|
|
|
2020-04-09 14:30:28 +00:00
|
|
|
oy = screen_hsize(s) + data->cy - data->oy;
|
2019-05-07 19:46:17 +00:00
|
|
|
if (data->lineflag == LINE_SEL_RIGHT_LEFT && oy == data->endsely)
|
|
|
|
window_copy_other_end(wme);
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
data->cy = screen_size_y(&data->screen) - 1;
|
2020-04-09 14:30:28 +00:00
|
|
|
data->cx = window_copy_find_length(wme, screen_hsize(s) + data->cy);
|
2019-03-26 21:01:19 +00:00
|
|
|
data->oy = 0;
|
|
|
|
|
2020-04-02 17:03:10 +00:00
|
|
|
if (data->searchmark != NULL && !data->timeout)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_history_top(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2019-05-07 19:46:17 +00:00
|
|
|
u_int oy;
|
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
|
|
|
window_copy_other_end(wme);
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
data->cy = 0;
|
2019-05-07 19:46:17 +00:00
|
|
|
data->cx = 0;
|
2019-03-26 21:01:19 +00:00
|
|
|
data->oy = screen_hsize(data->backing);
|
|
|
|
|
2020-04-02 17:03:10 +00:00
|
|
|
if (data->searchmark != NULL && !data->timeout)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_jump_again(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
switch (data->jumptype) {
|
|
|
|
case WINDOW_COPY_JUMPFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump(wme);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_back(wme);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wme);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wme);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_jump_reverse(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
switch (data->jumptype) {
|
|
|
|
case WINDOW_COPY_JUMPFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_back(wme);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump(wme);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wme);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wme);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_middle_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = (screen_size_y(&data->screen) - 1) / 2;
|
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
2019-04-29 06:55:21 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_previous_matching_bracket(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct screen *s = data->backing;
|
|
|
|
char open[] = "{[(", close[] = "}])";
|
|
|
|
char tried, found, start, *cp;
|
2019-05-01 06:07:14 +00:00
|
|
|
u_int px, py, xx, n;
|
2019-04-29 06:55:21 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
int failed;
|
|
|
|
|
|
|
|
for (; np != 0; np--) {
|
|
|
|
/* Get cursor position and line length. */
|
|
|
|
px = data->cx;
|
|
|
|
py = screen_hsize(s) + data->cy - data->oy;
|
|
|
|
xx = window_copy_find_length(wme, py);
|
|
|
|
if (xx == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current character. If not on a bracket, try the
|
|
|
|
* previous. If still not, then behave like previous-word.
|
|
|
|
*/
|
|
|
|
tried = 0;
|
|
|
|
retry:
|
|
|
|
grid_get_cell(s->grid, px, py, &gc);
|
|
|
|
if (gc.data.size != 1 || (gc.flags & GRID_FLAG_PADDING))
|
|
|
|
cp = NULL;
|
|
|
|
else {
|
|
|
|
found = *gc.data.data;
|
|
|
|
cp = strchr(close, found);
|
|
|
|
}
|
|
|
|
if (cp == NULL) {
|
|
|
|
if (data->modekeys == MODEKEY_EMACS) {
|
|
|
|
if (!tried && px > 0) {
|
|
|
|
px--;
|
|
|
|
tried = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
2019-08-01 14:30:31 +00:00
|
|
|
window_copy_cursor_previous_word(wme, "}]) ", 1);
|
2019-04-29 06:55:21 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
start = open[cp - close];
|
|
|
|
|
|
|
|
/* Walk backward until the matching bracket is reached. */
|
|
|
|
n = 1;
|
|
|
|
failed = 0;
|
|
|
|
do {
|
|
|
|
if (px == 0) {
|
|
|
|
if (py == 0) {
|
|
|
|
failed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
py--;
|
|
|
|
xx = window_copy_find_length(wme, py);
|
|
|
|
} while (xx == 0 && py > 0);
|
|
|
|
if (xx == 0 && py == 0) {
|
|
|
|
failed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
px = xx - 1;
|
|
|
|
} else
|
|
|
|
px--;
|
|
|
|
|
|
|
|
grid_get_cell(s->grid, px, py, &gc);
|
|
|
|
if (gc.data.size == 1 &&
|
|
|
|
(~gc.flags & GRID_FLAG_PADDING)) {
|
|
|
|
if (*gc.data.data == found)
|
|
|
|
n++;
|
|
|
|
else if (*gc.data.data == start)
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
} while (n != 0);
|
|
|
|
|
|
|
|
/* Move the cursor to the found location if any. */
|
|
|
|
if (!failed)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(wme, px, py, 0);
|
2019-04-29 06:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_next_matching_bracket(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct screen *s = data->backing;
|
|
|
|
char open[] = "{[(", close[] = "}])";
|
|
|
|
char tried, found, end, *cp;
|
|
|
|
u_int px, py, xx, yy, sx, sy, n;
|
|
|
|
struct grid_cell gc;
|
|
|
|
int failed;
|
|
|
|
struct grid_line *gl;
|
|
|
|
|
|
|
|
for (; np != 0; np--) {
|
|
|
|
/* Get cursor position and line length. */
|
|
|
|
px = data->cx;
|
|
|
|
py = screen_hsize(s) + data->cy - data->oy;
|
|
|
|
xx = window_copy_find_length(wme, py);
|
|
|
|
yy = screen_hsize(s) + screen_size_y(s) - 1;
|
|
|
|
if (xx == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current character. If not on a bracket, try the
|
|
|
|
* next. If still not, then behave like next-word.
|
|
|
|
*/
|
|
|
|
tried = 0;
|
|
|
|
retry:
|
|
|
|
grid_get_cell(s->grid, px, py, &gc);
|
|
|
|
if (gc.data.size != 1 || (gc.flags & GRID_FLAG_PADDING))
|
|
|
|
cp = NULL;
|
|
|
|
else {
|
|
|
|
found = *gc.data.data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In vi mode, attempt to move to previous bracket if a
|
|
|
|
* closing bracket is found first. If this fails,
|
|
|
|
* return to the original cursor position.
|
|
|
|
*/
|
|
|
|
cp = strchr(close, found);
|
|
|
|
if (cp != NULL && data->modekeys == MODEKEY_VI) {
|
|
|
|
sx = data->cx;
|
|
|
|
sy = screen_hsize(s) + data->cy - data->oy;
|
|
|
|
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(wme, px, py, 0);
|
2019-04-29 06:55:21 +00:00
|
|
|
window_copy_cmd_previous_matching_bracket(cs);
|
|
|
|
|
|
|
|
px = data->cx;
|
|
|
|
py = screen_hsize(s) + data->cy - data->oy;
|
|
|
|
grid_get_cell(s->grid, px, py, &gc);
|
2020-05-16 16:03:30 +00:00
|
|
|
if (gc.data.size == 1 &&
|
|
|
|
(~gc.flags & GRID_FLAG_PADDING) &&
|
|
|
|
strchr(close, *gc.data.data) != NULL)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(wme, sx, sy, 0);
|
2019-04-29 06:55:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = strchr(open, found);
|
|
|
|
}
|
|
|
|
if (cp == NULL) {
|
|
|
|
if (data->modekeys == MODEKEY_EMACS) {
|
|
|
|
if (!tried && px <= xx) {
|
|
|
|
px++;
|
|
|
|
tried = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
2020-03-20 13:12:04 +00:00
|
|
|
window_copy_cursor_next_word_end(wme, "{[( ",
|
|
|
|
0);
|
2019-04-29 06:55:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* For vi, continue searching for bracket until EOL. */
|
|
|
|
if (px > xx) {
|
|
|
|
if (py == yy)
|
|
|
|
continue;
|
|
|
|
gl = grid_get_line(s->grid, py);
|
|
|
|
if (~gl->flags & GRID_LINE_WRAPPED)
|
|
|
|
continue;
|
|
|
|
if (gl->cellsize > s->grid->sx)
|
|
|
|
continue;
|
|
|
|
px = 0;
|
|
|
|
py++;
|
|
|
|
xx = window_copy_find_length(wme, py);
|
|
|
|
} else
|
|
|
|
px++;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
end = close[cp - open];
|
|
|
|
|
|
|
|
/* Walk forward until the matching bracket is reached. */
|
|
|
|
n = 1;
|
|
|
|
failed = 0;
|
|
|
|
do {
|
|
|
|
if (px > xx) {
|
|
|
|
if (py == yy) {
|
|
|
|
failed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
px = 0;
|
|
|
|
py++;
|
|
|
|
xx = window_copy_find_length(wme, py);
|
|
|
|
} else
|
|
|
|
px++;
|
|
|
|
|
|
|
|
grid_get_cell(s->grid, px, py, &gc);
|
|
|
|
if (gc.data.size == 1 &&
|
|
|
|
(~gc.flags & GRID_FLAG_PADDING)) {
|
|
|
|
if (*gc.data.data == found)
|
|
|
|
n++;
|
|
|
|
else if (*gc.data.data == end)
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
} while (n != 0);
|
|
|
|
|
|
|
|
/* Move the cursor to the found location if any. */
|
|
|
|
if (!failed)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(wme, px, py, 0);
|
2019-04-29 06:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_next_paragraph(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_next_paragraph(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_next_space(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word(wme, " ");
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_next_space_end(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
2020-03-20 13:12:04 +00:00
|
|
|
window_copy_cursor_next_word_end(wme, " ", 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_next_word(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct session *s = cs->s;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
const char *ws;
|
|
|
|
|
|
|
|
ws = options_get_string(s->options, "word-separators");
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word(wme, ws);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_next_word_end(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct session *s = cs->s;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
const char *ws;
|
|
|
|
|
|
|
|
ws = options_get_string(s->options, "word-separators");
|
|
|
|
for (; np != 0; np--)
|
2020-03-20 13:12:04 +00:00
|
|
|
window_copy_cursor_next_word_end(wme, ws, 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_other_end(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
2020-03-20 06:09:19 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
2020-03-20 06:09:19 +00:00
|
|
|
data->selflag = SEL_CHAR;
|
2019-03-26 21:01:19 +00:00
|
|
|
if ((np % 2) != 0)
|
|
|
|
window_copy_other_end(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_page_down(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (window_copy_pagedown(wme, 0, data->scroll_exit))
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_page_down_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (window_copy_pagedown(wme, 0, 1))
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_page_up(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_pageup1(wme, 0);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_previous_paragraph(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_previous_paragraph(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_previous_space(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
2019-08-01 14:30:31 +00:00
|
|
|
window_copy_cursor_previous_word(wme, " ", 1);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_previous_word(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct session *s = cs->s;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
const char *ws;
|
|
|
|
|
|
|
|
ws = options_get_string(s->options, "word-separators");
|
|
|
|
for (; np != 0; np--)
|
2019-08-01 14:30:31 +00:00
|
|
|
window_copy_cursor_previous_word(wme, ws, 1);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2021-01-22 10:24:52 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_rectangle_on(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
data->lineflag = LINE_SEL_NONE;
|
|
|
|
window_copy_rectangle_set(wme, 1);
|
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_rectangle_off(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
data->lineflag = LINE_SEL_NONE;
|
|
|
|
window_copy_rectangle_set(wme, 0);
|
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_rectangle_toggle(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
data->lineflag = LINE_SEL_NONE;
|
2021-01-22 10:24:52 +00:00
|
|
|
window_copy_rectangle_set(wme, !data->rectflag);
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_scroll_down(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_down(wme, 1);
|
|
|
|
if (data->scroll_exit && data->oy == 0)
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_scroll_down_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_down(wme, 1);
|
|
|
|
if (data->oy == 0)
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_scroll_up(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_up(wme, 1);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_search_again(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_up(wme, data->searchregex);
|
2019-03-26 21:01:19 +00:00
|
|
|
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_down(wme, data->searchregex);
|
2019-03-26 21:01:19 +00:00
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_search_reverse(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_down(wme, data->searchregex);
|
2019-03-26 21:01:19 +00:00
|
|
|
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_up(wme, data->searchregex);
|
2019-03-26 21:01:19 +00:00
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_select_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
data->lineflag = LINE_SEL_LEFT_RIGHT;
|
|
|
|
data->rectflag = 0;
|
2020-02-24 09:53:59 +00:00
|
|
|
data->selflag = SEL_LINE;
|
|
|
|
data->dx = data->cx;
|
|
|
|
data->dy = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
window_copy_cursor_start_of_line(wme);
|
2020-02-24 09:53:59 +00:00
|
|
|
data->selrx = data->cx;
|
|
|
|
data->selry = screen_hsize(data->backing) + data->cy - data->oy;
|
2020-03-21 13:19:56 +00:00
|
|
|
data->endselry = data->selry;
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_start_selection(wme);
|
|
|
|
window_copy_cursor_end_of_line(wme);
|
2021-03-09 08:24:09 +00:00
|
|
|
data->endselry = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
data->endselrx = window_copy_find_length(wme, data->endselry);
|
|
|
|
for (; np > 1; np--) {
|
|
|
|
window_copy_cursor_down(wme, 0);
|
|
|
|
window_copy_cursor_end_of_line(wme);
|
|
|
|
}
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_select_word(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct session *s = cs->s;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2021-03-09 08:24:09 +00:00
|
|
|
u_int px, py, nextx, nexty;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
data->lineflag = LINE_SEL_LEFT_RIGHT;
|
|
|
|
data->rectflag = 0;
|
2020-02-24 09:53:59 +00:00
|
|
|
data->selflag = SEL_WORD;
|
|
|
|
data->dx = data->cx;
|
|
|
|
data->dy = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
data->ws = options_get_string(s->options, "word-separators");
|
|
|
|
window_copy_cursor_previous_word(wme, data->ws, 0);
|
2020-03-20 20:12:39 +00:00
|
|
|
px = data->cx;
|
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
data->selrx = px;
|
|
|
|
data->selry = py;
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_start_selection(wme);
|
2020-02-13 09:02:07 +00:00
|
|
|
|
2021-03-09 08:24:09 +00:00
|
|
|
/* Handle single character words. */
|
|
|
|
nextx = px + 1;
|
|
|
|
nexty = py;
|
|
|
|
if (grid_get_line(data->backing->grid, nexty)->flags &
|
|
|
|
GRID_LINE_WRAPPED && nextx > screen_size_x(data->backing) - 1) {
|
|
|
|
nextx = 0;
|
|
|
|
nexty++;
|
|
|
|
}
|
2020-02-24 09:53:59 +00:00
|
|
|
if (px >= window_copy_find_length(wme, py) ||
|
2021-03-09 08:24:09 +00:00
|
|
|
!window_copy_in_set(wme, nextx, nexty, data->ws))
|
2020-03-20 13:12:04 +00:00
|
|
|
window_copy_cursor_next_word_end(wme, data->ws, 1);
|
2020-02-13 09:02:07 +00:00
|
|
|
else {
|
|
|
|
window_copy_update_cursor(wme, px, data->cy);
|
2020-03-20 13:12:04 +00:00
|
|
|
if (window_copy_update_selection(wme, 1, 1))
|
2020-02-13 09:02:07 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
|
|
|
}
|
2020-02-24 09:53:59 +00:00
|
|
|
data->endselrx = data->cx;
|
|
|
|
data->endselry = screen_hsize(data->backing) + data->cy - data->oy;
|
2021-03-09 08:24:09 +00:00
|
|
|
if (data->dy > data->endselry) {
|
|
|
|
data->dy = data->endselry;
|
|
|
|
data->dx = data->endselrx;
|
|
|
|
} else if (data->dx > data->endselrx)
|
2020-03-20 20:12:39 +00:00
|
|
|
data->dx = data->endselrx;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
2020-05-16 16:10:28 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_set_mark(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = cs->wme->data;
|
|
|
|
|
|
|
|
data->mx = data->cx;
|
|
|
|
data->my = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
data->showmark = 1;
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_start_of_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_cursor_start_of_line(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_top_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = 0;
|
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_pipe_no_clear(struct window_copy_cmd_state *cs)
|
2019-03-26 21:01:19 +00:00
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct client *c = cs->c;
|
2019-03-26 21:01:19 +00:00
|
|
|
struct session *s = cs->s;
|
2019-04-02 09:03:39 +00:00
|
|
|
struct winlink *wl = cs->wl;
|
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
char *command = NULL;
|
|
|
|
char *prefix = NULL;
|
|
|
|
|
|
|
|
if (cs->args->argc == 3)
|
|
|
|
prefix = format_single(NULL, cs->args->argv[2], c, s, wl, wp);
|
2019-03-26 21:01:19 +00:00
|
|
|
|
2020-04-17 08:03:22 +00:00
|
|
|
if (s != NULL && cs->args->argc > 1 && *cs->args->argv[1] != '\0')
|
2019-04-02 09:03:39 +00:00
|
|
|
command = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
|
2020-04-17 08:03:22 +00:00
|
|
|
window_copy_copy_pipe(wme, s, prefix, command);
|
|
|
|
free(command);
|
2019-04-02 09:03:39 +00:00
|
|
|
|
|
|
|
free(prefix);
|
2019-03-26 21:01:19 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_pipe(struct window_copy_cmd_state *cs)
|
2019-03-26 21:01:19 +00:00
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2019-04-02 09:03:39 +00:00
|
|
|
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_pipe_no_clear(cs);
|
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
2019-03-26 21:01:19 +00:00
|
|
|
|
2019-04-23 09:39:07 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_copy_pipe_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2019-04-02 09:03:39 +00:00
|
|
|
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_pipe_no_clear(cs);
|
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
2019-03-26 21:01:19 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 14:46:53 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_pipe_no_clear(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct client *c = cs->c;
|
|
|
|
struct session *s = cs->s;
|
|
|
|
struct winlink *wl = cs->wl;
|
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
char *command = NULL;
|
|
|
|
|
|
|
|
if (s != NULL && cs->args->argc > 1 && *cs->args->argv[1] != '\0')
|
|
|
|
command = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
|
|
|
|
window_copy_pipe(wme, s, command);
|
|
|
|
free(command);
|
|
|
|
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_pipe(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_cmd_pipe_no_clear(cs);
|
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_pipe_and_cancel(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_cmd_pipe_no_clear(cs);
|
|
|
|
window_copy_clear_selection(wme);
|
|
|
|
return (WINDOW_COPY_CMD_CANCEL);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_goto_line(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
const char *argument = cs->args->argv[1];
|
|
|
|
|
|
|
|
if (*argument != '\0')
|
|
|
|
window_copy_goto_line(wme, argument);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_jump_backward(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
const char *argument = cs->args->argv[1];
|
|
|
|
|
|
|
|
if (*argument != '\0') {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPBACKWARD;
|
2021-02-22 06:53:04 +00:00
|
|
|
free(data->jumpchar);
|
|
|
|
data->jumpchar = utf8_fromcstr(argument);
|
2019-03-26 21:01:19 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_back(wme);
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_jump_forward(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
const char *argument = cs->args->argv[1];
|
|
|
|
|
|
|
|
if (*argument != '\0') {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPFORWARD;
|
2021-02-22 06:53:04 +00:00
|
|
|
free(data->jumpchar);
|
|
|
|
data->jumpchar = utf8_fromcstr(argument);
|
2019-03-26 21:01:19 +00:00
|
|
|
for (; np != 0; np--)
|
2019-04-02 09:03:39 +00:00
|
|
|
window_copy_cursor_jump(wme);
|
2019-03-26 21:01:19 +00:00
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_jump_to_backward(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
const char *argument = cs->args->argv[1];
|
|
|
|
|
|
|
|
if (*argument != '\0') {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPTOBACKWARD;
|
2021-02-22 06:53:04 +00:00
|
|
|
free(data->jumpchar);
|
|
|
|
data->jumpchar = utf8_fromcstr(argument);
|
2019-03-26 21:01:19 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wme);
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_jump_to_forward(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
const char *argument = cs->args->argv[1];
|
|
|
|
|
|
|
|
if (*argument != '\0') {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPTOFORWARD;
|
2021-02-22 06:53:04 +00:00
|
|
|
free(data->jumpchar);
|
|
|
|
data->jumpchar = utf8_fromcstr(argument);
|
2019-03-26 21:01:19 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wme);
|
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2020-05-16 16:10:28 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_jump_to_mark(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
|
|
|
|
window_copy_jump_to_mark(wme);
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_search_backward(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
2020-03-31 16:53:23 +00:00
|
|
|
if (!window_copy_expand_search_string(cs))
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
|
2019-08-14 10:02:24 +00:00
|
|
|
if (data->searchstr != NULL) {
|
2019-03-26 21:01:19 +00:00
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = 1;
|
2020-04-01 09:36:37 +00:00
|
|
|
data->timeout = 0;
|
2019-03-26 21:01:19 +00:00
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_up(wme, 1);
|
2019-03-26 21:01:19 +00:00
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
2020-03-31 16:53:23 +00:00
|
|
|
window_copy_cmd_search_backward_text(struct window_copy_cmd_state *cs)
|
2019-03-26 21:01:19 +00:00
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
2020-03-31 16:53:23 +00:00
|
|
|
if (!window_copy_expand_search_string(cs))
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
|
|
|
|
if (data->searchstr != NULL) {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
|
|
|
data->searchregex = 0;
|
2020-04-01 09:36:37 +00:00
|
|
|
data->timeout = 0;
|
2020-03-31 16:53:23 +00:00
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_up(wme, 0);
|
2019-08-14 10:02:24 +00:00
|
|
|
}
|
2020-03-31 16:53:23 +00:00
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_search_forward(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
if (!window_copy_expand_search_string(cs))
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
|
2019-08-14 10:02:24 +00:00
|
|
|
if (data->searchstr != NULL) {
|
2019-03-26 21:01:19 +00:00
|
|
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = 1;
|
2020-04-01 09:36:37 +00:00
|
|
|
data->timeout = 0;
|
2019-03-26 21:01:19 +00:00
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_down(wme, 1);
|
2019-03-26 21:01:19 +00:00
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2020-03-31 16:53:23 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_search_forward_text(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int np = wme->prefix;
|
|
|
|
|
|
|
|
if (!window_copy_expand_search_string(cs))
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
|
|
|
|
if (data->searchstr != NULL) {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
|
|
|
data->searchregex = 0;
|
2020-04-01 09:36:37 +00:00
|
|
|
data->timeout = 0;
|
2020-03-31 16:53:23 +00:00
|
|
|
for (; np != 0; np--)
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_down(wme, 0);
|
2020-03-31 16:53:23 +00:00
|
|
|
}
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_search_backward_incremental(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
const char *argument = cs->args->argv[1];
|
|
|
|
const char *ss = data->searchstr;
|
2019-06-05 19:00:36 +00:00
|
|
|
char prefix;
|
|
|
|
enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
2020-04-01 09:36:37 +00:00
|
|
|
data->timeout = 0;
|
|
|
|
|
2021-01-08 08:22:10 +00:00
|
|
|
log_debug ("%s: %s", __func__, argument);
|
|
|
|
|
2019-06-05 19:00:36 +00:00
|
|
|
prefix = *argument++;
|
2019-03-26 21:01:19 +00:00
|
|
|
if (data->searchx == -1 || data->searchy == -1) {
|
|
|
|
data->searchx = data->cx;
|
|
|
|
data->searchy = data->cy;
|
|
|
|
data->searcho = data->oy;
|
|
|
|
} else if (ss != NULL && strcmp(argument, ss) != 0) {
|
|
|
|
data->cx = data->searchx;
|
|
|
|
data->cy = data->searchy;
|
|
|
|
data->oy = data->searcho;
|
|
|
|
action = WINDOW_COPY_CMD_REDRAW;
|
|
|
|
}
|
|
|
|
if (*argument == '\0') {
|
|
|
|
window_copy_clear_marks(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
2019-06-05 19:00:36 +00:00
|
|
|
switch (prefix) {
|
2019-03-26 21:01:19 +00:00
|
|
|
case '=':
|
|
|
|
case '-':
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = 0;
|
2019-03-26 21:01:19 +00:00
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
2021-04-01 06:46:12 +00:00
|
|
|
if (!window_copy_search_up(wme, 0)) {
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_clear_marks(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = 0;
|
2019-03-26 21:01:19 +00:00
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
2021-04-01 06:46:12 +00:00
|
|
|
if (!window_copy_search_down(wme, 0)) {
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_clear_marks(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_search_forward_incremental(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
const char *argument = cs->args->argv[1];
|
|
|
|
const char *ss = data->searchstr;
|
2019-06-05 19:00:36 +00:00
|
|
|
char prefix;
|
|
|
|
enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
2020-04-01 09:36:37 +00:00
|
|
|
data->timeout = 0;
|
|
|
|
|
2021-01-08 08:22:10 +00:00
|
|
|
log_debug ("%s: %s", __func__, argument);
|
|
|
|
|
2019-06-05 19:00:36 +00:00
|
|
|
prefix = *argument++;
|
2019-03-26 21:01:19 +00:00
|
|
|
if (data->searchx == -1 || data->searchy == -1) {
|
|
|
|
data->searchx = data->cx;
|
|
|
|
data->searchy = data->cy;
|
|
|
|
data->searcho = data->oy;
|
|
|
|
} else if (ss != NULL && strcmp(argument, ss) != 0) {
|
|
|
|
data->cx = data->searchx;
|
|
|
|
data->cy = data->searchy;
|
|
|
|
data->oy = data->searcho;
|
|
|
|
action = WINDOW_COPY_CMD_REDRAW;
|
|
|
|
}
|
|
|
|
if (*argument == '\0') {
|
|
|
|
window_copy_clear_marks(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
2019-06-05 19:00:36 +00:00
|
|
|
switch (prefix) {
|
2019-03-26 21:01:19 +00:00
|
|
|
case '=':
|
|
|
|
case '+':
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = 0;
|
2019-03-26 21:01:19 +00:00
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
2021-04-01 06:46:12 +00:00
|
|
|
if (!window_copy_search_down(wme, 0)) {
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_clear_marks(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
2020-03-31 16:53:23 +00:00
|
|
|
data->searchregex = 0;
|
2019-03-26 21:01:19 +00:00
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
2021-04-01 06:46:12 +00:00
|
|
|
if (!window_copy_search_up(wme, 0)) {
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_clear_marks(wme);
|
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (action);
|
|
|
|
}
|
|
|
|
|
2020-04-06 17:51:34 +00:00
|
|
|
static enum window_copy_cmd_action
|
|
|
|
window_copy_cmd_refresh_from_pane(struct window_copy_cmd_state *cs)
|
|
|
|
{
|
|
|
|
struct window_mode_entry *wme = cs->wme;
|
2020-04-10 07:44:26 +00:00
|
|
|
struct window_pane *wp = wme->swp;
|
2020-04-06 17:51:34 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
if (data->viewmode)
|
|
|
|
return (WINDOW_COPY_CMD_NOTHING);
|
|
|
|
|
|
|
|
screen_free(data->backing);
|
|
|
|
free(data->backing);
|
2020-04-15 17:50:02 +00:00
|
|
|
data->backing = window_copy_clone_screen(&wp->base, &data->screen, NULL,
|
2020-04-20 06:08:37 +00:00
|
|
|
NULL, wme->swp != wme->wp);
|
2020-04-06 17:51:34 +00:00
|
|
|
|
2020-04-15 19:06:49 +00:00
|
|
|
window_copy_size_changed(wme);
|
2020-04-06 17:51:34 +00:00
|
|
|
return (WINDOW_COPY_CMD_REDRAW);
|
|
|
|
}
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
static const struct {
|
|
|
|
const char *command;
|
|
|
|
int minargs;
|
|
|
|
int maxargs;
|
2020-06-04 10:24:14 +00:00
|
|
|
enum window_copy_cmd_clear clear;
|
2019-03-26 21:01:19 +00:00
|
|
|
enum window_copy_cmd_action (*f)(struct window_copy_cmd_state *);
|
|
|
|
} window_copy_cmd_table[] = {
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "append-selection", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_append_selection },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "append-selection-and-cancel", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_append_selection_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "back-to-indentation", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_back_to_indentation },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "begin-selection", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_begin_selection },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "bottom-line", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_bottom_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "cancel", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "clear-selection", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_clear_selection },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-end-of-line", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_copy_end_of_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-line", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_copy_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-pipe-no-clear", 0, 2, WINDOW_COPY_CMD_CLEAR_NEVER,
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_pipe_no_clear },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-pipe", 0, 2, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_copy_pipe },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-pipe-and-cancel", 0, 2, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_copy_pipe_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-selection-no-clear", 0, 1, WINDOW_COPY_CMD_CLEAR_NEVER,
|
2019-04-23 09:39:07 +00:00
|
|
|
window_copy_cmd_copy_selection_no_clear },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-selection", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_copy_selection },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "copy-selection-and-cancel", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_copy_selection_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "cursor-down", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_cursor_down },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "cursor-down-and-cancel", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-09-09 08:01:21 +00:00
|
|
|
window_copy_cmd_cursor_down_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "cursor-left", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_cursor_left },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "cursor-right", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_cursor_right },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "cursor-up", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_cursor_up },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "end-of-line", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_end_of_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "goto-line", 1, 1, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_goto_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "halfpage-down", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_halfpage_down },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "halfpage-down-and-cancel", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_halfpage_down_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "halfpage-up", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_halfpage_up },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "history-bottom", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_history_bottom },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "history-top", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_history_top },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "jump-again", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_jump_again },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "jump-backward", 1, 1, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_jump_backward },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "jump-forward", 1, 1, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_jump_forward },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "jump-reverse", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_jump_reverse },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "jump-to-backward", 1, 1, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_jump_to_backward },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "jump-to-forward", 1, 1, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_jump_to_forward },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "jump-to-mark", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2020-05-16 16:10:28 +00:00
|
|
|
window_copy_cmd_jump_to_mark },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "middle-line", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_middle_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "next-matching-bracket", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-04-29 06:55:21 +00:00
|
|
|
window_copy_cmd_next_matching_bracket },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "next-paragraph", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_next_paragraph },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "next-space", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_next_space },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "next-space-end", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_next_space_end },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "next-word", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_next_word },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "next-word-end", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_next_word_end },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "other-end", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_other_end },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "page-down", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_page_down },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "page-down-and-cancel", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_page_down_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "page-up", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_page_up },
|
2021-02-08 14:46:53 +00:00
|
|
|
{ "pipe-no-clear", 0, 1, WINDOW_COPY_CMD_CLEAR_NEVER,
|
|
|
|
window_copy_cmd_pipe_no_clear },
|
|
|
|
{ "pipe", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
|
|
|
window_copy_cmd_pipe },
|
|
|
|
{ "pipe-and-cancel", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
|
|
|
window_copy_cmd_pipe_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "previous-matching-bracket", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-04-29 06:55:21 +00:00
|
|
|
window_copy_cmd_previous_matching_bracket },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "previous-paragraph", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_previous_paragraph },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "previous-space", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_previous_space },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "previous-word", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_previous_word },
|
2021-01-22 10:24:52 +00:00
|
|
|
{ "rectangle-on", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
|
|
|
window_copy_cmd_rectangle_on },
|
|
|
|
{ "rectangle-off", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
|
|
|
window_copy_cmd_rectangle_off },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "rectangle-toggle", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_rectangle_toggle },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "refresh-from-pane", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2020-04-06 17:51:34 +00:00
|
|
|
window_copy_cmd_refresh_from_pane },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "scroll-down", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_scroll_down },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "scroll-down-and-cancel", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_scroll_down_and_cancel },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "scroll-up", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_scroll_up },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-again", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_search_again },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-backward", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_search_backward },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-backward-text", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2020-03-31 16:53:23 +00:00
|
|
|
window_copy_cmd_search_backward_text },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-backward-incremental", 1, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_search_backward_incremental },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-forward", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_search_forward },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-forward-text", 0, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2020-03-31 16:53:23 +00:00
|
|
|
window_copy_cmd_search_forward_text },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-forward-incremental", 1, 1, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_search_forward_incremental },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "search-reverse", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_search_reverse },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "select-line", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_select_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "select-word", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_select_word },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "set-mark", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2020-05-16 16:10:28 +00:00
|
|
|
window_copy_cmd_set_mark },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "start-of-line", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_start_of_line },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "stop-selection", 0, 0, WINDOW_COPY_CMD_CLEAR_ALWAYS,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_stop_selection },
|
2020-06-04 10:24:14 +00:00
|
|
|
{ "top-line", 0, 0, WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
|
2019-03-26 21:01:19 +00:00
|
|
|
window_copy_cmd_top_line },
|
|
|
|
};
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_command(struct window_mode_entry *wme, struct client *c,
|
2019-04-02 09:03:39 +00:00
|
|
|
struct session *s, struct winlink *wl, struct args *args,
|
2019-03-07 20:24:21 +00:00
|
|
|
struct mouse_event *m)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2019-03-26 21:01:19 +00:00
|
|
|
struct window_copy_cmd_state cs;
|
|
|
|
enum window_copy_cmd_action action;
|
2020-06-04 10:24:14 +00:00
|
|
|
enum window_copy_cmd_clear clear = WINDOW_COPY_CMD_CLEAR_NEVER;
|
2019-03-26 21:01:19 +00:00
|
|
|
const char *command;
|
|
|
|
u_int i;
|
2020-06-04 10:24:14 +00:00
|
|
|
int keys;
|
2016-10-11 07:23:34 +00:00
|
|
|
|
|
|
|
if (args->argc == 0)
|
2009-08-18 07:08:26 +00:00
|
|
|
return;
|
2016-10-11 07:23:34 +00:00
|
|
|
command = args->argv[0];
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2018-10-03 15:27:55 +00:00
|
|
|
if (m != NULL && m->valid && !MOUSE_WHEEL(m->b))
|
2016-10-11 09:30:36 +00:00
|
|
|
window_copy_move_mouse(m);
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
cs.wme = wme;
|
|
|
|
cs.args = args;
|
|
|
|
cs.m = m;
|
2019-04-02 09:03:39 +00:00
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
cs.c = c;
|
|
|
|
cs.s = s;
|
2019-04-02 09:03:39 +00:00
|
|
|
cs.wl = wl;
|
2019-03-26 21:01:19 +00:00
|
|
|
|
|
|
|
action = WINDOW_COPY_CMD_NOTHING;
|
|
|
|
for (i = 0; i < nitems(window_copy_cmd_table); i++) {
|
|
|
|
if (strcmp(window_copy_cmd_table[i].command, command) == 0) {
|
|
|
|
if (args->argc - 1 < window_copy_cmd_table[i].minargs ||
|
|
|
|
args->argc - 1 > window_copy_cmd_table[i].maxargs)
|
2016-10-11 07:23:34 +00:00
|
|
|
break;
|
2020-06-04 10:24:14 +00:00
|
|
|
clear = window_copy_cmd_table[i].clear;
|
2019-03-26 21:01:19 +00:00
|
|
|
action = window_copy_cmd_table[i].f (&cs);
|
|
|
|
break;
|
2017-01-06 11:57:03 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
if (strncmp(command, "search-", 7) != 0 && data->searchmark != NULL) {
|
2019-11-25 20:42:18 +00:00
|
|
|
keys = options_get_number(wme->wp->window->options, "mode-keys");
|
2020-06-04 10:24:14 +00:00
|
|
|
if (clear == WINDOW_COPY_CMD_CLEAR_EMACS_ONLY &&
|
|
|
|
keys == MODEKEY_VI)
|
|
|
|
clear = WINDOW_COPY_CMD_CLEAR_NEVER;
|
|
|
|
if (clear != WINDOW_COPY_CMD_CLEAR_NEVER) {
|
2019-11-25 20:42:18 +00:00
|
|
|
window_copy_clear_marks(wme);
|
|
|
|
data->searchx = data->searchy = -1;
|
|
|
|
}
|
2019-03-26 21:01:19 +00:00
|
|
|
if (action == WINDOW_COPY_CMD_NOTHING)
|
|
|
|
action = WINDOW_COPY_CMD_REDRAW;
|
2017-01-05 09:07:15 +00:00
|
|
|
}
|
2019-03-08 10:29:25 +00:00
|
|
|
wme->prefix = 1;
|
|
|
|
|
2019-03-26 21:01:19 +00:00
|
|
|
if (action == WINDOW_COPY_CMD_CANCEL)
|
|
|
|
window_pane_reset_mode(wme->wp);
|
|
|
|
else if (action == WINDOW_COPY_CMD_REDRAW)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2010-03-02 00:32:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(struct window_mode_entry *wme, u_int px, u_int py,
|
|
|
|
int no_redraw)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct grid *gd = data->backing->grid;
|
2009-08-18 07:08:26 +00:00
|
|
|
u_int offset, gap;
|
|
|
|
|
|
|
|
data->cx = px;
|
|
|
|
|
2017-11-13 11:49:11 +00:00
|
|
|
if (py >= gd->hsize - data->oy && py < gd->hsize - data->oy + gd->sy)
|
|
|
|
data->cy = py - (gd->hsize - data->oy);
|
|
|
|
else {
|
|
|
|
gap = gd->sy / 4;
|
|
|
|
if (py < gd->sy) {
|
|
|
|
offset = 0;
|
|
|
|
data->cy = py;
|
|
|
|
} else if (py > gd->hsize + gd->sy - gap) {
|
|
|
|
offset = gd->hsize;
|
|
|
|
data->cy = py - gd->hsize;
|
|
|
|
} else {
|
|
|
|
offset = py + gap - gd->sy;
|
|
|
|
data->cy = py - offset;
|
|
|
|
}
|
|
|
|
data->oy = gd->hsize - offset;
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 20:41:57 +00:00
|
|
|
if (!no_redraw && data->searchmark != NULL && !data->timeout)
|
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2020-06-04 20:41:57 +00:00
|
|
|
if (!no_redraw)
|
|
|
|
window_copy_redraw_screen(wme);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2014-11-06 09:17:25 +00:00
|
|
|
window_copy_search_compare(struct grid *gd, u_int px, u_int py,
|
|
|
|
struct grid *sgd, u_int spx, int cis)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc, sgc;
|
|
|
|
const struct utf8_data *ud, *sud;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(gd, px, py, &gc);
|
|
|
|
ud = &gc.data;
|
|
|
|
grid_get_cell(sgd, spx, 0, &sgc);
|
|
|
|
sud = &sgc.data;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
if (ud->size != sud->size || ud->width != sud->width)
|
2009-08-18 07:08:26 +00:00
|
|
|
return (0);
|
2013-11-09 00:48:57 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
if (cis && ud->size == 1)
|
|
|
|
return (tolower(ud->data[0]) == sud->data[0]);
|
2013-11-09 00:48:57 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
return (memcmp(ud->data, sud->data, ud->size) == 0);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2020-08-05 09:11:09 +00:00
|
|
|
window_copy_search_lr(struct grid *gd, struct grid *sgd, u_int *ppx, u_int py,
|
|
|
|
u_int first, u_int last, int cis)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2019-12-11 18:30:29 +00:00
|
|
|
u_int ax, bx, px, pywrap, endline;
|
|
|
|
int matched;
|
|
|
|
struct grid_line *gl;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2019-12-11 18:23:34 +00:00
|
|
|
endline = gd->hsize + gd->sy - 1;
|
2009-08-18 07:08:26 +00:00
|
|
|
for (ax = first; ax < last; ax++) {
|
|
|
|
for (bx = 0; bx < sgd->sx; bx++) {
|
|
|
|
px = ax + bx;
|
2019-12-11 18:23:34 +00:00
|
|
|
pywrap = py;
|
|
|
|
/* Wrap line. */
|
|
|
|
while (px >= gd->sx && pywrap < endline) {
|
2019-12-11 18:30:29 +00:00
|
|
|
gl = grid_get_line(gd, pywrap);
|
|
|
|
if (~gl->flags & GRID_LINE_WRAPPED)
|
|
|
|
break;
|
2019-12-11 18:23:34 +00:00
|
|
|
px -= gd->sx;
|
|
|
|
pywrap++;
|
|
|
|
}
|
|
|
|
/* We have run off the end of the grid. */
|
|
|
|
if (px >= gd->sx)
|
|
|
|
break;
|
|
|
|
matched = window_copy_search_compare(gd, px, pywrap,
|
|
|
|
sgd, bx, cis);
|
2013-11-09 00:48:57 +00:00
|
|
|
if (!matched)
|
2009-08-18 07:08:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bx == sgd->sx) {
|
|
|
|
*ppx = ax;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2009-08-18 07:08:26 +00:00
|
|
|
window_copy_search_rl(struct grid *gd,
|
2013-11-09 00:48:57 +00:00
|
|
|
struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last, int cis)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2019-12-11 18:30:29 +00:00
|
|
|
u_int ax, bx, px, pywrap, endline;
|
|
|
|
int matched;
|
|
|
|
struct grid_line *gl;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2019-12-11 18:23:34 +00:00
|
|
|
endline = gd->hsize + gd->sy - 1;
|
|
|
|
for (ax = last; ax > first; ax--) {
|
2009-08-18 07:08:26 +00:00
|
|
|
for (bx = 0; bx < sgd->sx; bx++) {
|
|
|
|
px = ax - 1 + bx;
|
2019-12-11 18:23:34 +00:00
|
|
|
pywrap = py;
|
|
|
|
/* Wrap line. */
|
|
|
|
while (px >= gd->sx && pywrap < endline) {
|
2019-12-11 18:30:29 +00:00
|
|
|
gl = grid_get_line(gd, pywrap);
|
|
|
|
if (~gl->flags & GRID_LINE_WRAPPED)
|
|
|
|
break;
|
2019-12-11 18:23:34 +00:00
|
|
|
px -= gd->sx;
|
|
|
|
pywrap++;
|
|
|
|
}
|
|
|
|
/* We have run off the end of the grid. */
|
|
|
|
if (px >= gd->sx)
|
|
|
|
break;
|
|
|
|
matched = window_copy_search_compare(gd, px, pywrap,
|
|
|
|
sgd, bx, cis);
|
2013-11-09 00:48:57 +00:00
|
|
|
if (!matched)
|
2009-08-18 07:08:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bx == sgd->sx) {
|
|
|
|
*ppx = ax - 1;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2019-12-27 18:42:49 +00:00
|
|
|
static int
|
2020-04-01 07:35:10 +00:00
|
|
|
window_copy_search_lr_regex(struct grid *gd, u_int *ppx, u_int *psx, u_int py,
|
|
|
|
u_int first, u_int last, regex_t *reg)
|
2019-12-27 18:42:49 +00:00
|
|
|
{
|
2020-04-01 07:35:10 +00:00
|
|
|
int eflags = 0;
|
2019-12-27 18:42:49 +00:00
|
|
|
u_int endline, foundx, foundy, len, pywrap, size = 1;
|
2020-04-01 07:35:10 +00:00
|
|
|
char *buf;
|
2019-12-27 18:42:49 +00:00
|
|
|
regmatch_t regmatch;
|
|
|
|
struct grid_line *gl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This can happen during search if the last match was the last
|
|
|
|
* character on a line.
|
|
|
|
*/
|
|
|
|
if (first >= last)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Set flags for regex search. */
|
|
|
|
if (first != 0)
|
|
|
|
eflags |= REG_NOTBOL;
|
|
|
|
|
|
|
|
/* Need to look at the entire string. */
|
|
|
|
buf = xmalloc(size);
|
|
|
|
buf[0] = '\0';
|
|
|
|
buf = window_copy_stringify(gd, py, first, gd->sx, buf, &size);
|
|
|
|
len = gd->sx - first;
|
|
|
|
endline = gd->hsize + gd->sy - 1;
|
|
|
|
pywrap = py;
|
|
|
|
while (buf != NULL && pywrap <= endline) {
|
|
|
|
gl = grid_get_line(gd, pywrap);
|
|
|
|
if (~gl->flags & GRID_LINE_WRAPPED)
|
|
|
|
break;
|
|
|
|
pywrap++;
|
|
|
|
buf = window_copy_stringify(gd, pywrap, 0, gd->sx, buf, &size);
|
|
|
|
len += gd->sx;
|
|
|
|
}
|
|
|
|
|
2020-05-16 16:03:57 +00:00
|
|
|
if (regexec(reg, buf, 1, ®match, eflags) == 0 &&
|
|
|
|
regmatch.rm_so != regmatch.rm_eo) {
|
2019-12-27 18:42:49 +00:00
|
|
|
foundx = first;
|
|
|
|
foundy = py;
|
|
|
|
window_copy_cstrtocellpos(gd, len, &foundx, &foundy,
|
|
|
|
buf + regmatch.rm_so);
|
|
|
|
if (foundy == py && foundx < last) {
|
|
|
|
*ppx = foundx;
|
|
|
|
len -= foundx - first;
|
|
|
|
window_copy_cstrtocellpos(gd, len, &foundx, &foundy,
|
|
|
|
buf + regmatch.rm_eo);
|
|
|
|
*psx = foundx;
|
|
|
|
while (foundy > py) {
|
|
|
|
*psx += gd->sx;
|
|
|
|
foundy--;
|
|
|
|
}
|
|
|
|
*psx -= *ppx;
|
|
|
|
free(buf);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
*ppx = 0;
|
|
|
|
*psx = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-04-01 07:35:10 +00:00
|
|
|
window_copy_search_rl_regex(struct grid *gd, u_int *ppx, u_int *psx, u_int py,
|
|
|
|
u_int first, u_int last, regex_t *reg)
|
2019-12-27 18:42:49 +00:00
|
|
|
{
|
2020-04-01 07:35:10 +00:00
|
|
|
int eflags = 0;
|
|
|
|
u_int endline, len, pywrap, size = 1;
|
|
|
|
char *buf;
|
2019-12-27 18:42:49 +00:00
|
|
|
struct grid_line *gl;
|
|
|
|
|
|
|
|
/* Set flags for regex search. */
|
|
|
|
if (first != 0)
|
|
|
|
eflags |= REG_NOTBOL;
|
|
|
|
|
|
|
|
/* Need to look at the entire string. */
|
|
|
|
buf = xmalloc(size);
|
|
|
|
buf[0] = '\0';
|
|
|
|
buf = window_copy_stringify(gd, py, first, gd->sx, buf, &size);
|
|
|
|
len = gd->sx - first;
|
|
|
|
endline = gd->hsize + gd->sy - 1;
|
|
|
|
pywrap = py;
|
|
|
|
while (buf != NULL && (pywrap <= endline)) {
|
|
|
|
gl = grid_get_line(gd, pywrap);
|
|
|
|
if (~gl->flags & GRID_LINE_WRAPPED)
|
|
|
|
break;
|
|
|
|
pywrap++;
|
|
|
|
buf = window_copy_stringify(gd, pywrap, 0, gd->sx, buf, &size);
|
|
|
|
len += gd->sx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_copy_last_regex(gd, py, first, last, len, ppx, psx, buf,
|
2020-04-01 07:35:10 +00:00
|
|
|
reg, eflags))
|
2019-12-27 18:42:49 +00:00
|
|
|
{
|
|
|
|
free(buf);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
*ppx = 0;
|
|
|
|
*psx = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2020-04-01 07:35:10 +00:00
|
|
|
static const char *
|
2020-05-25 09:32:10 +00:00
|
|
|
window_copy_cellstring(const struct grid_line *gl, u_int px, size_t *size,
|
|
|
|
int *allocated)
|
2020-04-01 07:35:10 +00:00
|
|
|
{
|
2020-05-25 09:32:10 +00:00
|
|
|
static struct utf8_data ud;
|
2020-04-01 07:35:10 +00:00
|
|
|
struct grid_cell_entry *gce;
|
2020-05-25 09:32:10 +00:00
|
|
|
char *copy;
|
2020-04-01 07:35:10 +00:00
|
|
|
|
|
|
|
if (px >= gl->cellsize) {
|
|
|
|
*size = 1;
|
2020-05-25 09:32:10 +00:00
|
|
|
*allocated = 0;
|
2020-04-01 07:35:10 +00:00
|
|
|
return (" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
gce = &gl->celldata[px];
|
2020-07-15 10:09:54 +00:00
|
|
|
if (gce->flags & GRID_FLAG_PADDING) {
|
|
|
|
*size = 0;
|
|
|
|
*allocated = 0;
|
|
|
|
return (NULL);
|
|
|
|
}
|
2020-04-01 07:35:10 +00:00
|
|
|
if (~gce->flags & GRID_FLAG_EXTENDED) {
|
|
|
|
*size = 1;
|
2020-05-25 09:32:10 +00:00
|
|
|
*allocated = 0;
|
2020-04-01 07:35:10 +00:00
|
|
|
return (&gce->data.data);
|
|
|
|
}
|
|
|
|
|
2020-05-25 18:19:29 +00:00
|
|
|
utf8_to_data(gl->extddata[gce->offset].data, &ud);
|
2020-05-25 09:32:10 +00:00
|
|
|
*size = ud.size;
|
|
|
|
*allocated = 1;
|
|
|
|
|
|
|
|
copy = xmalloc(ud.size);
|
|
|
|
memcpy(copy, ud.data, ud.size);
|
|
|
|
return (copy);
|
2020-04-01 07:35:10 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 18:42:49 +00:00
|
|
|
/* Find last match in given range. */
|
|
|
|
static int
|
|
|
|
window_copy_last_regex(struct grid *gd, u_int py, u_int first, u_int last,
|
|
|
|
u_int len, u_int *ppx, u_int *psx, const char *buf, const regex_t *preg,
|
|
|
|
int eflags)
|
|
|
|
{
|
|
|
|
u_int foundx, foundy, oldx, px = 0, savepx, savesx = 0;
|
|
|
|
regmatch_t regmatch;
|
|
|
|
|
|
|
|
foundx = first;
|
|
|
|
foundy = py;
|
|
|
|
oldx = first;
|
|
|
|
while (regexec(preg, buf + px, 1, ®match, eflags) == 0) {
|
2020-05-16 16:03:57 +00:00
|
|
|
if (regmatch.rm_so == regmatch.rm_eo)
|
|
|
|
break;
|
2019-12-27 18:42:49 +00:00
|
|
|
window_copy_cstrtocellpos(gd, len, &foundx, &foundy,
|
|
|
|
buf + px + regmatch.rm_so);
|
|
|
|
if (foundy > py || foundx >= last)
|
|
|
|
break;
|
|
|
|
len -= foundx - oldx;
|
|
|
|
savepx = foundx;
|
|
|
|
window_copy_cstrtocellpos(gd, len, &foundx, &foundy,
|
|
|
|
buf + px + regmatch.rm_eo);
|
|
|
|
if (foundy > py || foundx >= last) {
|
|
|
|
*ppx = savepx;
|
|
|
|
*psx = foundx;
|
|
|
|
while (foundy > py) {
|
|
|
|
*psx += gd->sx;
|
|
|
|
foundy--;
|
|
|
|
}
|
|
|
|
*psx -= *ppx;
|
|
|
|
return (1);
|
|
|
|
} else {
|
|
|
|
savesx = foundx - savepx;
|
|
|
|
len -= savesx;
|
|
|
|
oldx = foundx;
|
|
|
|
}
|
|
|
|
px += regmatch.rm_eo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (savesx > 0) {
|
|
|
|
*ppx = savepx;
|
|
|
|
*psx = savesx;
|
|
|
|
return (1);
|
|
|
|
} else {
|
|
|
|
*ppx = 0;
|
|
|
|
*psx = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stringify line and append to input buffer. Caller frees. */
|
|
|
|
static char *
|
|
|
|
window_copy_stringify(struct grid *gd, u_int py, u_int first, u_int last,
|
|
|
|
char *buf, u_int *size)
|
|
|
|
{
|
2020-04-01 07:35:10 +00:00
|
|
|
u_int ax, bx, newsize = *size;
|
|
|
|
const struct grid_line *gl;
|
|
|
|
const char *d;
|
|
|
|
size_t bufsize = 1024, dlen;
|
2020-05-25 09:32:10 +00:00
|
|
|
int allocated;
|
2019-12-27 18:42:49 +00:00
|
|
|
|
2020-04-01 07:35:10 +00:00
|
|
|
while (bufsize < newsize)
|
|
|
|
bufsize *= 2;
|
|
|
|
buf = xrealloc(buf, bufsize);
|
|
|
|
|
|
|
|
gl = grid_peek_line(gd, py);
|
2019-12-27 18:42:49 +00:00
|
|
|
bx = *size - 1;
|
|
|
|
for (ax = first; ax < last; ax++) {
|
2020-05-25 09:32:10 +00:00
|
|
|
d = window_copy_cellstring(gl, ax, &dlen, &allocated);
|
2020-04-01 07:35:10 +00:00
|
|
|
newsize += dlen;
|
|
|
|
while (bufsize < newsize) {
|
|
|
|
bufsize *= 2;
|
|
|
|
buf = xrealloc(buf, bufsize);
|
|
|
|
}
|
|
|
|
if (dlen == 1)
|
|
|
|
buf[bx++] = *d;
|
|
|
|
else {
|
|
|
|
memcpy(buf + bx, d, dlen);
|
|
|
|
bx += dlen;
|
|
|
|
}
|
2020-05-25 09:32:10 +00:00
|
|
|
if (allocated)
|
|
|
|
free((void *)d);
|
2019-12-27 18:42:49 +00:00
|
|
|
}
|
|
|
|
buf[newsize - 1] = '\0';
|
2020-04-01 07:35:10 +00:00
|
|
|
|
2019-12-27 18:42:49 +00:00
|
|
|
*size = newsize;
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map start of C string containing UTF-8 data to grid cell position. */
|
|
|
|
static void
|
|
|
|
window_copy_cstrtocellpos(struct grid *gd, u_int ncells, u_int *ppx, u_int *ppy,
|
|
|
|
const char *str)
|
|
|
|
{
|
2020-04-01 07:35:10 +00:00
|
|
|
u_int cell, ccell, px, pywrap, pos, len;
|
|
|
|
int match;
|
|
|
|
const struct grid_line *gl;
|
|
|
|
const char *d;
|
|
|
|
size_t dlen;
|
|
|
|
struct {
|
|
|
|
const char *d;
|
|
|
|
size_t dlen;
|
2020-05-25 09:32:10 +00:00
|
|
|
int allocated;
|
2020-04-01 07:35:10 +00:00
|
|
|
} *cells;
|
2019-12-27 18:42:49 +00:00
|
|
|
|
|
|
|
/* Populate the array of cell data. */
|
2020-04-01 07:35:10 +00:00
|
|
|
cells = xreallocarray(NULL, ncells, sizeof cells[0]);
|
2019-12-27 18:42:49 +00:00
|
|
|
cell = 0;
|
|
|
|
px = *ppx;
|
|
|
|
pywrap = *ppy;
|
2020-04-01 07:35:10 +00:00
|
|
|
gl = grid_peek_line(gd, pywrap);
|
2019-12-27 18:42:49 +00:00
|
|
|
while (cell < ncells) {
|
2020-04-01 07:35:10 +00:00
|
|
|
cells[cell].d = window_copy_cellstring(gl, px,
|
2020-05-25 09:32:10 +00:00
|
|
|
&cells[cell].dlen, &cells[cell].allocated);
|
2019-12-27 18:42:49 +00:00
|
|
|
cell++;
|
2020-04-01 07:52:07 +00:00
|
|
|
px++;
|
|
|
|
if (px == gd->sx) {
|
|
|
|
px = 0;
|
2019-12-27 18:42:49 +00:00
|
|
|
pywrap++;
|
2020-04-01 07:35:10 +00:00
|
|
|
gl = grid_peek_line(gd, pywrap);
|
|
|
|
}
|
2019-12-27 18:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Locate starting cell. */
|
|
|
|
cell = 0;
|
2020-04-01 07:35:10 +00:00
|
|
|
len = strlen(str);
|
2019-12-27 18:42:49 +00:00
|
|
|
while (cell < ncells) {
|
|
|
|
ccell = cell;
|
2020-04-01 07:35:10 +00:00
|
|
|
pos = 0;
|
2019-12-27 18:42:49 +00:00
|
|
|
match = 1;
|
|
|
|
while (ccell < ncells) {
|
2020-04-01 07:35:10 +00:00
|
|
|
if (str[pos] == '\0') {
|
2019-12-27 18:42:49 +00:00
|
|
|
match = 0;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-01 07:35:10 +00:00
|
|
|
d = cells[ccell].d;
|
|
|
|
dlen = cells[ccell].dlen;
|
|
|
|
if (dlen == 1) {
|
|
|
|
if (str[pos] != *d) {
|
|
|
|
match = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
} else {
|
|
|
|
if (dlen > len - pos)
|
|
|
|
dlen = len - pos;
|
|
|
|
if (memcmp(str + pos, d, dlen) != 0) {
|
2019-12-27 18:42:49 +00:00
|
|
|
match = 0;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-01 07:35:10 +00:00
|
|
|
pos += dlen;
|
2019-12-27 18:42:49 +00:00
|
|
|
}
|
|
|
|
ccell++;
|
|
|
|
}
|
|
|
|
if (match)
|
|
|
|
break;
|
|
|
|
cell++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If not found this will be one past the end. */
|
|
|
|
px = *ppx + cell;
|
|
|
|
pywrap = *ppy;
|
|
|
|
while (px >= gd->sx) {
|
|
|
|
px -= gd->sx;
|
|
|
|
pywrap++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppx = px;
|
|
|
|
*ppy = pywrap;
|
|
|
|
|
|
|
|
/* Free cell data. */
|
2020-05-25 09:32:10 +00:00
|
|
|
for (cell = 0; cell < ncells; cell++) {
|
|
|
|
if (cells[cell].allocated)
|
|
|
|
free((void *)cells[cell].d);
|
|
|
|
}
|
2019-12-27 18:42:49 +00:00
|
|
|
free(cells);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-08-01 14:31:39 +00:00
|
|
|
window_copy_move_left(struct screen *s, u_int *fx, u_int *fy, int wrapflag)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2016-05-03 13:40:50 +00:00
|
|
|
if (*fx == 0) { /* left */
|
2019-08-01 14:31:39 +00:00
|
|
|
if (*fy == 0) { /* top */
|
|
|
|
if (wrapflag) {
|
|
|
|
*fx = screen_size_x(s) - 1;
|
2019-12-11 18:23:34 +00:00
|
|
|
*fy = screen_hsize(s) + screen_size_y(s) - 1;
|
2019-08-01 14:31:39 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
return;
|
2019-08-01 14:31:39 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
*fx = screen_size_x(s) - 1;
|
|
|
|
*fy = *fy - 1;
|
|
|
|
} else
|
|
|
|
*fx = *fx - 1;
|
|
|
|
}
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2021-04-01 06:46:12 +00:00
|
|
|
static void
|
|
|
|
window_copy_move_right(struct screen *s, u_int *fx, u_int *fy, int wrapflag)
|
|
|
|
{
|
|
|
|
if (*fx == screen_size_x(s) - 1) { /* right */
|
|
|
|
if (*fy == screen_hsize(s) + screen_size_y(s) - 1) { /* bottom */
|
|
|
|
if (wrapflag) {
|
|
|
|
*fx = 0;
|
|
|
|
*fy = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*fx = 0;
|
|
|
|
*fy = *fy + 1;
|
|
|
|
} else
|
|
|
|
*fx = *fx + 1;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2016-05-03 13:40:50 +00:00
|
|
|
window_copy_is_lowercase(const char *ptr)
|
|
|
|
{
|
|
|
|
while (*ptr != '\0') {
|
|
|
|
if (*ptr != tolower((u_char)*ptr))
|
|
|
|
return (0);
|
|
|
|
++ptr;
|
2013-11-09 00:48:57 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2013-11-09 00:48:57 +00:00
|
|
|
|
2021-02-22 08:31:19 +00:00
|
|
|
/*
|
|
|
|
* Handle backward wrapped regex searches with overlapping matches. In this case
|
|
|
|
* find the longest overlapping match from previous wrapped lines.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
window_copy_search_back_overlap(struct grid *gd, regex_t *preg, u_int *ppx,
|
|
|
|
u_int *psx, u_int *ppy, u_int endline)
|
|
|
|
{
|
|
|
|
u_int endx, endy, oldendx, oldendy, px, py, sx;
|
|
|
|
int found = 1;
|
|
|
|
|
|
|
|
oldendx = *ppx + *psx;
|
|
|
|
oldendy = *ppy - 1;
|
|
|
|
while (oldendx > gd->sx - 1) {
|
|
|
|
oldendx -= gd->sx;
|
|
|
|
oldendy++;
|
|
|
|
}
|
|
|
|
endx = oldendx;
|
|
|
|
endy = oldendy;
|
|
|
|
px = *ppx;
|
|
|
|
py = *ppy;
|
|
|
|
while (found && px == 0 && py - 1 > endline &&
|
|
|
|
grid_get_line(gd, py - 2)->flags & GRID_LINE_WRAPPED &&
|
|
|
|
endx == oldendx && endy == oldendy) {
|
|
|
|
py--;
|
|
|
|
found = window_copy_search_rl_regex(gd, &px, &sx, py - 1, 0,
|
|
|
|
gd->sx, preg);
|
|
|
|
if (found) {
|
|
|
|
endx = px + sx;
|
|
|
|
endy = py - 1;
|
|
|
|
while (endx > gd->sx - 1) {
|
|
|
|
endx -= gd->sx;
|
|
|
|
endy++;
|
|
|
|
}
|
|
|
|
if (endx == oldendx && endy == oldendy) {
|
|
|
|
*ppx = px;
|
|
|
|
*ppy = py;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 13:40:50 +00:00
|
|
|
/*
|
|
|
|
* Search for text stored in sgd starting from position fx,fy up to endline. If
|
|
|
|
* found, jump to it. If cis then ignore case. The direction is 0 for searching
|
|
|
|
* up, down otherwise. If wrap then go to begin/end of grid and try again if
|
|
|
|
* not found.
|
|
|
|
*/
|
2017-01-06 11:57:03 +00:00
|
|
|
static int
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
|
2016-05-03 13:40:50 +00:00
|
|
|
struct grid *sgd, u_int fx, u_int fy, u_int endline, int cis, int wrap,
|
2021-04-01 06:46:12 +00:00
|
|
|
int direction, int regex)
|
2016-05-03 13:40:50 +00:00
|
|
|
{
|
2020-04-01 07:35:10 +00:00
|
|
|
u_int i, px, sx, ssize = 1;
|
|
|
|
int found = 0, cflags = REG_EXTENDED;
|
|
|
|
char *sbuf;
|
|
|
|
regex_t reg;
|
|
|
|
|
|
|
|
if (regex) {
|
|
|
|
sbuf = xmalloc(ssize);
|
|
|
|
sbuf[0] = '\0';
|
|
|
|
sbuf = window_copy_stringify(sgd, 0, 0, sgd->sx, sbuf, &ssize);
|
|
|
|
if (cis)
|
|
|
|
cflags |= REG_ICASE;
|
|
|
|
if (regcomp(®, sbuf, cflags) != 0) {
|
|
|
|
free(sbuf);
|
|
|
|
return (0);
|
|
|
|
}
|
2020-09-18 11:23:29 +00:00
|
|
|
free(sbuf);
|
2020-04-01 07:35:10 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
|
|
|
|
if (direction) {
|
|
|
|
for (i = fy; i <= endline; i++) {
|
2020-04-01 07:35:10 +00:00
|
|
|
if (regex) {
|
|
|
|
found = window_copy_search_lr_regex(gd,
|
|
|
|
&px, &sx, i, fx, gd->sx, ®);
|
|
|
|
} else {
|
2019-12-27 18:42:49 +00:00
|
|
|
found = window_copy_search_lr(gd, sgd,
|
|
|
|
&px, i, fx, gd->sx, cis);
|
2020-04-01 07:35:10 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
fx = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = fy + 1; endline < i; i--) {
|
2020-04-01 07:35:10 +00:00
|
|
|
if (regex) {
|
|
|
|
found = window_copy_search_rl_regex(gd,
|
|
|
|
&px, &sx, i - 1, 0, fx + 1, ®);
|
2021-02-22 08:31:19 +00:00
|
|
|
if (found) {
|
|
|
|
window_copy_search_back_overlap(gd,
|
|
|
|
®, &px, &sx, &i, endline);
|
|
|
|
}
|
2020-04-01 07:35:10 +00:00
|
|
|
} else {
|
2019-12-27 18:42:49 +00:00
|
|
|
found = window_copy_search_rl(gd, sgd,
|
|
|
|
&px, i - 1, 0, fx + 1, cis);
|
2020-04-01 07:35:10 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
if (found) {
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
2019-12-11 18:23:34 +00:00
|
|
|
fx = gd->sx - 1;
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-18 11:23:29 +00:00
|
|
|
if (regex)
|
2020-04-01 07:35:10 +00:00
|
|
|
regfree(®);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2017-01-06 11:57:03 +00:00
|
|
|
if (found) {
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_scroll_to(wme, px, i, 1);
|
2017-01-06 11:57:03 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (wrap) {
|
2019-03-07 20:24:21 +00:00
|
|
|
return (window_copy_search_jump(wme, gd, sgd,
|
2017-01-06 11:57:03 +00:00
|
|
|
direction ? 0 : gd->sx - 1,
|
2016-05-03 13:40:50 +00:00
|
|
|
direction ? 0 : gd->hsize + gd->sy - 1, fy, cis, 0,
|
2021-04-01 06:46:12 +00:00
|
|
|
direction, regex));
|
2016-05-03 13:40:50 +00:00
|
|
|
}
|
2017-01-06 11:57:03 +00:00
|
|
|
return (0);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 06:46:12 +00:00
|
|
|
static void
|
|
|
|
window_copy_move_after_search_mark(struct window_copy_mode_data *data,
|
|
|
|
u_int *fx, u_int *fy, int wrapflag)
|
|
|
|
{
|
|
|
|
struct screen *s = data->backing;
|
|
|
|
u_int at, start;
|
|
|
|
|
|
|
|
if (window_copy_search_mark_at(data, *fx, *fy, &start) == 0 &&
|
|
|
|
data->searchmark[start] != 0) {
|
|
|
|
while (window_copy_search_mark_at(data, *fx, *fy, &at) == 0) {
|
|
|
|
if (data->searchmark[at] != data->searchmark[start])
|
|
|
|
break;
|
|
|
|
/* Stop if not wrapping and at the end of the grid. */
|
|
|
|
if (!wrapflag &&
|
|
|
|
*fx == screen_size_x(s) - 1 &&
|
|
|
|
*fy == screen_hsize(s) + screen_size_y(s) - 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
window_copy_move_right(s, fx, fy, wrapflag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 13:40:50 +00:00
|
|
|
/*
|
|
|
|
* Search in for text searchstr. If direction is 0 then search up, otherwise
|
2017-09-13 07:31:07 +00:00
|
|
|
* down.
|
2016-05-03 13:40:50 +00:00
|
|
|
*/
|
2017-01-06 11:57:03 +00:00
|
|
|
static int
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search(struct window_mode_entry *wme, int direction, int regex)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *s = data->backing, ss;
|
2009-08-18 07:08:26 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2016-05-03 13:40:50 +00:00
|
|
|
struct grid *gd = s->grid;
|
2020-04-01 08:07:05 +00:00
|
|
|
const char *str = data->searchstr;
|
2021-04-01 06:46:12 +00:00
|
|
|
u_int at, endline, fx, fy, start;
|
|
|
|
int cis, found, keys, visible_only;
|
|
|
|
int wrapflag;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2020-04-01 08:07:05 +00:00
|
|
|
if (regex && str[strcspn(str, "^$*+()?[].\\")] == '\0')
|
|
|
|
regex = 0;
|
|
|
|
|
2021-04-01 06:46:12 +00:00
|
|
|
data->searchdirection = direction;
|
|
|
|
|
2020-04-01 09:36:37 +00:00
|
|
|
if (data->timeout)
|
|
|
|
return (0);
|
|
|
|
|
2020-12-28 09:36:26 +00:00
|
|
|
if (data->searchall || wp->searchstr == NULL ||
|
|
|
|
wp->searchregex != regex) {
|
2020-06-04 20:41:57 +00:00
|
|
|
visible_only = 0;
|
2020-12-28 09:36:26 +00:00
|
|
|
data->searchall = 0;
|
|
|
|
} else
|
2020-06-04 20:41:57 +00:00
|
|
|
visible_only = (strcmp(wp->searchstr, str) == 0);
|
2017-05-12 10:45:38 +00:00
|
|
|
free(wp->searchstr);
|
2020-04-01 08:07:05 +00:00
|
|
|
wp->searchstr = xstrdup(str);
|
2020-03-31 16:53:23 +00:00
|
|
|
wp->searchregex = regex;
|
2017-05-12 10:45:38 +00:00
|
|
|
|
2009-08-18 07:08:26 +00:00
|
|
|
fx = data->cx;
|
2016-05-03 13:40:50 +00:00
|
|
|
fy = screen_hsize(data->backing) - data->oy + data->cy;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2020-04-01 08:07:05 +00:00
|
|
|
screen_init(&ss, screen_write_strlen("%s", str), 1, 0);
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start(&ctx, &ss);
|
2020-04-01 08:07:05 +00:00
|
|
|
screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", str);
|
2016-05-03 13:40:50 +00:00
|
|
|
screen_write_stop(&ctx);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2016-05-03 13:40:50 +00:00
|
|
|
wrapflag = options_get_number(wp->window->options, "wrap-search");
|
2020-04-01 08:07:05 +00:00
|
|
|
cis = window_copy_is_lowercase(str);
|
2016-05-03 13:40:50 +00:00
|
|
|
|
2021-04-01 06:46:12 +00:00
|
|
|
keys = options_get_number(wp->window->options, "mode-keys");
|
|
|
|
|
|
|
|
if (direction) {
|
|
|
|
/*
|
|
|
|
* Behave according to mode-keys. If it is emacs, search forward
|
|
|
|
* leaves the cursor after the match. If it is vi, the cursor
|
|
|
|
* remains at the beginning of the match, regardless of
|
|
|
|
* direction, which means that we need to start the next search
|
|
|
|
* after the term the cursor is currently on when searching
|
|
|
|
* forward.
|
|
|
|
*/
|
|
|
|
if (keys == MODEKEY_VI) {
|
|
|
|
if (data->searchmark != NULL)
|
|
|
|
window_copy_move_after_search_mark(data, &fx,
|
|
|
|
&fy, wrapflag);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* When there are no search marks, start the
|
|
|
|
* search after the current cursor position.
|
|
|
|
*/
|
|
|
|
window_copy_move_right(s, &fx, &fy, wrapflag);
|
|
|
|
}
|
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
endline = gd->hsize + gd->sy - 1;
|
2021-04-01 06:46:12 +00:00
|
|
|
}
|
2020-08-05 09:11:09 +00:00
|
|
|
else {
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_move_left(s, &fx, &fy, wrapflag);
|
2016-05-03 13:40:50 +00:00
|
|
|
endline = 0;
|
2019-08-01 14:31:39 +00:00
|
|
|
}
|
2019-12-27 18:42:49 +00:00
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
found = window_copy_search_jump(wme, gd, ss.grid, fx, fy, endline, cis,
|
2021-04-01 06:46:12 +00:00
|
|
|
wrapflag, direction, regex);
|
2020-08-05 09:11:09 +00:00
|
|
|
if (found) {
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, &ss, regex, visible_only);
|
2021-04-01 06:46:12 +00:00
|
|
|
fx = data->cx;
|
|
|
|
fy = screen_hsize(data->backing) - data->oy + data->cy;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When searching forward, if the cursor is not at the beginning
|
|
|
|
* of the mark, search again.
|
|
|
|
*/
|
|
|
|
if (direction &&
|
|
|
|
window_copy_search_mark_at(data, fx, fy, &at) == 0 &&
|
|
|
|
at > 0 &&
|
|
|
|
data->searchmark[at] == data->searchmark[at - 1]) {
|
|
|
|
window_copy_move_after_search_mark(data, &fx, &fy,
|
|
|
|
wrapflag);
|
|
|
|
window_copy_search_jump(wme, gd, ss.grid, fx,
|
|
|
|
fy, endline, cis, wrapflag, direction,
|
|
|
|
regex);
|
|
|
|
fx = data->cx;
|
|
|
|
fy = screen_hsize(data->backing) - data->oy + data->cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (direction) {
|
|
|
|
/*
|
|
|
|
* When in Emacs mode, position the cursor just after
|
|
|
|
* the mark.
|
|
|
|
*/
|
|
|
|
if (keys == MODEKEY_EMACS) {
|
|
|
|
window_copy_move_after_search_mark(data, &fx,
|
|
|
|
&fy, wrapflag);
|
|
|
|
data->cx = fx;
|
|
|
|
data->cy = fy - screen_hsize(data->backing) +
|
|
|
|
data-> oy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* When searching backward, position the cursor at the
|
|
|
|
* beginning of the mark.
|
|
|
|
*/
|
|
|
|
if (window_copy_search_mark_at(data, fx, fy,
|
|
|
|
&start) == 0) {
|
|
|
|
while (window_copy_search_mark_at(data, fx, fy,
|
|
|
|
&at) == 0 &&
|
|
|
|
data->searchmark[at] ==
|
|
|
|
data->searchmark[start]) {
|
|
|
|
data->cx = fx;
|
|
|
|
data->cy = fy -
|
|
|
|
screen_hsize(data->backing) +
|
|
|
|
data-> oy;
|
|
|
|
if (at == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
window_copy_move_left(s, &fx, &fy, 0);
|
|
|
|
}
|
2021-02-22 08:31:19 +00:00
|
|
|
}
|
2020-08-05 09:11:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
|
|
|
screen_free(&ss);
|
2017-01-06 11:57:03 +00:00
|
|
|
return (found);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 20:41:57 +00:00
|
|
|
static void
|
|
|
|
window_copy_visible_lines(struct window_copy_mode_data *data, u_int *start,
|
|
|
|
u_int *end)
|
|
|
|
{
|
|
|
|
struct grid *gd = data->backing->grid;
|
|
|
|
const struct grid_line *gl;
|
|
|
|
|
|
|
|
for (*start = gd->hsize - data->oy; *start > 0; (*start)--) {
|
|
|
|
gl = grid_peek_line(gd, (*start) - 1);
|
|
|
|
if (~gl->flags & GRID_LINE_WRAPPED)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*end = gd->hsize - data->oy + gd->sy;
|
|
|
|
}
|
|
|
|
|
2020-06-04 21:40:27 +00:00
|
|
|
static int
|
2020-08-05 09:11:09 +00:00
|
|
|
window_copy_search_mark_at(struct window_copy_mode_data *data, u_int px,
|
|
|
|
u_int py, u_int *at)
|
2020-06-04 21:40:27 +00:00
|
|
|
{
|
|
|
|
struct screen *s = data->backing;
|
|
|
|
struct grid *gd = s->grid;
|
|
|
|
|
|
|
|
if (py < gd->hsize - data->oy)
|
|
|
|
return (-1);
|
|
|
|
if (py > gd->hsize - data->oy + gd->sy - 1)
|
|
|
|
return (-1);
|
|
|
|
*at = ((py - (gd->hsize - data->oy)) * gd->sx) + px;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
static int
|
2019-12-27 18:42:49 +00:00
|
|
|
window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
|
2020-06-04 20:41:57 +00:00
|
|
|
int regex, int visible_only)
|
2017-01-05 09:07:15 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2017-01-05 09:07:15 +00:00
|
|
|
struct screen *s = data->backing, ss;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
struct grid *gd = s->grid;
|
2021-01-06 07:29:49 +00:00
|
|
|
int found, cis, stopped = 0;
|
2020-04-01 07:35:10 +00:00
|
|
|
int cflags = REG_EXTENDED;
|
2020-05-16 15:11:52 +00:00
|
|
|
u_int px, py, i, b, nfound = 0, width;
|
2020-05-16 15:38:14 +00:00
|
|
|
u_int ssize = 1, start, end;
|
2020-04-01 07:35:10 +00:00
|
|
|
char *sbuf;
|
|
|
|
regex_t reg;
|
2020-05-16 15:38:14 +00:00
|
|
|
uint64_t stop = 0, tstart, t;
|
2017-01-05 09:07:15 +00:00
|
|
|
|
|
|
|
if (ssp == NULL) {
|
|
|
|
width = screen_write_strlen("%s", data->searchstr);
|
|
|
|
screen_init(&ss, width, 1, 0);
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start(&ctx, &ss);
|
2017-01-05 09:07:15 +00:00
|
|
|
screen_write_nputs(&ctx, -1, &grid_default_cell, "%s",
|
|
|
|
data->searchstr);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
ssp = &ss;
|
|
|
|
} else
|
|
|
|
width = screen_size_x(ssp);
|
|
|
|
|
|
|
|
cis = window_copy_is_lowercase(data->searchstr);
|
|
|
|
|
2020-04-01 07:35:10 +00:00
|
|
|
if (regex) {
|
|
|
|
sbuf = xmalloc(ssize);
|
|
|
|
sbuf[0] = '\0';
|
|
|
|
sbuf = window_copy_stringify(ssp->grid, 0, 0, ssp->grid->sx,
|
|
|
|
sbuf, &ssize);
|
|
|
|
if (cis)
|
|
|
|
cflags |= REG_ICASE;
|
|
|
|
if (regcomp(®, sbuf, cflags) != 0) {
|
|
|
|
free(sbuf);
|
|
|
|
return (0);
|
|
|
|
}
|
2020-09-18 11:23:29 +00:00
|
|
|
free(sbuf);
|
2020-04-01 07:35:10 +00:00
|
|
|
}
|
2020-06-02 08:17:27 +00:00
|
|
|
tstart = get_timer();
|
2020-05-16 15:38:14 +00:00
|
|
|
|
2020-06-04 20:41:57 +00:00
|
|
|
if (visible_only)
|
|
|
|
window_copy_visible_lines(data, &start, &end);
|
|
|
|
else {
|
|
|
|
start = 0;
|
|
|
|
end = gd->hsize + gd->sy;
|
|
|
|
stop = get_timer() + WINDOW_COPY_SEARCH_ALL_TIMEOUT;
|
|
|
|
}
|
2020-05-16 15:38:14 +00:00
|
|
|
|
|
|
|
again:
|
|
|
|
free(data->searchmark);
|
2020-06-04 21:40:27 +00:00
|
|
|
data->searchmark = xcalloc(gd->sx, gd->sy);
|
2020-05-16 15:38:14 +00:00
|
|
|
data->searchgen = 1;
|
|
|
|
|
|
|
|
for (py = start; py < end; py++) {
|
2017-01-05 09:07:15 +00:00
|
|
|
px = 0;
|
|
|
|
for (;;) {
|
2019-12-27 18:42:49 +00:00
|
|
|
if (regex) {
|
|
|
|
found = window_copy_search_lr_regex(gd,
|
2020-04-01 07:35:10 +00:00
|
|
|
&px, &width, py, px, gd->sx, ®);
|
2019-12-27 18:42:49 +00:00
|
|
|
if (!found)
|
|
|
|
break;
|
2020-04-01 07:35:10 +00:00
|
|
|
} else {
|
2019-12-27 18:42:49 +00:00
|
|
|
found = window_copy_search_lr(gd, ssp->grid,
|
2020-04-01 07:35:10 +00:00
|
|
|
&px, py, px, gd->sx, cis);
|
2019-12-27 18:42:49 +00:00
|
|
|
if (!found)
|
|
|
|
break;
|
|
|
|
}
|
2017-01-05 09:07:15 +00:00
|
|
|
nfound++;
|
|
|
|
|
2020-06-04 21:40:27 +00:00
|
|
|
if (window_copy_search_mark_at(data, px, py, &b) == 0) {
|
|
|
|
if (b + width > gd->sx * gd->sy)
|
|
|
|
width = (gd->sx * gd->sy) - b;
|
2021-02-22 08:31:19 +00:00
|
|
|
for (i = b; i < b + width; i++) {
|
|
|
|
if (data->searchmark[i] != 0)
|
|
|
|
continue;
|
2020-06-04 21:40:27 +00:00
|
|
|
data->searchmark[i] = data->searchgen;
|
2021-02-22 08:31:19 +00:00
|
|
|
}
|
2020-06-04 21:40:27 +00:00
|
|
|
if (data->searchgen == UCHAR_MAX)
|
|
|
|
data->searchgen = 1;
|
|
|
|
else
|
|
|
|
data->searchgen++;
|
|
|
|
}
|
2020-08-05 09:11:09 +00:00
|
|
|
px += width;
|
2017-01-05 09:07:15 +00:00
|
|
|
}
|
2020-04-01 09:36:37 +00:00
|
|
|
|
2020-06-02 08:17:27 +00:00
|
|
|
t = get_timer();
|
2020-04-01 09:36:37 +00:00
|
|
|
if (t - tstart > WINDOW_COPY_SEARCH_TIMEOUT) {
|
|
|
|
data->timeout = 1;
|
|
|
|
break;
|
|
|
|
}
|
2020-05-16 15:38:14 +00:00
|
|
|
if (stop != 0 && t > stop) {
|
|
|
|
stopped = 1;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-01 07:35:10 +00:00
|
|
|
}
|
2020-04-01 09:36:37 +00:00
|
|
|
if (data->timeout) {
|
|
|
|
window_copy_clear_marks(wme);
|
2020-05-16 15:38:14 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stopped && stop != 0) {
|
|
|
|
/* Try again but just the visible context. */
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_visible_lines(data, &start, &end);
|
2020-05-16 15:38:14 +00:00
|
|
|
stop = 0;
|
|
|
|
goto again;
|
2020-04-01 09:36:37 +00:00
|
|
|
}
|
2017-01-05 09:07:15 +00:00
|
|
|
|
2020-06-04 20:41:57 +00:00
|
|
|
if (!visible_only) {
|
|
|
|
if (stopped) {
|
|
|
|
if (nfound > 1000)
|
|
|
|
data->searchcount = 1000;
|
|
|
|
else if (nfound > 100)
|
|
|
|
data->searchcount = 100;
|
|
|
|
else if (nfound > 10)
|
|
|
|
data->searchcount = 10;
|
|
|
|
else
|
|
|
|
data->searchcount = -1;
|
|
|
|
data->searchmore = 1;
|
|
|
|
} else {
|
|
|
|
data->searchcount = nfound;
|
|
|
|
data->searchmore = 0;
|
|
|
|
}
|
2020-05-16 15:38:14 +00:00
|
|
|
}
|
2017-03-24 07:14:27 +00:00
|
|
|
|
2020-05-16 15:38:14 +00:00
|
|
|
out:
|
2017-01-05 09:07:15 +00:00
|
|
|
if (ssp == &ss)
|
|
|
|
screen_free(&ss);
|
2020-09-18 11:23:29 +00:00
|
|
|
if (regex)
|
2020-05-16 15:38:14 +00:00
|
|
|
regfree(®);
|
2020-04-01 09:36:37 +00:00
|
|
|
return (1);
|
2017-01-05 09:07:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_clear_marks(struct window_mode_entry *wme)
|
2017-01-06 11:57:03 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2017-01-06 11:57:03 +00:00
|
|
|
|
|
|
|
free(data->searchmark);
|
|
|
|
data->searchmark = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_up(struct window_mode_entry *wme, int regex)
|
2016-05-03 13:40:50 +00:00
|
|
|
{
|
2021-04-01 06:46:12 +00:00
|
|
|
return (window_copy_search(wme, 0, regex));
|
2016-05-03 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 11:57:03 +00:00
|
|
|
static int
|
2021-04-01 06:46:12 +00:00
|
|
|
window_copy_search_down(struct window_mode_entry *wme, int regex)
|
2016-05-03 13:40:50 +00:00
|
|
|
{
|
2021-04-01 06:46:12 +00:00
|
|
|
return (window_copy_search(wme, 1, regex));
|
2016-05-03 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_goto_line(struct window_mode_entry *wme, const char *linestr)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-08-18 07:08:26 +00:00
|
|
|
const char *errstr;
|
2018-09-03 08:51:43 +00:00
|
|
|
int lineno;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2018-09-03 08:51:43 +00:00
|
|
|
lineno = strtonum(linestr, -1, INT_MAX, &errstr);
|
2009-08-18 07:08:26 +00:00
|
|
|
if (errstr != NULL)
|
|
|
|
return;
|
2018-09-03 08:51:43 +00:00
|
|
|
if (lineno < 0 || (u_int)lineno > screen_hsize(data->backing))
|
|
|
|
lineno = screen_hsize(data->backing);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-08-18 07:08:26 +00:00
|
|
|
data->oy = lineno;
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 15:11:52 +00:00
|
|
|
static void
|
|
|
|
window_copy_match_start_end(struct window_copy_mode_data *data, u_int at,
|
|
|
|
u_int *start, u_int *end)
|
|
|
|
{
|
|
|
|
struct grid *gd = data->backing->grid;
|
2020-06-04 21:40:27 +00:00
|
|
|
u_int last = (gd->sy * gd->sx) - 1;
|
2020-05-16 15:11:52 +00:00
|
|
|
u_char mark = data->searchmark[at];
|
|
|
|
|
|
|
|
*start = *end = at;
|
|
|
|
while (*start != 0 && data->searchmark[*start] == mark)
|
|
|
|
(*start)--;
|
|
|
|
if (data->searchmark[*start] != mark)
|
|
|
|
(*start)++;
|
|
|
|
while (*end != last && data->searchmark[*end] == mark)
|
|
|
|
(*end)++;
|
|
|
|
if (data->searchmark[*end] != mark)
|
|
|
|
(*end)--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
window_copy_match_at_cursor(struct window_copy_mode_data *data)
|
|
|
|
{
|
|
|
|
struct grid *gd = data->backing->grid;
|
|
|
|
struct grid_cell gc;
|
|
|
|
u_int at, start, end, cy, px, py;
|
|
|
|
u_int sx = screen_size_x(data->backing);
|
|
|
|
char *buf = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
if (data->searchmark == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
cy = screen_hsize(data->backing) - data->oy + data->cy;
|
2020-06-04 21:40:27 +00:00
|
|
|
if (window_copy_search_mark_at(data, data->cx, cy, &at) != 0)
|
|
|
|
return (NULL);
|
2021-03-09 13:07:50 +00:00
|
|
|
if (data->searchmark[at] == 0) {
|
|
|
|
/* Allow one position after the match. */
|
|
|
|
if (at == 0 || data->searchmark[--at] == 0)
|
|
|
|
return (NULL);
|
|
|
|
}
|
2020-05-16 15:11:52 +00:00
|
|
|
window_copy_match_start_end(data, at, &start, &end);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cells will not be set in the marked array unless they are valid text
|
|
|
|
* and wrapping will be taken care of, so we can just copy.
|
|
|
|
*/
|
|
|
|
for (at = start; at <= end; at++) {
|
|
|
|
py = at / sx;
|
2020-05-25 12:12:58 +00:00
|
|
|
px = at - (py * sx);
|
2020-05-16 15:11:52 +00:00
|
|
|
|
2020-06-04 21:40:27 +00:00
|
|
|
grid_get_cell(gd, px, gd->hsize + py - data->oy, &gc);
|
2020-05-16 15:11:52 +00:00
|
|
|
buf = xrealloc(buf, len + gc.data.size + 1);
|
|
|
|
memcpy(buf + len, gc.data.data, gc.data.size);
|
|
|
|
len += gc.data.size;
|
|
|
|
}
|
|
|
|
if (len != 0)
|
|
|
|
buf[len] = '\0';
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_update_style(struct window_mode_entry *wme, u_int fx, u_int fy,
|
|
|
|
struct grid_cell *gc, const struct grid_cell *mgc,
|
2020-05-16 16:10:28 +00:00
|
|
|
const struct grid_cell *cgc, const struct grid_cell *mkgc)
|
2020-05-16 15:11:52 +00:00
|
|
|
{
|
2021-04-01 06:46:12 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
2020-05-16 15:11:52 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2020-05-16 15:38:14 +00:00
|
|
|
u_int mark, start, end, cy, cursor, current;
|
2020-08-05 09:11:09 +00:00
|
|
|
int inv = 0, found = 0;
|
2021-04-01 06:46:12 +00:00
|
|
|
int keys;
|
2020-05-16 16:10:28 +00:00
|
|
|
|
|
|
|
if (data->showmark && fy == data->my) {
|
|
|
|
gc->attr = mkgc->attr;
|
|
|
|
if (fx == data->mx)
|
|
|
|
inv = 1;
|
|
|
|
if (inv) {
|
|
|
|
gc->fg = mkgc->bg;
|
|
|
|
gc->bg = mkgc->fg;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gc->fg = mkgc->fg;
|
|
|
|
gc->bg = mkgc->bg;
|
|
|
|
}
|
|
|
|
}
|
2020-05-16 15:11:52 +00:00
|
|
|
|
|
|
|
if (data->searchmark == NULL)
|
|
|
|
return;
|
2020-05-16 15:38:14 +00:00
|
|
|
|
2020-06-04 21:40:27 +00:00
|
|
|
if (window_copy_search_mark_at(data, fx, fy, ¤t) != 0)
|
|
|
|
return;
|
2020-05-16 15:38:14 +00:00
|
|
|
mark = data->searchmark[current];
|
2020-05-16 15:11:52 +00:00
|
|
|
if (mark == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cy = screen_hsize(data->backing) - data->oy + data->cy;
|
2020-08-05 09:11:09 +00:00
|
|
|
if (window_copy_search_mark_at(data, data->cx, cy, &cursor) == 0) {
|
2021-04-01 06:46:12 +00:00
|
|
|
keys = options_get_number(wp->window->options, "mode-keys");
|
|
|
|
if (cursor != 0 &&
|
|
|
|
keys == MODEKEY_EMACS &&
|
|
|
|
data->searchdirection) {
|
|
|
|
if (data->searchmark[cursor - 1] == mark) {
|
|
|
|
cursor--;
|
2020-08-05 09:11:09 +00:00
|
|
|
found = 1;
|
2021-04-01 06:46:12 +00:00
|
|
|
}
|
|
|
|
} else if (data->searchmark[cursor] == mark)
|
|
|
|
found = 1;
|
2020-08-05 09:11:09 +00:00
|
|
|
if (found) {
|
|
|
|
window_copy_match_start_end(data, cursor, &start, &end);
|
|
|
|
if (current >= start && current <= end) {
|
|
|
|
gc->attr = cgc->attr;
|
|
|
|
if (inv) {
|
|
|
|
gc->fg = cgc->bg;
|
|
|
|
gc->bg = cgc->fg;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gc->fg = cgc->fg;
|
|
|
|
gc->bg = cgc->bg;
|
|
|
|
}
|
|
|
|
return;
|
2020-05-16 16:10:28 +00:00
|
|
|
}
|
2020-05-16 15:11:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gc->attr = mgc->attr;
|
2020-05-16 16:10:28 +00:00
|
|
|
if (inv) {
|
|
|
|
gc->fg = mgc->bg;
|
|
|
|
gc->bg = mgc->fg;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gc->fg = mgc->fg;
|
|
|
|
gc->bg = mgc->bg;
|
|
|
|
}
|
2020-05-16 15:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_write_one(struct window_mode_entry *wme,
|
|
|
|
struct screen_write_ctx *ctx, u_int py, u_int fy, u_int nx,
|
2020-05-16 16:10:28 +00:00
|
|
|
const struct grid_cell *mgc, const struct grid_cell *cgc,
|
|
|
|
const struct grid_cell *mkgc)
|
2020-05-16 15:11:52 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct grid *gd = data->backing->grid;
|
|
|
|
struct grid_cell gc;
|
|
|
|
u_int fx;
|
|
|
|
|
|
|
|
screen_write_cursormove(ctx, 0, py, 0);
|
|
|
|
for (fx = 0; fx < nx; fx++) {
|
|
|
|
grid_get_cell(gd, fx, fy, &gc);
|
|
|
|
if (fx + gc.data.width <= nx) {
|
2020-05-16 16:10:28 +00:00
|
|
|
window_copy_update_style(wme, fx, fy, &gc, mgc, cgc,
|
|
|
|
mkgc);
|
2020-05-16 15:11:52 +00:00
|
|
|
screen_write_cell(ctx, &gc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(struct window_mode_entry *wme,
|
|
|
|
struct screen_write_ctx *ctx, u_int py)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
2015-10-27 15:58:42 +00:00
|
|
|
struct options *oo = wp->window->options;
|
2020-05-16 16:10:28 +00:00
|
|
|
struct grid_cell gc, mgc, cgc, mkgc;
|
2014-01-22 22:32:15 +00:00
|
|
|
char hdr[512];
|
2017-01-05 09:07:15 +00:00
|
|
|
size_t size = 0;
|
2020-04-10 07:44:26 +00:00
|
|
|
u_int hsize = screen_hsize(data->backing);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-05-16 15:01:30 +00:00
|
|
|
style_apply(&gc, oo, "mode-style", NULL);
|
2017-01-07 15:28:13 +00:00
|
|
|
gc.flags |= GRID_FLAG_NOPALETTE;
|
2020-05-16 15:11:52 +00:00
|
|
|
style_apply(&mgc, oo, "copy-mode-match-style", NULL);
|
|
|
|
mgc.flags |= GRID_FLAG_NOPALETTE;
|
|
|
|
style_apply(&cgc, oo, "copy-mode-current-match-style", NULL);
|
|
|
|
cgc.flags |= GRID_FLAG_NOPALETTE;
|
2020-05-16 16:10:28 +00:00
|
|
|
style_apply(&mkgc, oo, "copy-mode-mark-style", NULL);
|
|
|
|
mkgc.flags |= GRID_FLAG_NOPALETTE;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2020-03-12 13:19:20 +00:00
|
|
|
if (py == 0 && s->rupper < s->rlower && !data->hide_position) {
|
2017-03-24 07:14:27 +00:00
|
|
|
if (data->searchmark == NULL) {
|
2020-04-01 09:36:37 +00:00
|
|
|
if (data->timeout) {
|
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
2020-04-10 07:44:26 +00:00
|
|
|
"(timed out) [%u/%u]", data->oy, hsize);
|
2020-04-01 09:36:37 +00:00
|
|
|
} else {
|
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
2020-04-10 07:44:26 +00:00
|
|
|
"[%u/%u]", data->oy, hsize);
|
2020-04-01 09:36:37 +00:00
|
|
|
}
|
2017-03-24 07:14:27 +00:00
|
|
|
} else {
|
2020-05-16 15:38:14 +00:00
|
|
|
if (data->searchcount == -1) {
|
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
|
|
|
"[%u/%u]", data->oy, hsize);
|
2020-12-28 09:36:26 +00:00
|
|
|
} else {
|
2017-03-24 07:14:27 +00:00
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
2020-05-16 15:38:14 +00:00
|
|
|
"(%d%s results) [%u/%u]", data->searchcount,
|
2020-08-05 09:11:09 +00:00
|
|
|
data->searchmore ? "+" : "", data->oy,
|
|
|
|
hsize);
|
2017-03-24 07:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-08 20:36:42 +00:00
|
|
|
if (size > screen_size_x(s))
|
|
|
|
size = screen_size_x(s);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(ctx, screen_size_x(s) - size, 0, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_puts(ctx, &gc, "%s", hdr);
|
|
|
|
} else
|
|
|
|
size = 0;
|
|
|
|
|
2014-04-11 19:35:54 +00:00
|
|
|
if (size < screen_size_x(s)) {
|
2020-05-16 15:11:52 +00:00
|
|
|
window_copy_write_one(wme, ctx, py, hsize - data->oy + py,
|
2020-05-16 16:10:28 +00:00
|
|
|
screen_size_x(s) - size, &mgc, &cgc, &mkgc);
|
2014-04-11 19:35:54 +00:00
|
|
|
}
|
2009-08-13 19:35:20 +00:00
|
|
|
|
|
|
|
if (py == data->cy && data->cx == screen_size_x(s)) {
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(ctx, screen_size_x(s) - 1, py, 0);
|
2020-05-16 15:11:52 +00:00
|
|
|
screen_write_putc(ctx, &grid_default_cell, '$');
|
2009-08-13 19:35:20 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_lines(struct window_mode_entry *wme,
|
|
|
|
struct screen_write_ctx *ctx, u_int py, u_int ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
u_int yy;
|
|
|
|
|
|
|
|
for (yy = py; yy < py + ny; yy++)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, ctx, py);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_selection(struct window_mode_entry *wme, u_int old_y)
|
2014-12-15 10:02:55 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2020-02-24 09:53:59 +00:00
|
|
|
struct grid *gd = data->backing->grid;
|
2014-12-15 10:02:55 +00:00
|
|
|
u_int new_y, start, end;
|
|
|
|
|
|
|
|
new_y = data->cy;
|
|
|
|
if (old_y <= new_y) {
|
|
|
|
start = old_y;
|
|
|
|
end = new_y;
|
|
|
|
} else {
|
|
|
|
start = new_y;
|
|
|
|
end = old_y;
|
|
|
|
}
|
2020-02-24 09:53:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In word selection mode the first word on the line below the cursor
|
|
|
|
* might be selected, so add this line to the redraw area.
|
|
|
|
*/
|
|
|
|
if (data->selflag == SEL_WORD) {
|
|
|
|
/* Last grid line in data coordinates. */
|
|
|
|
if (end < gd->sy + data->oy - 1)
|
|
|
|
end++;
|
|
|
|
}
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, start, end - start + 1);
|
2014-12-15 10:02:55 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(struct window_mode_entry *wme, u_int py, u_int ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, NULL);
|
2009-06-01 22:58:49 +00:00
|
|
|
for (i = py; i < py + ny; i++)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, &ctx, i);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, 0, screen_size_y(&data->screen));
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
static void
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_synchronize_cursor_end(struct window_mode_entry *wme, int begin,
|
|
|
|
int no_reset)
|
2016-11-24 13:38:44 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int xx, yy;
|
|
|
|
|
2021-01-18 11:14:23 +00:00
|
|
|
xx = data->cx;
|
2016-11-24 13:38:44 +00:00
|
|
|
yy = screen_hsize(data->backing) + data->cy - data->oy;
|
2020-02-24 09:53:59 +00:00
|
|
|
switch (data->selflag) {
|
|
|
|
case SEL_WORD:
|
2020-03-19 13:28:52 +00:00
|
|
|
if (no_reset)
|
2020-02-24 09:53:59 +00:00
|
|
|
break;
|
2020-03-19 13:28:52 +00:00
|
|
|
begin = 0;
|
2020-02-24 09:53:59 +00:00
|
|
|
if (data->dy > yy || (data->dy == yy && data->dx > xx)) {
|
|
|
|
/* Right to left selection. */
|
|
|
|
window_copy_cursor_previous_word_pos(wme, data->ws, 0,
|
|
|
|
&xx, &yy);
|
|
|
|
begin = 1;
|
|
|
|
|
|
|
|
/* Reset the end. */
|
|
|
|
data->endselx = data->endselrx;
|
|
|
|
data->endsely = data->endselry;
|
|
|
|
} else {
|
|
|
|
/* Left to right selection. */
|
|
|
|
if (xx >= window_copy_find_length(wme, yy) ||
|
|
|
|
!window_copy_in_set(wme, xx + 1, yy, data->ws))
|
|
|
|
window_copy_cursor_next_word_end_pos(wme,
|
|
|
|
data->ws, &xx, &yy);
|
|
|
|
|
|
|
|
/* Reset the start. */
|
|
|
|
data->selx = data->selrx;
|
|
|
|
data->sely = data->selry;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SEL_LINE:
|
2021-01-18 11:14:23 +00:00
|
|
|
if (no_reset)
|
2020-03-19 13:28:52 +00:00
|
|
|
break;
|
2020-03-16 14:17:56 +00:00
|
|
|
begin = 0;
|
2020-02-24 09:53:59 +00:00
|
|
|
if (data->dy > yy) {
|
|
|
|
/* Right to left selection. */
|
|
|
|
xx = 0;
|
|
|
|
begin = 1;
|
|
|
|
|
|
|
|
/* Reset the end. */
|
|
|
|
data->endselx = data->endselrx;
|
|
|
|
data->endsely = data->endselry;
|
|
|
|
} else {
|
|
|
|
/* Left to right selection. */
|
2021-03-09 08:24:09 +00:00
|
|
|
if (yy < data->endselry)
|
|
|
|
yy = data->endselry;
|
2020-02-24 09:53:59 +00:00
|
|
|
xx = window_copy_find_length(wme, yy);
|
2016-11-24 13:38:44 +00:00
|
|
|
|
2020-02-24 09:53:59 +00:00
|
|
|
/* Reset the start. */
|
|
|
|
data->selx = data->selrx;
|
|
|
|
data->sely = data->selry;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SEL_CHAR:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (begin) {
|
|
|
|
data->selx = xx;
|
|
|
|
data->sely = yy;
|
|
|
|
} else {
|
2016-11-24 13:38:44 +00:00
|
|
|
data->endselx = xx;
|
|
|
|
data->endsely = yy;
|
2020-02-24 09:53:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_synchronize_cursor(struct window_mode_entry *wme, int no_reset)
|
2020-02-24 09:53:59 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
|
|
|
|
switch (data->cursordrag) {
|
|
|
|
case CURSORDRAG_ENDSEL:
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_synchronize_cursor_end(wme, 0, no_reset);
|
2016-11-24 13:38:44 +00:00
|
|
|
break;
|
|
|
|
case CURSORDRAG_SEL:
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_synchronize_cursor_end(wme, 1, no_reset);
|
2016-11-24 13:38:44 +00:00
|
|
|
break;
|
|
|
|
case CURSORDRAG_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_update_cursor(struct window_mode_entry *wme, u_int cx, u_int cy)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-08-13 19:35:20 +00:00
|
|
|
struct screen *s = &data->screen;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2009-08-13 19:35:20 +00:00
|
|
|
u_int old_cx, old_cy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
old_cx = data->cx; old_cy = data->cy;
|
|
|
|
data->cx = cx; data->cy = cy;
|
|
|
|
if (old_cx == screen_size_x(s))
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, old_cy, 1);
|
2009-08-13 19:35:20 +00:00
|
|
|
if (data->cx == screen_size_x(s))
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
2009-08-13 19:35:20 +00:00
|
|
|
else {
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, NULL);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy, 0);
|
2009-08-13 19:35:20 +00:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_start_selection(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
data->selx = data->cx;
|
2010-04-06 21:35:44 +00:00
|
|
|
data->sely = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
data->endselx = data->selx;
|
|
|
|
data->endsely = data->sely;
|
|
|
|
|
|
|
|
data->cursordrag = CURSORDRAG_ENDSEL;
|
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_set_selection(wme, 1, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
static int
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_adjust_selection(struct window_mode_entry *wme, u_int *selx,
|
|
|
|
u_int *sely)
|
2016-11-24 13:38:44 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2016-11-24 13:38:44 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int sx, sy, ty;
|
|
|
|
int relpos;
|
|
|
|
|
|
|
|
sx = *selx;
|
|
|
|
sy = *sely;
|
|
|
|
|
|
|
|
ty = screen_hsize(data->backing) - data->oy;
|
|
|
|
if (sy < ty) {
|
|
|
|
relpos = WINDOW_COPY_REL_POS_ABOVE;
|
|
|
|
if (!data->rectflag)
|
|
|
|
sx = 0;
|
|
|
|
sy = 0;
|
|
|
|
} else if (sy > ty + screen_size_y(s) - 1) {
|
|
|
|
relpos = WINDOW_COPY_REL_POS_BELOW;
|
|
|
|
if (!data->rectflag)
|
|
|
|
sx = screen_size_x(s) - 1;
|
|
|
|
sy = screen_size_y(s) - 1;
|
|
|
|
} else {
|
|
|
|
relpos = WINDOW_COPY_REL_POS_ON_SCREEN;
|
|
|
|
sy -= ty;
|
|
|
|
}
|
|
|
|
|
|
|
|
*selx = sx;
|
2017-05-29 07:58:33 +00:00
|
|
|
*sely = sy;
|
2016-11-24 13:38:44 +00:00
|
|
|
return (relpos);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(struct window_mode_entry *wme, int may_redraw,
|
|
|
|
int no_reset)
|
2018-07-31 11:49:26 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2018-07-31 11:49:26 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
|
|
|
if (s->sel == NULL && data->lineflag == LINE_SEL_NONE)
|
|
|
|
return (0);
|
2020-03-19 13:28:52 +00:00
|
|
|
return (window_copy_set_selection(wme, may_redraw, no_reset));
|
2018-07-31 11:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_set_selection(struct window_mode_entry *wme, int may_redraw,
|
|
|
|
int no_reset)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
2015-10-27 15:58:42 +00:00
|
|
|
struct options *oo = wp->window->options;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct grid_cell gc;
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int sx, sy, cy, endsx, endsy;
|
|
|
|
int startrelpos, endrelpos;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_synchronize_cursor(wme, no_reset);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/* Adjust the selection. */
|
|
|
|
sx = data->selx;
|
|
|
|
sy = data->sely;
|
2019-03-07 20:24:21 +00:00
|
|
|
startrelpos = window_copy_adjust_selection(wme, &sx, &sy);
|
2016-11-24 13:38:44 +00:00
|
|
|
|
|
|
|
/* Adjust the end of selection. */
|
|
|
|
endsx = data->endselx;
|
|
|
|
endsy = data->endsely;
|
2019-03-07 20:24:21 +00:00
|
|
|
endrelpos = window_copy_adjust_selection(wme, &endsx, &endsy);
|
2016-11-24 13:38:44 +00:00
|
|
|
|
|
|
|
/* Selection is outside of the current screen */
|
|
|
|
if (startrelpos == endrelpos &&
|
|
|
|
startrelpos != WINDOW_COPY_REL_POS_ON_SCREEN) {
|
|
|
|
screen_hide_selection(s);
|
|
|
|
return (0);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
/* Set colours and selection. */
|
2020-05-16 15:01:30 +00:00
|
|
|
style_apply(&gc, oo, "mode-style", NULL);
|
2017-01-07 15:28:13 +00:00
|
|
|
gc.flags |= GRID_FLAG_NOPALETTE;
|
2018-07-31 11:49:26 +00:00
|
|
|
screen_set_selection(s, sx, sy, endsx, endsy, data->rectflag,
|
|
|
|
data->modekeys, &gc);
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2013-11-08 12:39:20 +00:00
|
|
|
if (data->rectflag && may_redraw) {
|
2010-02-06 17:35:01 +00:00
|
|
|
/*
|
|
|
|
* Can't rely on the caller to redraw the right lines for
|
|
|
|
* rectangle selection - find the highest line and the number
|
|
|
|
* of lines, and redraw just past that in both directions
|
|
|
|
*/
|
|
|
|
cy = data->cy;
|
2017-08-29 20:26:25 +00:00
|
|
|
if (data->cursordrag == CURSORDRAG_ENDSEL) {
|
|
|
|
if (sy < cy)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, sy, cy - sy + 1);
|
2017-08-29 20:26:25 +00:00
|
|
|
else
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, cy, sy - cy + 1);
|
2017-08-29 20:26:25 +00:00
|
|
|
} else {
|
2019-03-07 20:24:21 +00:00
|
|
|
if (endsy < cy) {
|
|
|
|
window_copy_redraw_lines(wme, endsy,
|
|
|
|
cy - endsy + 1);
|
|
|
|
} else {
|
|
|
|
window_copy_redraw_lines(wme, cy,
|
|
|
|
endsy - cy + 1);
|
|
|
|
}
|
2017-08-29 20:26:25 +00:00
|
|
|
}
|
2010-02-06 17:35:01 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void *
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_get_selection(struct window_mode_entry *wme, size_t *len)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
char *buf;
|
2010-02-06 17:35:01 +00:00
|
|
|
size_t off;
|
2014-06-19 07:37:59 +00:00
|
|
|
u_int i, xx, yy, sx, sy, ex, ey, ey_last;
|
2018-04-23 13:46:34 +00:00
|
|
|
u_int firstsx, lastex, restex, restsx, selx;
|
2011-04-24 21:06:12 +00:00
|
|
|
int keys;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-05-16 15:11:52 +00:00
|
|
|
if (data->screen.sel == NULL && data->lineflag == LINE_SEL_NONE) {
|
|
|
|
buf = window_copy_match_at_cursor(data);
|
|
|
|
if (buf != NULL)
|
|
|
|
*len = strlen(buf);
|
2020-06-02 19:10:26 +00:00
|
|
|
else
|
|
|
|
*len = 0;
|
2020-05-16 15:11:52 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
buf = xmalloc(1);
|
|
|
|
off = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The selection extends from selx,sely to (adjusted) cx,cy on
|
|
|
|
* the base screen.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Find start and end. */
|
2016-11-24 13:38:44 +00:00
|
|
|
xx = data->endselx;
|
|
|
|
yy = data->endsely;
|
2009-07-02 16:15:43 +00:00
|
|
|
if (yy < data->sely || (yy == data->sely && xx < data->selx)) {
|
2009-06-01 22:58:49 +00:00
|
|
|
sx = xx; sy = yy;
|
|
|
|
ex = data->selx; ey = data->sely;
|
|
|
|
} else {
|
|
|
|
sx = data->selx; sy = data->sely;
|
|
|
|
ex = xx; ey = yy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trim ex to end of line. */
|
2019-03-07 20:24:21 +00:00
|
|
|
ey_last = window_copy_find_length(wme, ey);
|
2014-06-19 07:37:59 +00:00
|
|
|
if (ex > ey_last)
|
|
|
|
ex = ey_last;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-02-06 17:35:01 +00:00
|
|
|
/*
|
|
|
|
* Deal with rectangle-copy if necessary; four situations: start of
|
|
|
|
* first line (firstsx), end of last line (lastex), start (restsx) and
|
|
|
|
* end (restex) of all other lines.
|
|
|
|
*/
|
|
|
|
xx = screen_size_x(s);
|
2011-04-24 21:06:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Behave according to mode-keys. If it is emacs, copy like emacs,
|
|
|
|
* keeping the top-left-most character, and dropping the
|
|
|
|
* bottom-right-most, regardless of copy direction. If it is vi, also
|
|
|
|
* keep bottom-right-most character.
|
|
|
|
*/
|
2015-10-27 15:58:42 +00:00
|
|
|
keys = options_get_number(wp->window->options, "mode-keys");
|
2010-02-06 17:35:01 +00:00
|
|
|
if (data->rectflag) {
|
|
|
|
/*
|
|
|
|
* Need to ignore the column with the cursor in it, which for
|
|
|
|
* rectangular copy means knowing which side the cursor is on.
|
|
|
|
*/
|
2018-04-23 13:46:34 +00:00
|
|
|
if (data->cursordrag == CURSORDRAG_ENDSEL)
|
|
|
|
selx = data->selx;
|
|
|
|
else
|
|
|
|
selx = data->endselx;
|
|
|
|
if (selx < data->cx) {
|
2010-02-06 17:35:01 +00:00
|
|
|
/* Selection start is on the left. */
|
2011-04-24 21:06:12 +00:00
|
|
|
if (keys == MODEKEY_EMACS) {
|
|
|
|
lastex = data->cx;
|
|
|
|
restex = data->cx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastex = data->cx + 1;
|
|
|
|
restex = data->cx + 1;
|
|
|
|
}
|
2018-04-23 13:46:34 +00:00
|
|
|
firstsx = selx;
|
|
|
|
restsx = selx;
|
2010-02-06 17:35:01 +00:00
|
|
|
} else {
|
|
|
|
/* Cursor is on the left. */
|
2018-04-23 13:46:34 +00:00
|
|
|
lastex = selx + 1;
|
|
|
|
restex = selx + 1;
|
2010-12-11 17:56:01 +00:00
|
|
|
firstsx = data->cx;
|
|
|
|
restsx = data->cx;
|
2010-02-06 17:35:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-04-24 21:06:12 +00:00
|
|
|
if (keys == MODEKEY_EMACS)
|
|
|
|
lastex = ex;
|
2011-10-23 23:38:16 +00:00
|
|
|
else
|
2011-04-24 21:06:12 +00:00
|
|
|
lastex = ex + 1;
|
2010-02-06 17:35:01 +00:00
|
|
|
restex = xx;
|
|
|
|
firstsx = sx;
|
|
|
|
restsx = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Copy the lines. */
|
2014-05-14 06:39:58 +00:00
|
|
|
for (i = sy; i <= ey; i++) {
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_copy_line(wme, &buf, &off, i,
|
2014-05-14 06:39:58 +00:00
|
|
|
(i == sy ? firstsx : restsx),
|
|
|
|
(i == ey ? lastex : restex));
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 18:50:45 +00:00
|
|
|
/* Don't bother if no data. */
|
|
|
|
if (off == 0) {
|
2012-07-10 11:53:01 +00:00
|
|
|
free(buf);
|
2020-06-02 19:16:46 +00:00
|
|
|
*len = 0;
|
2013-03-22 15:52:40 +00:00
|
|
|
return (NULL);
|
2009-09-07 18:50:45 +00:00
|
|
|
}
|
2021-03-09 08:24:09 +00:00
|
|
|
/* Remove final \n (unless at end in vi mode). */
|
|
|
|
if (keys == MODEKEY_EMACS || lastex <= ey_last) {
|
|
|
|
if (~grid_get_line(data->backing->grid, ey)->flags &
|
|
|
|
GRID_LINE_WRAPPED || lastex != ey_last)
|
|
|
|
off -= 1;
|
|
|
|
}
|
2014-06-19 07:37:59 +00:00
|
|
|
*len = off;
|
2013-03-22 15:52:40 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-04-02 09:03:39 +00:00
|
|
|
window_copy_copy_buffer(struct window_mode_entry *wme, const char *prefix,
|
|
|
|
void *buf, size_t len)
|
2013-03-22 15:52:40 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct screen_write_ctx ctx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-06-03 17:43:01 +00:00
|
|
|
if (options_get_number(global_options, "set-clipboard") != 0) {
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, NULL);
|
2013-03-25 11:43:33 +00:00
|
|
|
screen_write_setselection(&ctx, buf, len);
|
|
|
|
screen_write_stop(&ctx);
|
2017-06-09 09:21:24 +00:00
|
|
|
notify_pane("pane-set-clipboard", wp);
|
2013-03-25 11:43:33 +00:00
|
|
|
}
|
2011-05-18 20:24:29 +00:00
|
|
|
|
2019-04-02 09:03:39 +00:00
|
|
|
paste_add(prefix, buf, len);
|
2013-03-22 15:52:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 14:46:53 +00:00
|
|
|
static void *
|
|
|
|
window_copy_pipe_run(struct window_mode_entry *wme, struct session *s,
|
|
|
|
const char *cmd, size_t *len)
|
2013-03-22 15:52:40 +00:00
|
|
|
{
|
2019-04-02 09:03:39 +00:00
|
|
|
void *buf;
|
|
|
|
struct job *job;
|
2013-03-22 15:52:40 +00:00
|
|
|
|
2021-02-08 14:46:53 +00:00
|
|
|
buf = window_copy_get_selection(wme, len);
|
2020-04-17 08:03:22 +00:00
|
|
|
if (cmd == NULL || *cmd == '\0')
|
|
|
|
cmd = options_get_string(global_options, "copy-command");
|
|
|
|
if (cmd != NULL && *cmd != '\0') {
|
2021-03-02 10:56:45 +00:00
|
|
|
job = job_run(cmd, 0, NULL, s, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
JOB_NOWAIT, -1, -1);
|
2021-02-08 14:46:53 +00:00
|
|
|
bufferevent_write(job_get_event(job), buf, *len);
|
2020-04-17 08:03:22 +00:00
|
|
|
}
|
2021-02-08 14:46:53 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_pipe(struct window_mode_entry *wme, struct session *s,
|
|
|
|
const char *cmd)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
window_copy_pipe_run(wme, s, cmd, &len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_copy_pipe(struct window_mode_entry *wme, struct session *s,
|
|
|
|
const char *prefix, const char *cmd)
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
buf = window_copy_pipe_run(wme, s, cmd, &len);
|
2020-06-02 19:10:26 +00:00
|
|
|
if (buf != NULL)
|
|
|
|
window_copy_copy_buffer(wme, prefix, buf, len);
|
2013-03-22 15:52:40 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-04-02 09:03:39 +00:00
|
|
|
window_copy_copy_selection(struct window_mode_entry *wme, const char *prefix)
|
2013-03-22 15:52:40 +00:00
|
|
|
{
|
2018-11-08 18:49:19 +00:00
|
|
|
char *buf;
|
2014-09-01 21:50:18 +00:00
|
|
|
size_t len;
|
2013-03-22 15:52:40 +00:00
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
buf = window_copy_get_selection(wme, &len);
|
2018-11-08 18:49:19 +00:00
|
|
|
if (buf != NULL)
|
2019-04-02 09:03:39 +00:00
|
|
|
window_copy_copy_buffer(wme, prefix, buf, len);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_append_selection(struct window_mode_entry *wme)
|
2014-03-31 21:39:31 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
2014-05-13 07:34:35 +00:00
|
|
|
char *buf;
|
|
|
|
struct paste_buffer *pb;
|
2019-07-05 07:52:27 +00:00
|
|
|
const char *bufdata, *bufname = NULL;
|
2015-08-29 09:25:00 +00:00
|
|
|
size_t len, bufsize;
|
2014-05-13 07:34:35 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2014-03-31 21:39:31 +00:00
|
|
|
|
2019-03-07 20:24:21 +00:00
|
|
|
buf = window_copy_get_selection(wme, &len);
|
2014-03-31 21:39:31 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-06-03 17:43:01 +00:00
|
|
|
if (options_get_number(global_options, "set-clipboard") != 0) {
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, NULL);
|
2014-03-31 21:39:31 +00:00
|
|
|
screen_write_setselection(&ctx, buf, len);
|
|
|
|
screen_write_stop(&ctx);
|
2017-06-09 09:21:24 +00:00
|
|
|
notify_pane("pane-set-clipboard", wp);
|
2014-03-31 21:39:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 18:49:19 +00:00
|
|
|
pb = paste_get_top(&bufname);
|
2014-03-31 21:39:31 +00:00
|
|
|
if (pb != NULL) {
|
2015-08-29 09:25:00 +00:00
|
|
|
bufdata = paste_buffer_data(pb, &bufsize);
|
|
|
|
buf = xrealloc(buf, len + bufsize);
|
|
|
|
memmove(buf + bufsize, buf, len);
|
|
|
|
memcpy(buf, bufdata, bufsize);
|
|
|
|
len += bufsize;
|
2014-03-31 21:39:31 +00:00
|
|
|
}
|
2014-05-13 07:34:35 +00:00
|
|
|
if (paste_set(buf, len, bufname, NULL) != 0)
|
2014-03-31 21:39:31 +00:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_copy_line(struct window_mode_entry *wme, char **buf, size_t *off,
|
|
|
|
u_int sy, u_int sx, u_int ex)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct grid *gd = data->backing->grid;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct grid_line *gl;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2010-04-06 21:35:44 +00:00
|
|
|
u_int i, xx, wrapped = 0;
|
2014-10-02 08:36:26 +00:00
|
|
|
const char *s;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (sx > ex)
|
|
|
|
return;
|
|
|
|
|
2009-08-08 15:57:49 +00:00
|
|
|
/*
|
|
|
|
* Work out if the line was wrapped at the screen edge and all of it is
|
|
|
|
* on screen.
|
|
|
|
*/
|
2018-07-04 09:44:07 +00:00
|
|
|
gl = grid_get_line(gd, sy);
|
2009-12-03 22:50:09 +00:00
|
|
|
if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx)
|
2009-08-08 15:57:49 +00:00
|
|
|
wrapped = 1;
|
|
|
|
|
|
|
|
/* If the line was wrapped, don't strip spaces (use the full length). */
|
|
|
|
if (wrapped)
|
|
|
|
xx = gl->cellsize;
|
|
|
|
else
|
2019-03-07 20:24:21 +00:00
|
|
|
xx = window_copy_find_length(wme, sy);
|
2009-06-01 22:58:49 +00:00
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
if (sx > xx)
|
|
|
|
sx = xx;
|
|
|
|
|
|
|
|
if (sx < ex) {
|
|
|
|
for (i = sx; i < ex; i++) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(gd, i, sy, &gc);
|
|
|
|
if (gc.flags & GRID_FLAG_PADDING)
|
2009-06-01 22:58:49 +00:00
|
|
|
continue;
|
2015-11-13 08:09:28 +00:00
|
|
|
utf8_copy(&ud, &gc.data);
|
|
|
|
if (ud.size == 1 && (gc.attr & GRID_ATTR_CHARSET)) {
|
2014-10-02 08:36:26 +00:00
|
|
|
s = tty_acs_get(NULL, ud.data[0]);
|
|
|
|
if (s != NULL && strlen(s) <= sizeof ud.data) {
|
|
|
|
ud.size = strlen(s);
|
2014-10-22 23:18:53 +00:00
|
|
|
memcpy(ud.data, s, ud.size);
|
2014-10-02 08:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-18 02:16:21 +00:00
|
|
|
|
2014-10-08 17:35:58 +00:00
|
|
|
*buf = xrealloc(*buf, (*off) + ud.size);
|
2013-01-18 02:16:21 +00:00
|
|
|
memcpy(*buf + *off, ud.data, ud.size);
|
|
|
|
*off += ud.size;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-08 15:57:49 +00:00
|
|
|
/* Only add a newline if the line wasn't wrapped. */
|
2010-02-17 20:58:24 +00:00
|
|
|
if (!wrapped || ex != xx) {
|
2014-10-08 17:35:58 +00:00
|
|
|
*buf = xrealloc(*buf, (*off) + 1);
|
2009-08-08 15:57:49 +00:00
|
|
|
(*buf)[(*off)++] = '\n';
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_clear_selection(struct window_mode_entry *wme)
|
2010-02-22 20:28:21 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-02-22 20:28:21 +00:00
|
|
|
u_int px, py;
|
|
|
|
|
|
|
|
screen_clear_selection(&data->screen);
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
data->cursordrag = CURSORDRAG_NONE;
|
2018-08-29 18:54:23 +00:00
|
|
|
data->lineflag = LINE_SEL_NONE;
|
2020-03-15 20:44:19 +00:00
|
|
|
data->selflag = SEL_CHAR;
|
2016-11-24 13:38:44 +00:00
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
px = window_copy_find_length(wme, py);
|
2010-02-22 20:28:21 +00:00
|
|
|
if (data->cx > px)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_update_cursor(wme, px, data->cy);
|
2010-02-22 20:28:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_in_set(struct window_mode_entry *wme, u_int px, u_int py,
|
|
|
|
const char *set)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
|
|
|
|
grid_get_cell(data->backing->grid, px, py, &gc);
|
2018-11-28 11:20:13 +00:00
|
|
|
if (gc.flags & GRID_FLAG_PADDING)
|
2009-06-01 22:58:49 +00:00
|
|
|
return (0);
|
2019-05-26 17:34:45 +00:00
|
|
|
return (utf8_cstrhas(set, &gc.data));
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static u_int
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_find_length(struct window_mode_entry *wme, u_int py)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-05-26 17:34:45 +00:00
|
|
|
return (grid_line_length(data->backing->grid, py));
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_start_of_line(struct window_mode_entry *wme)
|
2009-07-12 16:12:34 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-06-05 15:49:48 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2020-12-22 09:22:14 +00:00
|
|
|
struct grid_reader gr;
|
2021-02-22 06:53:04 +00:00
|
|
|
u_int px, py, oldy, hsize;
|
2020-12-22 09:22:14 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
2021-01-22 10:21:24 +00:00
|
|
|
oldy = data->cy;
|
2020-12-22 09:22:14 +00:00
|
|
|
|
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
grid_reader_cursor_start_of_line(&gr, 1);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2021-02-22 06:53:04 +00:00
|
|
|
window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px, py);
|
2009-07-12 16:12:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_back_to_indentation(struct window_mode_entry *wme)
|
2009-07-12 16:15:34 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2021-04-05 08:43:48 +00:00
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
struct grid_reader gr;
|
|
|
|
u_int px, py, oldy, hsize;
|
2009-07-12 16:15:34 +00:00
|
|
|
|
2021-04-05 08:43:48 +00:00
|
|
|
px = data->cx;
|
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
|
|
|
oldy = data->cy;
|
2009-07-12 16:15:34 +00:00
|
|
|
|
2021-04-05 08:43:48 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
grid_reader_cursor_back_to_indentation(&gr);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
|
|
|
window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px, py);
|
2009-07-12 16:15:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_end_of_line(struct window_mode_entry *wme)
|
2009-07-12 16:12:34 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2020-12-22 09:22:14 +00:00
|
|
|
struct grid_reader gr;
|
2021-02-22 06:53:04 +00:00
|
|
|
u_int px, py, oldy, hsize;
|
2009-07-12 16:12:34 +00:00
|
|
|
|
2020-12-22 09:22:14 +00:00
|
|
|
px = data->cx;
|
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
2021-01-22 10:21:24 +00:00
|
|
|
oldy = data->cy;
|
2009-07-12 16:12:34 +00:00
|
|
|
|
2020-12-22 09:22:14 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
if (data->screen.sel != NULL && data->rectflag)
|
|
|
|
grid_reader_cursor_end_of_line(&gr, 1, 1);
|
|
|
|
else
|
|
|
|
grid_reader_cursor_end_of_line(&gr, 1, 0);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2021-02-22 06:53:04 +00:00
|
|
|
window_copy_acquire_cursor_down(wme, hsize, screen_size_y(back_s),
|
|
|
|
data->oy, oldy, px, py, 0);
|
2009-07-12 16:12:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_other_end(struct window_mode_entry *wme)
|
2013-10-23 11:31:03 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2013-10-23 11:31:03 +00:00
|
|
|
struct screen *s = &data->screen;
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int selx, sely, cy, yy, hsize;
|
2013-10-23 11:31:03 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (s->sel == NULL && data->lineflag == LINE_SEL_NONE)
|
2013-10-23 11:31:03 +00:00
|
|
|
return;
|
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT)
|
|
|
|
data->lineflag = LINE_SEL_RIGHT_LEFT;
|
|
|
|
else if (data->lineflag == LINE_SEL_RIGHT_LEFT)
|
|
|
|
data->lineflag = LINE_SEL_LEFT_RIGHT;
|
2014-11-06 09:17:25 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
switch (data->cursordrag) {
|
|
|
|
case CURSORDRAG_NONE:
|
|
|
|
case CURSORDRAG_SEL:
|
|
|
|
data->cursordrag = CURSORDRAG_ENDSEL;
|
|
|
|
break;
|
|
|
|
case CURSORDRAG_ENDSEL:
|
|
|
|
data->cursordrag = CURSORDRAG_SEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
selx = data->endselx;
|
|
|
|
sely = data->endsely;
|
|
|
|
if (data->cursordrag == CURSORDRAG_SEL) {
|
|
|
|
selx = data->selx;
|
|
|
|
sely = data->sely;
|
|
|
|
}
|
|
|
|
|
2013-10-23 11:31:03 +00:00
|
|
|
cy = data->cy;
|
|
|
|
yy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
|
|
|
|
data->cx = selx;
|
|
|
|
|
2015-01-15 13:35:13 +00:00
|
|
|
hsize = screen_hsize(data->backing);
|
2016-11-24 13:38:44 +00:00
|
|
|
if (sely < hsize - data->oy) { /* above */
|
2015-01-15 13:35:13 +00:00
|
|
|
data->oy = hsize - sely;
|
2013-10-23 11:31:03 +00:00
|
|
|
data->cy = 0;
|
2016-11-24 13:38:44 +00:00
|
|
|
} else if (sely > hsize - data->oy + screen_size_y(s)) { /* below */
|
2015-01-15 13:35:13 +00:00
|
|
|
data->oy = hsize - sely + screen_size_y(s) - 1;
|
2013-10-23 11:31:03 +00:00
|
|
|
data->cy = screen_size_y(s) - 1;
|
|
|
|
} else
|
|
|
|
data->cy = cy + sely - yy;
|
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 1);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2013-10-23 11:31:03 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_left(struct window_mode_entry *wme)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2020-12-22 09:22:14 +00:00
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
struct grid_reader gr;
|
2021-02-22 06:53:04 +00:00
|
|
|
u_int px, py, oldy, hsize;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-12-22 09:22:14 +00:00
|
|
|
px = data->cx;
|
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
2021-02-22 06:53:04 +00:00
|
|
|
oldy = data->cy;
|
2020-12-22 09:22:14 +00:00
|
|
|
|
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
2021-04-05 08:43:48 +00:00
|
|
|
grid_reader_cursor_left(&gr, 1);
|
2020-12-22 09:22:14 +00:00
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2021-02-22 06:53:04 +00:00
|
|
|
window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px, py);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2020-09-22 08:41:27 +00:00
|
|
|
window_copy_cursor_right(struct window_mode_entry *wme, int all)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2020-12-22 09:22:14 +00:00
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
struct grid_reader gr;
|
2021-02-22 06:53:04 +00:00
|
|
|
u_int px, py, oldy, hsize;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-12-22 09:22:14 +00:00
|
|
|
px = data->cx;
|
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
2021-02-22 06:53:04 +00:00
|
|
|
oldy = data->cy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-12-22 09:22:14 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
grid_reader_cursor_right(&gr, 1, all);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2021-02-22 06:53:04 +00:00
|
|
|
window_copy_acquire_cursor_down(wme, hsize, screen_size_y(back_s),
|
|
|
|
data->oy, oldy, px, py, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_up(struct window_mode_entry *wme, int scroll_only)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-01-24 21:05:12 +00:00
|
|
|
struct screen *s = &data->screen;
|
2009-06-01 22:58:49 +00:00
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
ox = window_copy_find_length(wme, oy);
|
2012-03-11 23:01:19 +00:00
|
|
|
if (data->cx != ox) {
|
2009-08-21 07:33:58 +00:00
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_other_end(wme);
|
2014-11-06 09:17:25 +00:00
|
|
|
|
2009-10-06 07:09:00 +00:00
|
|
|
if (scroll_only || data->cy == 0) {
|
2019-06-13 20:38:05 +00:00
|
|
|
data->cx = data->lastcx;
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_scroll_down(wme, 1);
|
2010-01-24 21:05:12 +00:00
|
|
|
if (scroll_only) {
|
|
|
|
if (data->cy == screen_size_y(s) - 1)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
2010-01-24 21:05:12 +00:00
|
|
|
else
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy, 2);
|
2010-01-24 21:05:12 +00:00
|
|
|
}
|
2009-10-06 07:09:00 +00:00
|
|
|
} else {
|
2019-06-13 20:38:05 +00:00
|
|
|
window_copy_update_cursor(wme, data->lastcx, data->cy - 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
if (window_copy_update_selection(wme, 1, 0)) {
|
2010-01-24 21:05:12 +00:00
|
|
|
if (data->cy == screen_size_y(s) - 1)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
2010-01-24 21:05:12 +00:00
|
|
|
else
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy, 2);
|
2010-01-24 21:05:12 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 08:47:27 +00:00
|
|
|
if (data->screen.sel == NULL || !data->rectflag) {
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
px = window_copy_find_length(wme, py);
|
2010-03-01 23:53:27 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2020-12-22 09:22:14 +00:00
|
|
|
{
|
|
|
|
window_copy_update_cursor(wme, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
|
|
|
}
|
2010-02-22 20:28:21 +00:00
|
|
|
}
|
2014-11-06 09:17:25 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT)
|
2020-12-22 09:22:14 +00:00
|
|
|
{
|
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
if (data->rectflag)
|
|
|
|
px = screen_size_x(data->backing);
|
|
|
|
else
|
|
|
|
px = window_copy_find_length(wme, py);
|
|
|
|
window_copy_update_cursor(wme, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
|
|
|
}
|
2018-07-31 11:49:26 +00:00
|
|
|
else if (data->lineflag == LINE_SEL_RIGHT_LEFT)
|
2020-12-22 09:22:14 +00:00
|
|
|
{
|
|
|
|
window_copy_update_cursor(wme, 0, data->cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_down(struct window_mode_entry *wme, int scroll_only)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
ox = window_copy_find_length(wme, oy);
|
2012-03-11 23:01:19 +00:00
|
|
|
if (data->cx != ox) {
|
2009-08-21 07:33:58 +00:00
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->lineflag == LINE_SEL_RIGHT_LEFT && oy == data->endsely)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_other_end(wme);
|
2014-11-06 09:17:25 +00:00
|
|
|
|
2009-10-06 07:09:00 +00:00
|
|
|
if (scroll_only || data->cy == screen_size_y(s) - 1) {
|
2019-06-13 20:38:05 +00:00
|
|
|
data->cx = data->lastcx;
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_scroll_up(wme, 1);
|
2009-10-20 21:35:25 +00:00
|
|
|
if (scroll_only && data->cy > 0)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy - 1, 2);
|
2009-10-06 07:09:00 +00:00
|
|
|
} else {
|
2019-06-13 20:38:05 +00:00
|
|
|
window_copy_update_cursor(wme, data->lastcx, data->cy + 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_lines(wme, data->cy - 1, 2);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->screen.sel == NULL || !data->rectflag) {
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
px = window_copy_find_length(wme, py);
|
2010-03-01 23:53:27 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2020-12-22 09:22:14 +00:00
|
|
|
{
|
|
|
|
window_copy_update_cursor(wme, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
|
|
|
}
|
2010-02-22 20:28:21 +00:00
|
|
|
}
|
2014-11-06 09:17:25 +00:00
|
|
|
|
2018-07-31 11:49:26 +00:00
|
|
|
if (data->lineflag == LINE_SEL_LEFT_RIGHT)
|
2020-12-22 09:22:14 +00:00
|
|
|
{
|
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
if (data->rectflag)
|
|
|
|
px = screen_size_x(data->backing);
|
|
|
|
else
|
|
|
|
px = window_copy_find_length(wme, py);
|
|
|
|
window_copy_update_cursor(wme, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
|
|
|
}
|
2018-07-31 11:49:26 +00:00
|
|
|
else if (data->lineflag == LINE_SEL_RIGHT_LEFT)
|
2020-12-22 09:22:14 +00:00
|
|
|
{
|
|
|
|
window_copy_update_cursor(wme, 0, data->cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
|
|
|
window_copy_redraw_lines(wme, data->cy, 1);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_jump(struct window_mode_entry *wme)
|
2010-03-22 19:10:42 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2021-02-22 06:53:04 +00:00
|
|
|
struct grid_reader gr;
|
|
|
|
u_int px, py, oldy, hsize;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
|
|
|
px = data->cx + 1;
|
2021-02-22 06:53:04 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
|
|
|
oldy = data->cy;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
2021-02-22 06:53:04 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
if (grid_reader_cursor_jump(&gr, data->jumpchar)) {
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
|
|
|
window_copy_acquire_cursor_down(wme, hsize,
|
|
|
|
screen_size_y(back_s), data->oy, oldy, px, py, 0);
|
2010-03-22 19:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_jump_back(struct window_mode_entry *wme)
|
2010-03-22 19:10:42 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2021-02-22 06:53:04 +00:00
|
|
|
struct grid_reader gr;
|
|
|
|
u_int px, py, oldy, hsize;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2021-02-22 06:53:04 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
|
|
|
oldy = data->cy;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
2021-02-22 06:53:04 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
2021-04-05 08:43:48 +00:00
|
|
|
grid_reader_cursor_left(&gr, 0);
|
2021-02-22 06:53:04 +00:00
|
|
|
if (grid_reader_cursor_jump_back(&gr, data->jumpchar)) {
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
|
|
|
window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px,
|
|
|
|
py);
|
2010-03-22 19:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_jump_to(struct window_mode_entry *wme)
|
2011-12-04 16:18:01 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2011-12-04 16:18:01 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2021-02-22 06:53:04 +00:00
|
|
|
struct grid_reader gr;
|
|
|
|
u_int px, py, oldy, hsize;
|
2011-12-04 16:18:01 +00:00
|
|
|
|
2017-09-13 07:31:07 +00:00
|
|
|
px = data->cx + 2;
|
2021-02-22 06:53:04 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
|
|
|
oldy = data->cy;
|
2011-12-04 16:18:01 +00:00
|
|
|
|
2021-02-22 06:53:04 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
if (grid_reader_cursor_jump(&gr, data->jumpchar)) {
|
2021-04-05 08:43:48 +00:00
|
|
|
grid_reader_cursor_left(&gr, 1);
|
2021-02-22 06:53:04 +00:00
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
|
|
|
window_copy_acquire_cursor_down(wme, hsize,
|
|
|
|
screen_size_y(back_s), data->oy, oldy, px, py, 0);
|
2011-12-04 16:18:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_jump_to_back(struct window_mode_entry *wme)
|
2011-12-04 16:18:01 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2011-12-04 16:18:01 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2021-02-22 06:53:04 +00:00
|
|
|
struct grid_reader gr;
|
|
|
|
u_int px, py, oldy, hsize;
|
2011-12-04 16:18:01 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2021-02-22 06:53:04 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
|
|
|
oldy = data->cy;
|
2011-12-04 16:18:01 +00:00
|
|
|
|
2021-02-22 06:53:04 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
2021-04-05 08:43:48 +00:00
|
|
|
grid_reader_cursor_left(&gr, 0);
|
|
|
|
grid_reader_cursor_left(&gr, 0);
|
2021-02-22 06:53:04 +00:00
|
|
|
if (grid_reader_cursor_jump_back(&gr, data->jumpchar)) {
|
|
|
|
grid_reader_cursor_right(&gr, 1, 0);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
|
|
|
window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px,
|
|
|
|
py);
|
2011-12-04 16:18:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_next_word(struct window_mode_entry *wme,
|
|
|
|
const char *separators)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2021-01-22 10:21:24 +00:00
|
|
|
struct grid_reader gr;
|
2021-02-22 06:53:04 +00:00
|
|
|
u_int px, py, oldy, hsize;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
px = data->cx;
|
2021-01-22 10:21:24 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
|
|
|
oldy = data->cy;
|
2010-02-22 20:41:16 +00:00
|
|
|
|
2021-01-22 10:21:24 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
grid_reader_cursor_next_word(&gr, separators);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2021-02-22 06:53:04 +00:00
|
|
|
window_copy_acquire_cursor_down(wme, hsize, screen_size_y(back_s),
|
|
|
|
data->oy, oldy, px, py, 0);
|
2010-01-27 20:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 08:24:09 +00:00
|
|
|
/* Compute the next place where a word ends. */
|
2020-02-24 09:53:59 +00:00
|
|
|
static void
|
|
|
|
window_copy_cursor_next_word_end_pos(struct window_mode_entry *wme,
|
|
|
|
const char *separators, u_int *ppx, u_int *ppy)
|
|
|
|
{
|
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
struct options *oo = wp->window->options;
|
|
|
|
struct screen *back_s = data->backing;
|
2021-03-09 08:24:09 +00:00
|
|
|
struct grid_reader gr;
|
|
|
|
u_int px, py, hsize;
|
|
|
|
int keys;
|
2020-02-24 09:53:59 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2021-03-09 08:24:09 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
2020-02-24 09:53:59 +00:00
|
|
|
|
2021-03-09 08:24:09 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
2020-02-24 09:53:59 +00:00
|
|
|
keys = options_get_number(oo, "mode-keys");
|
2021-03-09 08:24:09 +00:00
|
|
|
if (keys == MODEKEY_VI && !grid_reader_in_set(&gr, separators))
|
|
|
|
grid_reader_cursor_right(&gr, 0, 0);
|
|
|
|
grid_reader_cursor_next_word_end(&gr, separators);
|
|
|
|
if (keys == MODEKEY_VI)
|
2021-04-05 08:43:48 +00:00
|
|
|
grid_reader_cursor_left(&gr, 1);
|
2021-03-09 08:24:09 +00:00
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2020-02-24 09:53:59 +00:00
|
|
|
*ppx = px;
|
|
|
|
*ppy = py;
|
|
|
|
}
|
|
|
|
|
2021-03-09 08:24:09 +00:00
|
|
|
/* Move to the next place where a word ends. */
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_next_word_end(struct window_mode_entry *wme,
|
2020-03-20 13:12:04 +00:00
|
|
|
const char *separators, int no_reset)
|
2010-01-27 20:18:52 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2015-10-27 15:58:42 +00:00
|
|
|
struct options *oo = wp->window->options;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2020-12-22 09:22:14 +00:00
|
|
|
struct grid_reader gr;
|
2021-02-22 06:53:04 +00:00
|
|
|
u_int px, py, oldy, hsize;
|
2020-12-22 09:22:14 +00:00
|
|
|
int keys;
|
2010-01-27 20:18:52 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2020-12-22 09:22:14 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
|
|
|
py = hsize + data->cy - data->oy;
|
2021-01-22 10:21:24 +00:00
|
|
|
oldy = data->cy;
|
2010-01-27 20:18:52 +00:00
|
|
|
|
2020-12-22 09:22:14 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
2013-07-12 09:52:36 +00:00
|
|
|
keys = options_get_number(oo, "mode-keys");
|
2020-12-22 09:22:14 +00:00
|
|
|
if (keys == MODEKEY_VI && !grid_reader_in_set(&gr, separators))
|
|
|
|
grid_reader_cursor_right(&gr, 0, 0);
|
|
|
|
grid_reader_cursor_next_word_end(&gr, separators);
|
|
|
|
if (keys == MODEKEY_VI)
|
2021-04-05 08:43:48 +00:00
|
|
|
grid_reader_cursor_left(&gr, 1);
|
2020-12-22 09:22:14 +00:00
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2021-02-22 06:53:04 +00:00
|
|
|
window_copy_acquire_cursor_down(wme, hsize, screen_size_y(back_s),
|
|
|
|
data->oy, oldy, px, py, no_reset);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 09:53:59 +00:00
|
|
|
/* Compute the previous place where a word begins. */
|
|
|
|
static void
|
|
|
|
window_copy_cursor_previous_word_pos(struct window_mode_entry *wme,
|
|
|
|
const char *separators, int already, u_int *ppx, u_int *ppy)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2021-03-09 08:24:09 +00:00
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
struct grid_reader gr;
|
2020-11-10 08:16:52 +00:00
|
|
|
u_int px, py, hsize;
|
2020-02-24 09:53:59 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2021-03-09 08:24:09 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
2020-11-10 08:16:52 +00:00
|
|
|
py = hsize + data->cy - data->oy;
|
2020-02-24 09:53:59 +00:00
|
|
|
|
2021-03-09 08:24:09 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
grid_reader_cursor_previous_word(&gr, separators, already);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2020-02-24 09:53:59 +00:00
|
|
|
*ppx = px;
|
|
|
|
*ppy = py;
|
|
|
|
}
|
|
|
|
|
2009-07-27 07:42:45 +00:00
|
|
|
/* Move to the previous place where a word begins. */
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_cursor_previous_word(struct window_mode_entry *wme,
|
2019-08-01 14:30:31 +00:00
|
|
|
const char *separators, int already)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2020-12-22 09:22:14 +00:00
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
struct grid_reader gr;
|
2021-02-22 06:53:04 +00:00
|
|
|
u_int px, py, oldy, hsize;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
px = data->cx;
|
2020-12-22 09:22:14 +00:00
|
|
|
hsize = screen_hsize(back_s);
|
2020-11-10 08:16:52 +00:00
|
|
|
py = hsize + data->cy - data->oy;
|
2021-01-22 10:21:24 +00:00
|
|
|
oldy = data->cy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-12-22 09:22:14 +00:00
|
|
|
grid_reader_start(&gr, back_s->grid, px, py);
|
|
|
|
grid_reader_cursor_previous_word(&gr, separators, already);
|
|
|
|
grid_reader_get_cursor(&gr, &px, &py);
|
2021-02-22 06:53:04 +00:00
|
|
|
window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px, py);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_scroll_up(struct window_mode_entry *wme, u_int ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
|
|
|
|
if (data->oy < ny)
|
|
|
|
ny = data->oy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy -= ny;
|
|
|
|
|
2020-04-02 17:03:10 +00:00
|
|
|
if (data->searchmark != NULL && !data->timeout)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 0, 0);
|
2013-11-08 12:39:20 +00:00
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, NULL);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, 0, 0, 0);
|
2016-10-13 20:27:27 +00:00
|
|
|
screen_write_deleteline(&ctx, ny, 8);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_lines(wme, &ctx, screen_size_y(s) - ny, ny);
|
|
|
|
window_copy_write_line(wme, &ctx, 0);
|
2009-10-20 21:35:25 +00:00
|
|
|
if (screen_size_y(s) > 1)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, &ctx, 1);
|
2009-10-20 21:35:25 +00:00
|
|
|
if (screen_size_y(s) > 3)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, &ctx, screen_size_y(s) - 2);
|
2018-07-31 11:49:26 +00:00
|
|
|
if (s->sel != NULL && screen_size_y(s) > ny)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, &ctx, screen_size_y(s) - ny - 1);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_scroll_down(struct window_mode_entry *wme, u_int ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp = wme->wp;
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
if (ny > screen_hsize(data->backing))
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
if (data->oy > screen_hsize(data->backing) - ny)
|
|
|
|
ny = screen_hsize(data->backing) - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy += ny;
|
|
|
|
|
2020-04-02 17:03:10 +00:00
|
|
|
if (data->searchmark != NULL && !data->timeout)
|
2020-06-04 20:41:57 +00:00
|
|
|
window_copy_search_marks(wme, NULL, data->searchregex, 1);
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 0, 0);
|
2013-11-08 12:39:20 +00:00
|
|
|
|
2020-05-16 15:34:08 +00:00
|
|
|
screen_write_start_pane(&ctx, wp, NULL);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, 0, 0, 0);
|
2016-10-13 20:27:27 +00:00
|
|
|
screen_write_insertline(&ctx, ny, 8);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_lines(wme, &ctx, 0, ny);
|
2018-07-31 11:49:26 +00:00
|
|
|
if (s->sel != NULL && screen_size_y(s) > ny)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, &ctx, ny);
|
2013-11-08 12:39:20 +00:00
|
|
|
else if (ny == 1) /* nuke position */
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_write_line(wme, &ctx, 1);
|
2019-03-12 20:02:47 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2021-01-22 10:24:52 +00:00
|
|
|
window_copy_rectangle_set(struct window_mode_entry *wme, int rectflag)
|
2010-02-06 17:35:01 +00:00
|
|
|
{
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_copy_mode_data *data = wme->data;
|
2010-02-22 20:28:21 +00:00
|
|
|
u_int px, py;
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2021-01-22 10:24:52 +00:00
|
|
|
data->rectflag = rectflag;
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2019-03-07 20:24:21 +00:00
|
|
|
px = window_copy_find_length(wme, py);
|
2010-02-22 20:28:21 +00:00
|
|
|
if (data->cx > px)
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_update_cursor(wme, px, data->cy);
|
2010-02-22 20:28:21 +00:00
|
|
|
|
2020-03-19 13:28:52 +00:00
|
|
|
window_copy_update_selection(wme, 1, 0);
|
2019-03-07 20:24:21 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2010-02-06 17:35:01 +00:00
|
|
|
}
|
2015-04-19 21:34:21 +00:00
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2016-10-11 09:30:36 +00:00
|
|
|
window_copy_move_mouse(struct mouse_event *m)
|
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_pane *wp;
|
|
|
|
struct window_mode_entry *wme;
|
|
|
|
u_int x, y;
|
2016-10-11 09:30:36 +00:00
|
|
|
|
|
|
|
wp = cmd_mouse_pane(m, NULL, NULL);
|
2019-03-12 11:16:49 +00:00
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
2019-05-15 19:25:53 +00:00
|
|
|
if (wme == NULL)
|
|
|
|
return;
|
|
|
|
if (wme->mode != &window_copy_mode && wme->mode != &window_view_mode)
|
2016-10-11 09:30:36 +00:00
|
|
|
return;
|
|
|
|
|
2017-09-04 09:18:51 +00:00
|
|
|
if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
|
2016-10-11 09:30:36 +00:00
|
|
|
return;
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
window_copy_update_cursor(wme, x, y);
|
2016-10-11 09:30:36 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
void
|
2015-11-18 14:27:44 +00:00
|
|
|
window_copy_start_drag(struct client *c, struct mouse_event *m)
|
2015-04-19 21:34:21 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_pane *wp;
|
|
|
|
struct window_mode_entry *wme;
|
2020-02-24 09:53:59 +00:00
|
|
|
struct window_copy_mode_data *data;
|
2020-03-11 18:46:42 +00:00
|
|
|
u_int x, y, yg;
|
2015-04-19 21:34:21 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
if (c == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
wp = cmd_mouse_pane(m, NULL, NULL);
|
2019-03-12 11:16:49 +00:00
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
2019-05-15 19:25:53 +00:00
|
|
|
if (wme == NULL)
|
|
|
|
return;
|
|
|
|
if (wme->mode != &window_copy_mode && wme->mode != &window_view_mode)
|
2015-04-19 21:34:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (cmd_mouse_at(wp, m, &x, &y, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
c->tty.mouse_drag_update = window_copy_drag_update;
|
2019-04-25 06:34:57 +00:00
|
|
|
c->tty.mouse_drag_release = window_copy_drag_release;
|
2015-04-19 21:34:21 +00:00
|
|
|
|
2020-02-24 09:53:59 +00:00
|
|
|
data = wme->data;
|
2020-03-11 18:46:42 +00:00
|
|
|
yg = screen_hsize(data->backing) + y - data->oy;
|
|
|
|
if (x < data->selrx || x > data->endselrx || yg != data->selry)
|
|
|
|
data->selflag = SEL_CHAR;
|
2020-02-24 09:53:59 +00:00
|
|
|
switch (data->selflag) {
|
2021-01-18 11:14:23 +00:00
|
|
|
case SEL_WORD:
|
|
|
|
if (data->ws != NULL) {
|
2020-02-24 09:53:59 +00:00
|
|
|
window_copy_update_cursor(wme, x, y);
|
2021-01-18 11:14:23 +00:00
|
|
|
window_copy_cursor_previous_word_pos(wme, data->ws, 0,
|
|
|
|
&x, &y);
|
|
|
|
y -= screen_hsize(data->backing) - data->oy;
|
|
|
|
}
|
|
|
|
window_copy_update_cursor(wme, x, y);
|
|
|
|
break;
|
|
|
|
case SEL_LINE:
|
|
|
|
window_copy_update_cursor(wme, 0, y);
|
|
|
|
break;
|
|
|
|
case SEL_CHAR:
|
|
|
|
window_copy_update_cursor(wme, x, y);
|
|
|
|
window_copy_start_selection(wme);
|
|
|
|
break;
|
2020-02-24 09:53:59 +00:00
|
|
|
}
|
2019-05-03 18:42:40 +00:00
|
|
|
|
2020-02-24 09:53:59 +00:00
|
|
|
window_copy_redraw_screen(wme);
|
2019-05-03 18:42:40 +00:00
|
|
|
window_copy_drag_update(c, m);
|
2015-04-19 21:34:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2019-03-12 11:16:49 +00:00
|
|
|
window_copy_drag_update(struct client *c, struct mouse_event *m)
|
2015-04-19 21:34:21 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme;
|
2015-04-19 21:34:21 +00:00
|
|
|
struct window_copy_mode_data *data;
|
2019-04-25 06:34:57 +00:00
|
|
|
u_int x, y, old_cx, old_cy;
|
|
|
|
struct timeval tv = {
|
|
|
|
.tv_usec = WINDOW_COPY_DRAG_REPEAT_TIME
|
|
|
|
};
|
2015-04-19 21:34:21 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
if (c == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
wp = cmd_mouse_pane(m, NULL, NULL);
|
2019-03-12 11:16:49 +00:00
|
|
|
if (wp == NULL)
|
2015-04-19 21:34:21 +00:00
|
|
|
return;
|
2019-03-12 11:16:49 +00:00
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
2019-05-15 19:25:53 +00:00
|
|
|
if (wme == NULL)
|
|
|
|
return;
|
|
|
|
if (wme->mode != &window_copy_mode && wme->mode != &window_view_mode)
|
2019-03-12 11:16:49 +00:00
|
|
|
return;
|
2019-04-25 06:34:57 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
data = wme->data;
|
2019-04-25 06:34:57 +00:00
|
|
|
evtimer_del(&data->dragtimer);
|
2015-04-19 21:34:21 +00:00
|
|
|
|
|
|
|
if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
|
|
|
|
return;
|
2019-04-25 06:34:57 +00:00
|
|
|
old_cx = data->cx;
|
2015-04-19 21:34:21 +00:00
|
|
|
old_cy = data->cy;
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
window_copy_update_cursor(wme, x, y);
|
2020-03-19 13:28:52 +00:00
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
2019-03-12 11:16:49 +00:00
|
|
|
window_copy_redraw_selection(wme, old_cy);
|
2019-04-25 06:34:57 +00:00
|
|
|
if (old_cy != data->cy || old_cx == data->cx) {
|
|
|
|
if (y == 0) {
|
|
|
|
evtimer_add(&data->dragtimer, &tv);
|
|
|
|
window_copy_cursor_up(wme, 1);
|
|
|
|
} else if (y == screen_size_y(&data->screen) - 1) {
|
|
|
|
evtimer_add(&data->dragtimer, &tv);
|
|
|
|
window_copy_cursor_down(wme, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_drag_release(struct client *c, struct mouse_event *m)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
struct window_mode_entry *wme;
|
|
|
|
struct window_copy_mode_data *data;
|
|
|
|
|
|
|
|
if (c == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wp = cmd_mouse_pane(m, NULL, NULL);
|
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
2019-05-15 19:25:53 +00:00
|
|
|
if (wme == NULL)
|
|
|
|
return;
|
|
|
|
if (wme->mode != &window_copy_mode && wme->mode != &window_view_mode)
|
2019-04-25 06:34:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
data = wme->data;
|
|
|
|
evtimer_del(&data->dragtimer);
|
2015-04-19 21:34:21 +00:00
|
|
|
}
|
2020-05-16 16:10:28 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
window_copy_jump_to_mark(struct window_mode_entry *wme)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wme->data;
|
|
|
|
u_int tmx, tmy;
|
|
|
|
|
|
|
|
tmx = data->cx;
|
|
|
|
tmy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
data->cx = data->mx;
|
|
|
|
if (data->my < screen_hsize(data->backing)) {
|
|
|
|
data->cy = 0;
|
|
|
|
data->oy = screen_hsize(data->backing) - data->my;
|
|
|
|
} else {
|
|
|
|
data->cy = data->my - screen_hsize(data->backing);
|
|
|
|
data->oy = 0;
|
|
|
|
}
|
|
|
|
data->mx = tmx;
|
|
|
|
data->my = tmy;
|
|
|
|
data->showmark = 1;
|
|
|
|
window_copy_update_selection(wme, 0, 0);
|
|
|
|
window_copy_redraw_screen(wme);
|
|
|
|
}
|
2021-02-22 06:53:04 +00:00
|
|
|
|
|
|
|
/* Scroll up if the cursor went off the visible screen. */
|
|
|
|
static void
|
|
|
|
window_copy_acquire_cursor_up(struct window_mode_entry *wme, u_int hsize,
|
|
|
|
u_int oy, u_int oldy, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
u_int cy, yy, ny, nd;
|
|
|
|
|
|
|
|
yy = hsize - oy;
|
|
|
|
if (py < yy) {
|
|
|
|
ny = yy - py;
|
|
|
|
cy = 0;
|
|
|
|
nd = 1;
|
|
|
|
} else {
|
|
|
|
ny = 0;
|
|
|
|
cy = py - yy;
|
|
|
|
nd = oldy - cy + 1;
|
|
|
|
}
|
|
|
|
while (ny > 0) {
|
|
|
|
window_copy_cursor_up(wme, 1);
|
|
|
|
ny--;
|
|
|
|
}
|
|
|
|
window_copy_update_cursor(wme, px, cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, 0))
|
|
|
|
window_copy_redraw_lines(wme, cy, nd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll down if the cursor went off the visible screen. */
|
|
|
|
static void
|
|
|
|
window_copy_acquire_cursor_down(struct window_mode_entry *wme, u_int hsize,
|
|
|
|
u_int sy, u_int oy, u_int oldy, u_int px, u_int py, int no_reset)
|
|
|
|
{
|
|
|
|
u_int cy, yy, ny, nd;
|
|
|
|
|
|
|
|
cy = py - hsize + oy;
|
|
|
|
yy = sy - 1;
|
|
|
|
if (cy > yy) {
|
|
|
|
ny = cy - yy;
|
|
|
|
oldy = yy;
|
|
|
|
nd = 1;
|
|
|
|
} else {
|
|
|
|
ny = 0;
|
|
|
|
nd = cy - oldy + 1;
|
|
|
|
}
|
|
|
|
while (ny > 0) {
|
|
|
|
window_copy_cursor_down(wme, 1);
|
|
|
|
ny--;
|
|
|
|
}
|
|
|
|
if (cy > yy)
|
|
|
|
window_copy_update_cursor(wme, px, yy);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(wme, px, cy);
|
|
|
|
if (window_copy_update_selection(wme, 1, no_reset))
|
|
|
|
window_copy_redraw_lines(wme, oldy, nd);
|
|
|
|
}
|