terminal: Extend selection to end of line when selecting past last char
diff --git a/clients/terminal.c b/clients/terminal.c
index 504e3c2..a726232 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -1745,6 +1745,12 @@
 static int
 handle_special_char(struct terminal *terminal, char c)
 {
+	union utf8_char *row;
+	struct attr *attr_row;
+
+	row = terminal_get_row(terminal, terminal->row);
+	attr_row = terminal_get_attr_row(terminal, terminal->row);
+
 	switch(c) {
 	case '\r':
 		terminal->column = 0;
@@ -1767,6 +1773,13 @@
 		while (terminal->column < terminal->width) {
 			if (terminal->mode & MODE_IRM)
 				terminal_shift_line(terminal, +1);
+
+			if (row[terminal->column].byte[0] == '\0') {
+				row[terminal->column].byte[0] = ' ';
+				row[terminal->column].byte[1] = '\0';
+				attr_row[terminal->column] = terminal->curr_attr;
+			}
+
 			terminal->column++;
 			if (terminal->tab_ruler[terminal->column]) break;
 		}
@@ -2270,7 +2283,7 @@
 	struct rectangle allocation;
 	int col, x, width, height;
 	int start_row, end_row;
-	int word_start;
+	int word_start, eol;
 	int side_margin, top_margin;
 	int start_x, end_x;
 	int cw, ch;
@@ -2301,6 +2314,7 @@
 		end_x = terminal->selection_start_x;
 	}
 
+	eol = 0;
 	if (terminal->selection_start_row < 0) {
 		terminal->selection_start_row = 0;
 		terminal->selection_start_col = 0;
@@ -2312,6 +2326,8 @@
 		for (col = 0; col < terminal->width; col++, x += cw) {
 			if (col == 0 || wordsep(data[col - 1].ch))
 				word_start = col;
+			if (data[col].ch != 0)
+				eol = col + 1;
 			if (start_x < x)
 				break;
 		}
@@ -2342,10 +2358,19 @@
 			    end_x < x && wordsep(data[col].ch))
 				break;
 		}
-
 		terminal->selection_end_col = col;
 	}
 
+	if (terminal->selection_end_col != terminal->selection_start_col ||
+	    terminal->selection_start_row != terminal->selection_end_row) {
+		col = terminal->selection_end_col;
+		if (col > 0 && data[col - 1].ch == 0)
+			terminal->selection_end_col = terminal->width;
+		data = terminal_get_row(terminal, terminal->selection_start_row);
+		if (data[terminal->selection_start_col].ch == 0)
+			terminal->selection_start_col = eol;
+	}
+
 	return 1;
 }