=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/grid-reader.c,v retrieving revision 1.3 retrieving revision 1.4 diff -c -r1.3 -r1.4 *** src/usr.bin/tmux/grid-reader.c 2021/03/09 08:24:09 1.3 --- src/usr.bin/tmux/grid-reader.c 2021/04/05 08:43:48 1.4 *************** *** 1,4 **** ! /* $OpenBSD: grid-reader.c,v 1.3 2021/03/09 08:24:09 nicm Exp $ */ /* * Copyright (c) 2020 Anindya Mukherjee --- 1,4 ---- ! /* $OpenBSD: grid-reader.c,v 1.4 2021/04/05 08:43:48 nicm Exp $ */ /* * Copyright (c) 2020 Anindya Mukherjee *************** *** 71,77 **** /* Move cursor back one position. */ void ! grid_reader_cursor_left(struct grid_reader *gr) { struct grid_cell gc; --- 71,77 ---- /* Move cursor back one position. */ void ! grid_reader_cursor_left(struct grid_reader *gr, int wrap) { struct grid_cell gc; *************** *** 81,87 **** break; gr->cx--; } ! if (gr->cx == 0 && gr->cy > 0) { grid_reader_cursor_up(gr); grid_reader_cursor_end_of_line(gr, 0, 0); } else if (gr->cx > 0) --- 81,89 ---- break; gr->cx--; } ! if (gr->cx == 0 && gr->cy > 0 && ! (wrap || ! grid_get_line(gr->gd, gr->cy - 1)->flags & GRID_LINE_WRAPPED)) { grid_reader_cursor_up(gr); grid_reader_cursor_end_of_line(gr, 0, 0); } else if (gr->cx > 0) *************** *** 362,365 **** --- 364,389 ---- xx = grid_line_length(gr->gd, py - 2); } return 0; + } + + /* Jump back to the first non-blank character of the line. */ + void + grid_reader_cursor_back_to_indentation(struct grid_reader *gr) + { + struct grid_cell gc; + u_int px, py, xx, yy; + + yy = gr->gd->hsize + gr->gd->sy - 1; + grid_reader_cursor_start_of_line(gr, 1); + + for (py = gr->cy; py <= yy; py++) { + xx = grid_line_length(gr->gd, py); + for (px = 0; px < xx; px++) { + grid_get_cell(gr->gd, px, py, &gc); + if (gc.data.size != 1 || *gc.data.data != ' ') + break; + } + if (~grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED) + break; + } }