tweaks: reshuffle a bit of common code, moving it to an existing function
parent
ee5b250b66
commit
c22fef18e4
|
@ -609,7 +609,7 @@ void remove_magicline(void);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
void mark_order(const filestruct **top, size_t *top_x, const filestruct
|
void mark_order(const filestruct **top, size_t *top_x, const filestruct
|
||||||
**bot, size_t *bot_x, bool *right_side_up);
|
**bot, size_t *bot_x, bool *right_side_up);
|
||||||
void get_region(const filestruct **top, const filestruct **bot);
|
void get_range(const filestruct **top, const filestruct **bot);
|
||||||
#endif
|
#endif
|
||||||
size_t get_totsize(const filestruct *begin, const filestruct *end);
|
size_t get_totsize(const filestruct *begin, const filestruct *end);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
|
21
src/text.c
21
src/text.c
|
@ -298,12 +298,7 @@ void do_indent(void)
|
||||||
filestruct *top, *bot, *line;
|
filestruct *top, *bot, *line;
|
||||||
|
|
||||||
/* Use either all the marked lines or just the current line. */
|
/* Use either all the marked lines or just the current line. */
|
||||||
if (openfile->mark)
|
get_range((const filestruct **)&top, (const filestruct **)&bot);
|
||||||
get_region((const filestruct **)&top, (const filestruct **)&bot);
|
|
||||||
else {
|
|
||||||
top = openfile->current;
|
|
||||||
bot = top;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Go through the lines to see if there's a non-empty one. */
|
/* Go through the lines to see if there's a non-empty one. */
|
||||||
for (line = top; line != bot->next; line = line->next) {
|
for (line = top; line != bot->next; line = line->next) {
|
||||||
|
@ -401,12 +396,7 @@ void do_unindent(void)
|
||||||
filestruct *top, *bot, *line;
|
filestruct *top, *bot, *line;
|
||||||
|
|
||||||
/* Use either all the marked lines or just the current line. */
|
/* Use either all the marked lines or just the current line. */
|
||||||
if (openfile->mark)
|
get_range((const filestruct **)&top, (const filestruct **)&bot);
|
||||||
get_region((const filestruct **)&top, (const filestruct **)&bot);
|
|
||||||
else {
|
|
||||||
top = openfile->current;
|
|
||||||
bot = top;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if there is a line that can be unindented. */
|
/* Check if there is a line that can be unindented. */
|
||||||
for (line = top; line != bot->next; line = line->next) {
|
for (line = top; line != bot->next; line = line->next) {
|
||||||
|
@ -503,12 +493,7 @@ void do_comment(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Determine which lines to work on. */
|
/* Determine which lines to work on. */
|
||||||
if (openfile->mark)
|
get_range((const filestruct **)&top, (const filestruct **)&bot);
|
||||||
get_region((const filestruct **)&top, (const filestruct **)&bot);
|
|
||||||
else {
|
|
||||||
top = openfile->current;
|
|
||||||
bot = top;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If only the magic line is selected, don't do anything. */
|
/* If only the magic line is selected, don't do anything. */
|
||||||
if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) {
|
if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) {
|
||||||
|
|
20
src/utils.c
20
src/utils.c
|
@ -532,16 +532,22 @@ void mark_order(const filestruct **top, size_t *top_x, const filestruct
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the start and end points of the marked region, but
|
/* Get the set of lines to work on -- either just the current line, or the
|
||||||
* push the end point back if it's at the start of a line. */
|
* first to last lines of the marked region. When the cursor (or mark) is
|
||||||
void get_region(const filestruct **top, const filestruct **bot)
|
* at the start of the last line of the region, exclude that line. */
|
||||||
|
void get_range(const filestruct **top, const filestruct **bot)
|
||||||
{
|
{
|
||||||
size_t top_x, bot_x;
|
if (!openfile->mark) {
|
||||||
|
*top = openfile->current;
|
||||||
|
*bot = openfile->current;
|
||||||
|
} else {
|
||||||
|
size_t top_x, bot_x;
|
||||||
|
|
||||||
mark_order(top, &top_x, bot, &bot_x, NULL);
|
mark_order(top, &top_x, bot, &bot_x, NULL);
|
||||||
|
|
||||||
if (bot_x == 0 && *bot != *top)
|
if (bot_x == 0 && *bot != *top)
|
||||||
*bot = (*bot)->prev;
|
*bot = (*bot)->prev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given a line number, return a pointer to the corresponding struct. */
|
/* Given a line number, return a pointer to the corresponding struct. */
|
||||||
|
|
Loading…
Reference in New Issue