tweaks: factor out a three-line condition into a separate function
For clarity.
This commit is contained in:
parent
e39e2ddf52
commit
2bc5c1987c
@ -330,10 +330,8 @@ void ingraft_buffer(linestruct *topline)
|
||||
bool edittop_inside = (openfile->edittop == openfile->current);
|
||||
#ifndef NANO_TINY
|
||||
/* Remember whether mark and cursor are on the same line, and their order. */
|
||||
bool right_side_up = (openfile->mark && mark_is_before_cursor());
|
||||
bool same_line = (openfile->mark == openfile->current);
|
||||
bool right_side_up = (openfile->mark &&
|
||||
(openfile->mark->lineno < openfile->current->lineno ||
|
||||
(same_line && openfile->mark_x <= openfile->current_x)));
|
||||
#endif
|
||||
|
||||
/* Partition the buffer so that it contains no text, then delete it.*/
|
||||
|
@ -578,6 +578,7 @@ void new_magicline(void);
|
||||
void remove_magicline(void);
|
||||
#endif
|
||||
#ifndef NANO_TINY
|
||||
bool mark_is_before_cursor(void);
|
||||
void get_region(const linestruct **top, size_t *top_x,
|
||||
const linestruct **bot, size_t *bot_x, bool *right_side_up);
|
||||
void get_range(const linestruct **top, const linestruct **bot);
|
||||
|
@ -1181,9 +1181,7 @@ void add_undo(undo_type action, const char *message)
|
||||
case CUT:
|
||||
if (openfile->mark) {
|
||||
u->xflags |= MARK_WAS_SET;
|
||||
if (openfile->mark->lineno < openfile->current->lineno ||
|
||||
(openfile->mark == openfile->current &&
|
||||
openfile->mark_x < openfile->current_x)) {
|
||||
if (mark_is_before_cursor()){
|
||||
u->head_lineno = openfile->mark->lineno;
|
||||
u->head_x = openfile->mark_x;
|
||||
} else {
|
||||
@ -2552,10 +2550,8 @@ const char *treat(char *tempfile_name, char *theprogram, bool spelling)
|
||||
#ifndef NANO_TINY
|
||||
/* Replace the marked text (or entire text) with the corrected text. */
|
||||
if (spelling && openfile->mark) {
|
||||
bool upright = (openfile->mark->lineno < openfile->current->lineno ||
|
||||
(openfile->mark == openfile->current &&
|
||||
openfile->mark_x < openfile->current_x));
|
||||
ssize_t was_mark_lineno = openfile->mark->lineno;
|
||||
bool upright = mark_is_before_cursor();
|
||||
|
||||
replaced = replace_buffer(tempfile_name, CUT, TRUE, "spelling correction");
|
||||
|
||||
|
12
src/utils.c
12
src/utils.c
@ -450,15 +450,21 @@ void remove_magicline(void)
|
||||
#endif
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* Return TRUE when the mark is before or at the cursor, and FALSE otherwise. */
|
||||
bool mark_is_before_cursor(void)
|
||||
{
|
||||
return (openfile->mark->lineno < openfile->current->lineno ||
|
||||
(openfile->mark == openfile->current &&
|
||||
openfile->mark_x <= openfile->current_x));
|
||||
}
|
||||
|
||||
/* Return in (top, top_x) and (bot, bot_x) the start and end "coordinates"
|
||||
* of the marked region. If right_side_up isn't NULL, set it to TRUE when
|
||||
* the mark is at the top of the marked region, and to FALSE otherwise. */
|
||||
void get_region(const linestruct **top, size_t *top_x,
|
||||
const linestruct **bot, size_t *bot_x, bool *right_side_up)
|
||||
{
|
||||
if (openfile->mark->lineno < openfile->current->lineno ||
|
||||
(openfile->mark == openfile->current &&
|
||||
openfile->mark_x < openfile->current_x)) {
|
||||
if (mark_is_before_cursor()) {
|
||||
*top = openfile->mark;
|
||||
*top_x = openfile->mark_x;
|
||||
*bot = openfile->current;
|
||||
|
Loading…
Reference in New Issue
Block a user