git: 90b89100548f - main - vt(4): When cutting a line, append a newline character.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Wed, 05 Oct 2022 09:54:47 UTC
The branch main has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=90b89100548f7fef4cbd4a8c76dc3d83ab786d7a

commit 90b89100548f7fef4cbd4a8c76dc3d83ab786d7a
Author:     Ivan Quitschal <tezeka@hotmail.com>
AuthorDate: 2022-10-05 09:20:54 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-10-05 09:51:48 +0000

    vt(4): When cutting a line, append a newline character.
    
    While at it optimise "case 3" into a default.
    This way there is no need to initialize the "mark" variable in the beginning,
    because all cases set it.
    
    MFC after:      1 week
    Sponsored by:   NVIDIA Networking
    Differential Revision:  https://reviews.freebsd.org/D36042
---
 sys/dev/vt/vt.h      | 2 +-
 sys/dev/vt/vt_buf.c  | 6 +++---
 sys/dev/vt/vt_core.c | 5 ++---
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/sys/dev/vt/vt.h b/sys/dev/vt/vt.h
index 7305727804cf..977372f04a7d 100644
--- a/sys/dev/vt/vt.h
+++ b/sys/dev/vt/vt.h
@@ -239,7 +239,7 @@ void vtbuf_cursor_visibility(struct vt_buf *, int);
 #ifndef SC_NO_CUTPASTE
 int vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row);
 int vtbuf_get_marked_len(struct vt_buf *vb);
-void vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz);
+void vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz, int mark);
 #endif
 
 #define	VTB_MARK_NONE		0
diff --git a/sys/dev/vt/vt_buf.c b/sys/dev/vt/vt_buf.c
index b83db85f1cdb..88e4fc472f9d 100644
--- a/sys/dev/vt/vt_buf.c
+++ b/sys/dev/vt/vt_buf.c
@@ -742,7 +742,7 @@ vtbuf_get_marked_len(struct vt_buf *vb)
 	ei = e.tp_row * vb->vb_scr_size.tp_col + e.tp_col;
 
 	/* Number symbols and number of rows to inject \r */
-	sz = ei - si + (e.tp_row - s.tp_row);
+	sz = ei - si + (1 + e.tp_row - s.tp_row);
 
 	return (sz * sizeof(term_char_t));
 }
@@ -771,7 +771,7 @@ tchar_is_word_separator(term_char_t ch)
 }
 
 void
-vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz)
+vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz, int mark)
 {
 	int i, j, r, c, cs, ce;
 	term_pos_t s, e;
@@ -799,7 +799,7 @@ vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz)
 			buf[i++] = vb->vb_rows[r][c];
 
 		/* For all rows, but the last one. */
-		if (r != e.tp_row) {
+		if (r != e.tp_row || mark == VTB_MARK_ROW) {
 			/* Trim trailing word separators, if any. */
 			for (; i != j; i--) {
 				if (!tchar_is_word_separator(buf[i - 1]))
diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c
index 06503e8897aa..f0ea59e134ac 100644
--- a/sys/dev/vt/vt_core.c
+++ b/sys/dev/vt/vt_core.c
@@ -2153,7 +2153,6 @@ vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
 	vd = main_vd;
 	vw = vd->vd_curwindow;
 	vf = vw->vw_font;
-	mark = 0;
 
 	if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS))
 		/*
@@ -2217,7 +2216,7 @@ vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
 		case 2:	/* double click: cut a word */
 			mark = VTB_MARK_WORD;
 			break;
-		case 3:	/* triple click: cut a line */
+		default:	/* triple click: cut a line */
 			mark = VTB_MARK_ROW;
 			break;
 		}
@@ -2286,7 +2285,7 @@ vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
 			VD_PASTEBUFSZ(vd) = len;
 		}
 		/* Request copy/paste buffer data, no more than `len' */
-		vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd), len);
+		vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd), len, mark);
 
 		VD_PASTEBUFLEN(vd) = len;