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