vte r2222 - in trunk: . src



Author: behdad
Date: Sat Nov 29 06:00:17 2008
New Revision: 2222
URL: http://svn.gnome.org/viewvc/vte?rev=2222&view=rev

Log:
2008-11-29  Behdad Esfahbod  <behdad gnome org>

        Bug 514632 â Problem with cursor in emacs in gnome-terminal

        * src/vte-private.h:
        * src/vte.c (_vte_terminal_cleanup_tab_fragments_at_cursor),
        (_vte_terminal_insert_char):
        * src/vteseq.c (vte_sequence_handler_ch),
        (vte_sequence_handler_cm), (vte_sequence_handler_le),
        (vte_sequence_handler_cursor_character_absolute):
        Break "smart tabs" into multiple empty cells when cursor moves
        into them or inserting character there.



Modified:
   trunk/ChangeLog
   trunk/src/vte-private.h
   trunk/src/vte.c
   trunk/src/vteseq.c

Modified: trunk/src/vte-private.h
==============================================================================
--- trunk/src/vte-private.h	(original)
+++ trunk/src/vte-private.h	Sat Nov 29 06:00:17 2008
@@ -445,6 +445,7 @@
 gboolean _vte_terminal_get_tabstop(VteTerminal *terminal, int column);
 void _vte_terminal_set_tabstop(VteTerminal *terminal, int column);
 void _vte_terminal_update_insert_delta(VteTerminal *terminal);
+void _vte_terminal_cleanup_tab_fragments_at_cursor (VteTerminal *terminal);
 
 void _vte_terminal_inline_error_message(VteTerminal *terminal, const char *format, ...) G_GNUC_PRINTF(2,3);
 

Modified: trunk/src/vte.c
==============================================================================
--- trunk/src/vte.c	(original)
+++ trunk/src/vte.c	Sat Nov 29 06:00:17 2008
@@ -2894,6 +2894,42 @@
 	vte_terminal_set_colors(terminal, NULL, NULL, NULL, 0);
 }
 
+
+/* Cleanup smart-tabs.  See vte_sequence_handler_ta */
+inline void
+_vte_terminal_cleanup_tab_fragments_at_cursor (VteTerminal *terminal)
+{
+	VteRowData *row = _vte_terminal_ensure_row (terminal);
+	VteScreen *screen = terminal->pvt->screen;
+	long col = screen->cursor_current.col;
+	struct vte_charcell *cell = _vte_row_data_find_charcell(row, col);
+
+	if (G_UNLIKELY (cell != NULL && cell->c == '\t')) {
+		int i, num_columns;
+		
+		_vte_debug_print(VTE_DEBUG_MISC,
+				 "Cleaning tab fragments at %ld",
+				 col);
+		g_message ("cleaning tab at %ld", col);
+
+		/* go back to the beginning of the tab */
+		while (cell != NULL && cell->attr.fragment && col > 0) {
+			cell = _vte_row_data_find_charcell(row, --col);
+		}
+
+		if (!cell) {
+			/* heck, whatever */
+			return;
+		}
+
+		num_columns = cell->attr.columns;
+		for (i = 0; i < num_columns; i++) {
+			cell = _vte_row_data_find_charcell(row, col++);
+			*cell = screen->fill_defaults;
+		}
+	}
+}
+
 /* Insert a single character into the stored data array. */
 gboolean
 _vte_terminal_insert_char(VteTerminal *terminal, gunichar c,
@@ -2968,14 +3004,38 @@
 	row = vte_terminal_ensure_cursor (terminal);
 	g_assert(row != NULL);
 	if (insert) {
-		g_array_insert_val(row->cells, col,
-				screen->color_defaults);
+		for (i = 0; i < columns; i++)
+			g_array_insert_val(row->cells, col + i,
+					   screen->color_defaults);
 	} else {
 		if (G_LIKELY ((glong) row->cells->len < col + columns)) {
 			g_array_set_size (row->cells, col + columns);
 		}
 	}
 
+	_vte_terminal_cleanup_tab_fragments_at_cursor (terminal);
+
+	/* Convert any wide characters we may have broken into single
+	 * cells. (#514632) */
+	if (col > 0) {
+		glong col2 = col - 1;
+		struct vte_charcell *cell = _vte_row_data_find_charcell(row, col2);
+		while (cell != NULL && cell->attr.fragment && col2 > 0) {
+			cell = _vte_row_data_find_charcell(row, --col2);
+		}
+		cell->attr.columns = col - col2;
+	}
+	{
+		glong col2 = col + columns;
+		struct vte_charcell *cell = _vte_row_data_find_charcell(row, col2);
+		while (cell != NULL && cell->attr.fragment) {
+			cell->attr.fragment = 0;
+			cell->attr.columns = 1;
+			cell->c = 0;
+			cell = _vte_row_data_find_charcell(row, ++col2);
+		}
+	}
+
 	memcpy (&attr, &screen->defaults.attr, sizeof (attr));
 	attr.columns = columns;
 
@@ -2997,12 +3057,8 @@
 	col++;
 
 	/* insert wide-char fragments */
+	attr.fragment = 1;
 	for (i = 1; i < columns; i++) {
-		attr.fragment = 1;
-		if (insert) {
-			g_array_insert_val(row->cells, col,
-				screen->color_defaults);
-		}
 		g_array_index(row->cells, struct vte_charcell, col).c = c;
 		g_array_index(row->cells, struct vte_charcell, col).attr = attr;
 		col++;

Modified: trunk/src/vteseq.c
==============================================================================
--- trunk/src/vteseq.c	(original)
+++ trunk/src/vteseq.c	Sat Nov 29 06:00:17 2008
@@ -1183,6 +1183,7 @@
 				    terminal->column_count - 1);
 			/* Move the cursor. */
 			screen->cursor_current.col = val;
+			_vte_terminal_cleanup_tab_fragments_at_cursor (terminal);
 		}
 	}
 	return FALSE;
@@ -1241,6 +1242,7 @@
 	}
 	screen->cursor_current.row = rowval + screen->insert_delta;
 	screen->cursor_current.col = colval;
+	_vte_terminal_cleanup_tab_fragments_at_cursor (terminal);
 	return FALSE;
 }
 
@@ -1845,6 +1847,7 @@
 	if (screen->cursor_current.col > 0) {
 		/* There's room to move left, so do so. */
 		screen->cursor_current.col--;
+		_vte_terminal_cleanup_tab_fragments_at_cursor (terminal);
 	} else {
 		if (terminal->pvt->flags.bw) {
 			/* Wrap to the previous line. */
@@ -2992,6 +2995,7 @@
 	}
 
         screen->cursor_current.col = val;
+	_vte_terminal_cleanup_tab_fragments_at_cursor (terminal);
 
 	return FALSE;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]