From 818df923debfcd9194314ee05e64cc62fbbb5458 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 26 Nov 2007 20:36:30 +0000 Subject: Add ^A && ^E to copy mode. Also use STDIN instead of STDOUT in a couple of places. --- window-copy.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'window-copy.c') diff --git a/window-copy.c b/window-copy.c index 0efa72e4..2c2cd090 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1,4 +1,4 @@ -/* $Id: window-copy.c,v 1.6 2007-11-23 17:52:54 nicm Exp $ */ +/* $Id: window-copy.c,v 1.7 2007-11-26 20:36:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -34,6 +34,8 @@ void window_copy_copy_line( struct window *, char **, size_t *, size_t *, u_int, u_int, u_int); u_int window_copy_find_length(struct window *, u_int); void window_copy_move_cursor(struct window *); +void window_copy_cursor_bol(struct window *); +void window_copy_cursor_eol(struct window *); void window_copy_cursor_left(struct window *); void window_copy_cursor_right(struct window *); void window_copy_cursor_up(struct window *); @@ -186,12 +188,21 @@ window_copy_key(struct window *w, int key) data->sely = data->size + data->cy - data->oy; oy = -1; /* XXX */ break; + case '\033': + data->selflag = 0; + oy = -1; /* XXX */ + break; case '\027': /* C-w */ case '\r': /* enter */ if (data->selflag) window_copy_copy_selection(w); goto done; - /* XXX start/end of line, next word, prev word, cancel sel */ + case '\001': /* C-a */ + window_copy_cursor_bol(w); + return; + case '\005': /* C-e */ + window_copy_cursor_eol(w); + return; } if (data->oy != oy) { server_redraw_window_all(w); @@ -337,6 +348,55 @@ window_copy_move_cursor(struct window *w) } } +void +window_copy_cursor_bol(struct window *w) +{ + struct window_copy_mode_data *data = w->modedata; + + if (data->ox != 0) + window_copy_scroll_right(w, data->ox); + data->cx = 0; + window_copy_move_cursor(w); +} + +void +window_copy_cursor_eol(struct window *w) +{ + struct window_copy_mode_data *data = w->modedata; + struct screen *s = &w->screen; + u_int xx; + + xx = window_copy_find_length(w, data->size + data->cy - data->oy); + + /* On screen. */ + if (xx > data->ox && xx < data->ox + screen_last_x(s)) + data->cx = xx - data->ox; + + /* Off right of screen. */ + if (xx > data->ox + screen_last_x(s)) { + /* Move cursor to last and scroll screen. */ + window_copy_scroll_left(w, + xx - data->ox - screen_last_x(s)); + data->cx = screen_last_x(s); + } + + /* Off left of screen. */ + if (xx <= data->ox) { + if (xx < screen_last_x(s)) { + /* Short enough to fit on screen. */ + window_copy_scroll_right(w, data->ox); + data->cx = xx; + } else { + /* Too long to fit on screen. */ + window_copy_scroll_right( + w, data->ox - (xx - screen_last_x(s))); + data->cx = screen_last_x(s); + } + } + + window_copy_move_cursor(w); +} + void window_copy_cursor_left(struct window *w) { -- cgit v1.2.3