summaryrefslogtreecommitdiffstats
path: root/grid-reader.c
diff options
context:
space:
mode:
authornicm <nicm>2021-04-05 08:43:48 +0000
committernicm <nicm>2021-04-05 08:43:48 +0000
commit5900b164a47689620db962e69f6d040bb82885b0 (patch)
tree9016136aca185c88caac3b7f0a4164272376a388 /grid-reader.c
parent28cd956729c13f8f66e26d438592df9c9930e7b8 (diff)
Fix a couple of edge cases with the jump-back-xxx commands, and also
update back-to-indentation to use grid_reader, thereby fixing line wrapping issues. From Anindya Mukherjee, GitHub issue 2633.
Diffstat (limited to 'grid-reader.c')
-rw-r--r--grid-reader.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/grid-reader.c b/grid-reader.c
index ae2f4d2b..89fe90fb 100644
--- a/grid-reader.c
+++ b/grid-reader.c
@@ -71,7 +71,7 @@ grid_reader_cursor_right(struct grid_reader *gr, int wrap, int all)
/* Move cursor back one position. */
void
-grid_reader_cursor_left(struct grid_reader *gr)
+grid_reader_cursor_left(struct grid_reader *gr, int wrap)
{
struct grid_cell gc;
@@ -81,7 +81,9 @@ grid_reader_cursor_left(struct grid_reader *gr)
break;
gr->cx--;
}
- if (gr->cx == 0 && gr->cy > 0) {
+ 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)
@@ -363,3 +365,25 @@ grid_reader_cursor_jump_back(struct grid_reader *gr, const struct utf8_data *jc)
}
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;
+ }
+}