From 0b524a94a5e34148716832f1b6cada02e35369b0 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Mon, 12 Feb 2024 16:28:37 +0100 Subject: Improve word deletion Now it only deletes the word under dot. --- src/dged/buffer.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/dged/buffer.c') diff --git a/src/dged/buffer.c b/src/dged/buffer.c index a512c60..749dba7 100644 --- a/src/dged/buffer.c +++ b/src/dged/buffer.c @@ -328,6 +328,11 @@ static struct match_result find_prev_in_line(struct buffer *buffer, --bytei; } + // first byte on line can also be a match + if (predicate(line.text[bytei])) { + found = true; + } + uint32_t target_col = text_byteindex_to_col(buffer->text, start.line, bytei); return (struct match_result){ .at = (struct location){.line = start.line, .col = target_col}, @@ -595,6 +600,20 @@ struct location buffer_next_char(struct buffer *buffer, struct location dot) { return dot; } +struct region buffer_word_at(struct buffer *buffer, struct location at) { + struct match_result prev_word_break = + find_prev_in_line(buffer, at, is_word_break); + struct match_result next_word_break = + find_next_in_line(buffer, at, is_word_break); + + if (prev_word_break.at.col != next_word_break.at.col && + prev_word_break.found) { + moveh(buffer, 1, &prev_word_break.at); + } + + return region_new(prev_word_break.at, next_word_break.at); +} + struct location buffer_next_word(struct buffer *buffer, struct location dot) { struct match_result res = find_next_in_line(buffer, dot, is_word_break); if (!res.found) { -- cgit v1.2.3