Merge branch 'master' of https://git.savannah.gnu.org/git/nano into rexy712
This commit is contained in:
commit
ac58a97a92
23
src/move.c
23
src/move.c
@ -476,7 +476,8 @@ void do_home(void)
|
|||||||
bool moved_off_chunk = TRUE;
|
bool moved_off_chunk = TRUE;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
bool moved = FALSE;
|
bool moved = FALSE;
|
||||||
size_t leftedge = 0, leftedge_x = 0;
|
size_t leftedge = 0;
|
||||||
|
size_t left_x = 0;
|
||||||
|
|
||||||
#ifdef ENABLE_FOLDING
|
#ifdef ENABLE_FOLDING
|
||||||
if (openfile->current->folded)
|
if (openfile->current->folded)
|
||||||
@ -485,8 +486,7 @@ void do_home(void)
|
|||||||
|
|
||||||
if (ISSET(SOFTWRAP)) {
|
if (ISSET(SOFTWRAP)) {
|
||||||
leftedge = leftedge_for(was_column, openfile->current);
|
leftedge = leftedge_for(was_column, openfile->current);
|
||||||
leftedge_x = proper_x(openfile->current, &leftedge, FALSE, leftedge,
|
left_x = proper_x(openfile->current, &leftedge, FALSE, leftedge, NULL);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ISSET(SMART_HOME)) {
|
if (ISSET(SMART_HOME)) {
|
||||||
@ -499,7 +499,7 @@ void do_home(void)
|
|||||||
if (openfile->current_x == indent_x) {
|
if (openfile->current_x == indent_x) {
|
||||||
openfile->current_x = 0;
|
openfile->current_x = 0;
|
||||||
moved = TRUE;
|
moved = TRUE;
|
||||||
} else if (!ISSET(SOFTWRAP) || leftedge_x <= indent_x) {
|
} else if (left_x <= indent_x) {
|
||||||
openfile->current_x = indent_x;
|
openfile->current_x = indent_x;
|
||||||
moved = TRUE;
|
moved = TRUE;
|
||||||
}
|
}
|
||||||
@ -509,10 +509,10 @@ void do_home(void)
|
|||||||
if (!moved && ISSET(SOFTWRAP)) {
|
if (!moved && ISSET(SOFTWRAP)) {
|
||||||
/* If already at the left edge of the screen, move fully home.
|
/* If already at the left edge of the screen, move fully home.
|
||||||
* Otherwise, move to the left edge. */
|
* Otherwise, move to the left edge. */
|
||||||
if (openfile->current_x == leftedge_x)
|
if (openfile->current_x == left_x)
|
||||||
openfile->current_x = 0;
|
openfile->current_x = 0;
|
||||||
else {
|
else {
|
||||||
openfile->current_x = leftedge_x;
|
openfile->current_x = left_x;
|
||||||
openfile->placewewant = leftedge;
|
openfile->placewewant = leftedge;
|
||||||
moved_off_chunk = FALSE;
|
moved_off_chunk = FALSE;
|
||||||
}
|
}
|
||||||
@ -548,11 +548,12 @@ void do_end(void)
|
|||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (ISSET(SOFTWRAP)) {
|
if (ISSET(SOFTWRAP)) {
|
||||||
|
bool kickoff = TRUE;
|
||||||
bool last_chunk = FALSE;
|
bool last_chunk = FALSE;
|
||||||
size_t leftedge = leftedge_for(was_column, openfile->current);
|
size_t leftedge = leftedge_for(was_column, openfile->current);
|
||||||
size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
|
size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
|
||||||
leftedge, &last_chunk);
|
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.
|
/* 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
|
* Otherwise, we're one column past the end of the line. Shifting
|
||||||
@ -561,14 +562,14 @@ void do_end(void)
|
|||||||
if (!last_chunk)
|
if (!last_chunk)
|
||||||
rightedge--;
|
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
|
/* If already at the right edge of the screen, move fully to
|
||||||
* the end of the line. Otherwise, move to the right edge. */
|
* 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;
|
openfile->current_x = line_len;
|
||||||
else {
|
else {
|
||||||
openfile->current_x = rightedge_x;
|
openfile->current_x = right_x;
|
||||||
openfile->placewewant = rightedge;
|
openfile->placewewant = rightedge;
|
||||||
moved_off_chunk = FALSE;
|
moved_off_chunk = FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -614,8 +614,8 @@ int go_forward_chunks(int nrows, linestruct **line, size_t *leftedge);
|
|||||||
bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge);
|
bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge);
|
||||||
void edit_scroll(bool direction);
|
void edit_scroll(bool direction);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
|
size_t get_softwrap_breakpoint(const char *linedata, size_t leftedge,
|
||||||
bool *end_of_line);
|
bool *kickoff, bool *end_of_line);
|
||||||
size_t get_chunk_and_edge(size_t column, linestruct *line, size_t *leftedge);
|
size_t get_chunk_and_edge(size_t column, linestruct *line, size_t *leftedge);
|
||||||
size_t chunk_for(size_t column, linestruct *line);
|
size_t chunk_for(size_t column, linestruct *line);
|
||||||
size_t leftedge_for(size_t column, linestruct *line);
|
size_t leftedge_for(size_t column, linestruct *line);
|
||||||
|
|||||||
57
src/winio.c
57
src/winio.c
@ -2946,6 +2946,8 @@ int update_softwrapped_line(linestruct *line)
|
|||||||
/* The end column of the current chunk. */
|
/* The end column of the current chunk. */
|
||||||
char *converted;
|
char *converted;
|
||||||
/* The data of the chunk with tabs and control characters expanded. */
|
/* The data of the chunk with tabs and control characters expanded. */
|
||||||
|
bool kickoff = TRUE;
|
||||||
|
/* This tells the softwrapping routine to start at beginning-of-line. */
|
||||||
bool end_of_line = FALSE;
|
bool end_of_line = FALSE;
|
||||||
/* Becomes TRUE when the last chunk of the line has been reached. */
|
/* Becomes TRUE when the last chunk of the line has been reached. */
|
||||||
|
|
||||||
@ -2980,7 +2982,7 @@ int update_softwrapped_line(linestruct *line)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (!end_of_line && row < editwinrows) {
|
while (!end_of_line && row < editwinrows) {
|
||||||
to_col = get_softwrap_breakpoint(line->data, from_col, &end_of_line);
|
to_col = get_softwrap_breakpoint(line->data, from_col, &kickoff, &end_of_line);
|
||||||
|
|
||||||
sequel_column = (end_of_line) ? 0 : to_col;
|
sequel_column = (end_of_line) ? 0 : to_col;
|
||||||
|
|
||||||
@ -3076,6 +3078,7 @@ int go_forward_chunks(int nrows, linestruct **line, size_t *leftedge)
|
|||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (ISSET(SOFTWRAP)) {
|
if (ISSET(SOFTWRAP)) {
|
||||||
size_t current_leftedge = *leftedge;
|
size_t current_leftedge = *leftedge;
|
||||||
|
bool kickoff = TRUE;
|
||||||
|
|
||||||
/* Advance through the requested number of chunks. */
|
/* Advance through the requested number of chunks. */
|
||||||
for (i = nrows; i > 0; i--) {
|
for (i = nrows; i > 0; i--) {
|
||||||
@ -3090,7 +3093,7 @@ int go_forward_chunks(int nrows, linestruct **line, size_t *leftedge)
|
|||||||
bool end_of_line = FALSE;
|
bool end_of_line = FALSE;
|
||||||
|
|
||||||
current_leftedge = get_softwrap_breakpoint((*line)->data,
|
current_leftedge = get_softwrap_breakpoint((*line)->data,
|
||||||
current_leftedge, &end_of_line);
|
current_leftedge, &kickoff, &end_of_line);
|
||||||
|
|
||||||
if (!end_of_line)
|
if (!end_of_line)
|
||||||
continue;
|
continue;
|
||||||
@ -3100,6 +3103,7 @@ int go_forward_chunks(int nrows, linestruct **line, size_t *leftedge)
|
|||||||
|
|
||||||
*line = (*line)->next;
|
*line = (*line)->next;
|
||||||
current_leftedge = 0;
|
current_leftedge = 0;
|
||||||
|
kickoff = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only change leftedge when we actually could move. */
|
/* Only change leftedge when we actually could move. */
|
||||||
@ -3259,24 +3263,34 @@ void edit_scroll(bool direction)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* Get the column number after leftedge where we can break the given text, and
|
/* Get the column number after leftedge where we can break the given linedata,
|
||||||
* return it. This will always be editwincols or less after leftedge. Set
|
* and return it. (This will always be at most editwincols after leftedge.)
|
||||||
* end_of_line to TRUE if we reach the end of the line while searching the
|
* When kickoff is TRUE, start at the beginning of the linedata; otherwise,
|
||||||
* text. Assume leftedge is the leftmost column of a softwrapped chunk. */
|
* continue from where the previous call left off. Set end_of_line to TRUE
|
||||||
size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
|
* when end-of-line is reached while searching for a possible breakpoint. */
|
||||||
bool *end_of_line)
|
size_t get_softwrap_breakpoint(const char *linedata, size_t leftedge,
|
||||||
|
bool *kickoff, bool *end_of_line)
|
||||||
{
|
{
|
||||||
|
static const char *text;
|
||||||
|
/* Pointer at the current character in this line's data. */
|
||||||
|
static size_t column;
|
||||||
|
/* Column position that corresponds to the above pointer. */
|
||||||
size_t goal_column = leftedge + editwincols;
|
size_t goal_column = leftedge + editwincols;
|
||||||
/* The place at or before which text must be broken. */
|
/* The place at or before which text must be broken. */
|
||||||
size_t breaking_col = goal_column;
|
size_t breaking_col = goal_column;
|
||||||
/* The column where text can be broken, when there's no better. */
|
/* The column where text can be broken, when there's no better. */
|
||||||
size_t column = 0;
|
|
||||||
/* Current column position in text. */
|
|
||||||
size_t last_blank_col = 0;
|
size_t last_blank_col = 0;
|
||||||
/* The column position of the last seen whitespace character. */
|
/* The column position of the last seen whitespace character. */
|
||||||
const char *farthest_blank = NULL;
|
const char *farthest_blank = NULL;
|
||||||
/* A pointer to the last seen whitespace character in text. */
|
/* A pointer to the last seen whitespace character in text. */
|
||||||
|
|
||||||
|
/* Initialize the static variables when it's another line. */
|
||||||
|
if (*kickoff) {
|
||||||
|
text = linedata;
|
||||||
|
column = 0;
|
||||||
|
*kickoff = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* First find the place in text where the current chunk starts. */
|
/* First find the place in text where the current chunk starts. */
|
||||||
while (*text != '\0' && column < leftedge)
|
while (*text != '\0' && column < leftedge)
|
||||||
text += advance_over(text, &column);
|
text += advance_over(text, &column);
|
||||||
@ -3317,26 +3331,29 @@ size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
|
|||||||
return (editwincols > 1) ? breaking_col : column - 1;
|
return (editwincols > 1) ? breaking_col : column - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the row of the softwrapped chunk of the given line that column is on,
|
/* Return the row number of the softwrapped chunk in the given line that the
|
||||||
* relative to the first row (zero-based), and return it. If leftedge isn't
|
* given column is on, relative to the first row (zero-based). If leftedge
|
||||||
* NULL, return the leftmost column of the chunk in it. */
|
* 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 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 end_of_line = FALSE;
|
||||||
|
bool kickoff = TRUE;
|
||||||
|
size_t start_col = 0;
|
||||||
|
size_t end_col;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
end_col = get_softwrap_breakpoint(line->data, start_col, &end_of_line);
|
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 (end_of_line || (start_col <= column && column < end_col)) {
|
||||||
if (leftedge != NULL)
|
if (leftedge != NULL)
|
||||||
*leftedge = start_col;
|
*leftedge = start_col;
|
||||||
return current_chunk;
|
return current_chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_chunk++;
|
|
||||||
start_col = end_col;
|
start_col = end_col;
|
||||||
|
current_chunk++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3388,9 +3405,10 @@ size_t actual_last_column(size_t leftedge, size_t column)
|
|||||||
{
|
{
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (ISSET(SOFTWRAP)) {
|
if (ISSET(SOFTWRAP)) {
|
||||||
|
bool kickoff = TRUE;
|
||||||
bool last_chunk = FALSE;
|
bool last_chunk = FALSE;
|
||||||
size_t end_col = get_softwrap_breakpoint(openfile->current->data,
|
size_t end_col = get_softwrap_breakpoint(openfile->current->data,
|
||||||
leftedge, &last_chunk) - leftedge;
|
leftedge, &kickoff, &last_chunk) - leftedge;
|
||||||
|
|
||||||
/* If we're not on the last chunk, we're one column past the end of
|
/* If we're not on the last chunk, we're one column past the end of
|
||||||
* the row. Shifting back one column might put us in the middle of
|
* the row. Shifting back one column might put us in the middle of
|
||||||
@ -3676,6 +3694,7 @@ void spotlight_softwrapped(size_t from_col, size_t to_col)
|
|||||||
size_t leftedge = leftedge_for(from_col, openfile->current);
|
size_t leftedge = leftedge_for(from_col, openfile->current);
|
||||||
size_t break_col;
|
size_t break_col;
|
||||||
bool end_of_line = FALSE;
|
bool end_of_line = FALSE;
|
||||||
|
bool kickoff = TRUE;
|
||||||
char *word;
|
char *word;
|
||||||
|
|
||||||
place_the_cursor();
|
place_the_cursor();
|
||||||
@ -3683,7 +3702,7 @@ void spotlight_softwrapped(size_t from_col, size_t to_col)
|
|||||||
|
|
||||||
while (row < editwinrows) {
|
while (row < editwinrows) {
|
||||||
break_col = get_softwrap_breakpoint(openfile->current->data,
|
break_col = get_softwrap_breakpoint(openfile->current->data,
|
||||||
leftedge, &end_of_line);
|
leftedge, &kickoff, &end_of_line);
|
||||||
|
|
||||||
/* If the highlighting ends on this chunk, we can stop after it. */
|
/* If the highlighting ends on this chunk, we can stop after it. */
|
||||||
if (break_col >= to_col) {
|
if (break_col >= to_col) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user