commit d4a1dbd4a9a5724238f42688f8716b593ebc17bb
parent 0e9bef3429e92e9d9c6a087f741828b35329f242
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 22 Jul 2022 09:11:31 +0200
tweaks: rename two variables, to not contain the name of another
Also, elide an unneeded condition: when not softwrapping, left_x will
be zero, which is always smaller than or equal to the indentation.
Furthermore, reshuffle a few lines, improve three comments, and adjust
one to mention the parameter that was added in the previous commit.
Diffstat:
2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/src/move.c b/src/move.c
@@ -410,12 +410,12 @@ void do_home(void)
bool moved_off_chunk = TRUE;
#ifndef NANO_TINY
bool moved = FALSE;
- size_t leftedge = 0, leftedge_x = 0;
+ size_t leftedge = 0;
+ size_t left_x = 0;
if (ISSET(SOFTWRAP)) {
leftedge = leftedge_for(was_column, openfile->current);
- leftedge_x = proper_x(openfile->current, &leftedge, FALSE, leftedge,
- NULL);
+ left_x = proper_x(openfile->current, &leftedge, FALSE, leftedge, NULL);
}
if (ISSET(SMART_HOME)) {
@@ -428,7 +428,7 @@ void do_home(void)
if (openfile->current_x == indent_x) {
openfile->current_x = 0;
moved = TRUE;
- } else if (!ISSET(SOFTWRAP) || leftedge_x <= indent_x) {
+ } else if (left_x <= indent_x) {
openfile->current_x = indent_x;
moved = TRUE;
}
@@ -438,10 +438,10 @@ void do_home(void)
if (!moved && ISSET(SOFTWRAP)) {
/* If already at the left edge of the screen, move fully home.
* Otherwise, move to the left edge. */
- if (openfile->current_x == leftedge_x)
+ if (openfile->current_x == left_x)
openfile->current_x = 0;
else {
- openfile->current_x = leftedge_x;
+ openfile->current_x = left_x;
openfile->placewewant = leftedge;
moved_off_chunk = FALSE;
}
@@ -477,7 +477,7 @@ void do_end(void)
size_t leftedge = leftedge_for(was_column, openfile->current);
size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
leftedge, &kickoff, &last_chunk);
- size_t rightedge_x;
+ size_t right_x;
/* If we're on the last chunk, we're already at the end of the line.
* Otherwise, we're one column past the end of the line. Shifting
@@ -486,14 +486,14 @@ void do_end(void)
if (!last_chunk)
rightedge--;
- rightedge_x = actual_x(openfile->current->data, rightedge);
+ right_x = actual_x(openfile->current->data, rightedge);
/* If already at the right edge of the screen, move fully to
* the end of the line. Otherwise, move to the right edge. */
- if (openfile->current_x == rightedge_x)
+ if (openfile->current_x == right_x)
openfile->current_x = line_len;
else {
- openfile->current_x = rightedge_x;
+ openfile->current_x = right_x;
openfile->placewewant = rightedge;
moved_off_chunk = FALSE;
}
diff --git a/src/winio.c b/src/winio.c
@@ -3071,10 +3071,11 @@ void edit_scroll(bool direction)
}
#ifndef NANO_TINY
-/* Get the column number after leftedge where we can break the given text, and
- * return it. This will always be editwincols or less after leftedge. Set
- * end_of_line to TRUE if we reach the end of the line while searching the
- * text. Assume leftedge is the leftmost column of a softwrapped chunk. */
+/* Get the column number after leftedge where we can break the given linedata,
+ * and return it. (This will always be at most editwincols after leftedge.)
+ * When kickoff is TRUE, start at the beginning of the linedata; otherwise,
+ * continue from where the previous call left off. Set end_of_line to TRUE
+ * when end-of-line is reached while searching for a possible breakpoint. */
size_t get_softwrap_breakpoint(const char *linedata, size_t leftedge,
bool *kickoff, bool *end_of_line)
{
@@ -3138,27 +3139,29 @@ size_t get_softwrap_breakpoint(const char *linedata, size_t leftedge,
return (editwincols > 1) ? breaking_col : column - 1;
}
-/* Get the row of the softwrapped chunk of the given line that column is on,
- * relative to the first row (zero-based), and return it. If leftedge isn't
- * NULL, return the leftmost column of the chunk in it. */
+/* Return the row number of the softwrapped chunk in the given line that the
+ * given column is on, relative to the first row (zero-based). If leftedge
+ * isn't NULL, return in it the leftmost column of the chunk. */
size_t get_chunk_and_edge(size_t column, linestruct *line, size_t *leftedge)
{
- size_t current_chunk = 0, start_col = 0, end_col;
+ size_t current_chunk = 0;
bool end_of_line = FALSE;
bool kickoff = TRUE;
+ size_t start_col = 0;
+ size_t end_col;
while (TRUE) {
end_col = get_softwrap_breakpoint(line->data, start_col, &kickoff, &end_of_line);
- /* We reached the end of the line and/or found column, so get out. */
+ /* When the column is in range or we reached end-of-line, we're done. */
if (end_of_line || (start_col <= column && column < end_col)) {
if (leftedge != NULL)
*leftedge = start_col;
return current_chunk;
}
- current_chunk++;
start_col = end_col;
+ current_chunk++;
}
}