mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Add a helper function for cell data comparison, from Alexander Arch.
This commit is contained in:
		@@ -338,6 +338,18 @@ grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
 | 
				
			|||||||
	gr->cy = oldy;
 | 
						gr->cy = oldy;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Compare grid cell to UTF-8 data. Return 1 if equal, 0 if not. */
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					grid_reader_cell_equals_data(const struct grid_cell *gc,
 | 
				
			||||||
 | 
					    const struct utf8_data *ud)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (gc->flags & GRID_FLAG_PADDING)
 | 
				
			||||||
 | 
							return (0);
 | 
				
			||||||
 | 
						if (gc->data.size != ud->size)
 | 
				
			||||||
 | 
							return (0);
 | 
				
			||||||
 | 
						return (memcmp(gc->data.data, ud->data, gc->data.size) == 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Jump forward to character. */
 | 
					/* Jump forward to character. */
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
 | 
					grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
 | 
				
			||||||
@@ -352,9 +364,7 @@ grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
 | 
				
			|||||||
		xx = grid_line_length(gr->gd, py);
 | 
							xx = grid_line_length(gr->gd, py);
 | 
				
			||||||
		while (px < xx) {
 | 
							while (px < xx) {
 | 
				
			||||||
			grid_get_cell(gr->gd, px, py, &gc);
 | 
								grid_get_cell(gr->gd, px, py, &gc);
 | 
				
			||||||
			if (!(gc.flags & GRID_FLAG_PADDING) &&
 | 
								if (grid_reader_cell_equals_data(&gc, jc)) {
 | 
				
			||||||
			    gc.data.size == jc->size &&
 | 
					 | 
				
			||||||
			    memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
 | 
					 | 
				
			||||||
				gr->cx = px;
 | 
									gr->cx = px;
 | 
				
			||||||
				gr->cy = py;
 | 
									gr->cy = py;
 | 
				
			||||||
				return (1);
 | 
									return (1);
 | 
				
			||||||
@@ -382,9 +392,7 @@ grid_reader_cursor_jump_back(struct grid_reader *gr, const struct utf8_data *jc)
 | 
				
			|||||||
	for (py = gr->cy + 1; py > 0; py--) {
 | 
						for (py = gr->cy + 1; py > 0; py--) {
 | 
				
			||||||
		for (px = xx; px > 0; px--) {
 | 
							for (px = xx; px > 0; px--) {
 | 
				
			||||||
			grid_get_cell(gr->gd, px - 1, py - 1, &gc);
 | 
								grid_get_cell(gr->gd, px - 1, py - 1, &gc);
 | 
				
			||||||
			if (!(gc.flags & GRID_FLAG_PADDING) &&
 | 
								if (grid_reader_cell_equals_data(&gc, jc)) {
 | 
				
			||||||
			    gc.data.size == jc->size &&
 | 
					 | 
				
			||||||
			    memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
 | 
					 | 
				
			||||||
				gr->cx = px - 1;
 | 
									gr->cx = px - 1;
 | 
				
			||||||
				gr->cy = py - 1;
 | 
									gr->cy = py - 1;
 | 
				
			||||||
				return (1);
 | 
									return (1);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user