From a6f3675fc4e21b3f899286b9a02005368d913f74 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 03:11:51 +0200 Subject: Merging upstream version 3:4.8.31. Signed-off-by: Daniel Baumann --- src/editor/editcmd.c | 167 ++++++++++++++++++--------------------------------- 1 file changed, 59 insertions(+), 108 deletions(-) (limited to 'src/editor/editcmd.c') diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index de624f2..bca9df7 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1,7 +1,7 @@ /* Editor high level editing commands - Copyright (C) 1996-2023 + Copyright (C) 1996-2024 Free Software Foundation, Inc. Written by: @@ -460,22 +460,23 @@ edit_save_cmd (WEdit * edit) /* --------------------------------------------------------------------------------------------- */ static void -edit_delete_column_of_text (WEdit * edit) +edit_delete_column_of_text (WEdit * edit, off_t m1, off_t m2) { - off_t m1, m2; off_t n; + off_t r; long b, c, d; - eval_marks (edit, &m1, &m2); n = edit_buffer_get_forward_offset (&edit->buffer, m1, 0, m2) + 1; - c = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m1), 0, m1); - d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2), 0, m2); + r = edit_buffer_get_bol (&edit->buffer, m1); + c = (long) edit_move_forward3 (edit, r, 0, m1); + r = edit_buffer_get_bol (&edit->buffer, m2); + d = (long) edit_move_forward3 (edit, r, 0, m2); b = MAX (MIN (c, d), MIN (edit->column1, edit->column2)); c = MAX (c, MAX (edit->column1, edit->column2)); while (n-- != 0) { - off_t r, p, q; + off_t p, q; r = edit_buffer_get_current_bol (&edit->buffer); p = edit_move_forward3 (edit, r, b, 0); @@ -490,25 +491,22 @@ edit_delete_column_of_text (WEdit * edit) /* move to next line except on the last delete */ if (n != 0) - edit_cursor_move (edit, - edit_buffer_get_forward_offset (&edit->buffer, edit->buffer.curs1, 1, - 0) - edit->buffer.curs1); + { + r = edit_buffer_get_forward_offset (&edit->buffer, edit->buffer.curs1, 1, 0); + edit_cursor_move (edit, r - edit->buffer.curs1); + } } } /* --------------------------------------------------------------------------------------------- */ -/** if success return 0 */ +/** if success return TRUE */ -static int -edit_block_delete (WEdit * edit) +static gboolean +edit_block_delete (WEdit * edit, off_t start_mark, off_t end_mark) { - off_t start_mark, end_mark; off_t curs_pos; long curs_line, c1, c2; - if (!eval_marks (edit, &start_mark, &end_mark)) - return 0; - if (edit->column_highlight && edit->mark2 < 0) edit_mark_cmd (edit, FALSE); @@ -517,7 +515,7 @@ edit_block_delete (WEdit * edit) edit_query_dialog2 (_("Warning"), ("Block is large, you may not be able to undo this action"), _("C&ontinue"), _("&Cancel")) != 0) - return 1; + return FALSE; c1 = MIN (edit->column1, edit->column2); c2 = MAX (edit->column1, edit->column2); @@ -538,16 +536,18 @@ edit_block_delete (WEdit * edit) { if (edit->column_highlight) { + off_t b, e; off_t line_width; if (edit->mark2 < 0) edit_mark_cmd (edit, FALSE); - edit_delete_column_of_text (edit); + edit_delete_column_of_text (edit, start_mark, end_mark); /* move cursor to the saved position */ edit_move_to_line (edit, curs_line); /* calculate line width and cursor position before cut */ - line_width = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, - edit_buffer_get_current_eol (&edit->buffer)); + b = edit_buffer_get_current_bol (&edit->buffer); + e = edit_buffer_get_current_eol (&edit->buffer); + line_width = edit_move_forward3 (edit, b, 0, e); if (edit_options.cursor_beyond_eol && curs_pos > line_width) edit->over_col = curs_pos - line_width; } @@ -563,7 +563,7 @@ edit_block_delete (WEdit * edit) edit_set_markers (edit, 0, 0, 0, 0); edit->force |= REDRAW_PAGE; - return 0; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -586,7 +586,8 @@ edit_get_block (WEdit * edit, off_t start, off_t finish, off_t * l) int c; off_t x; - x = edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, start), 0, start); + x = edit_buffer_get_bol (&edit->buffer, start); + x = edit_move_forward3 (edit, x, 0, start); c = edit_buffer_get_byte (&edit->buffer, start); if ((x >= edit->column1 && x < edit->column2) || (x >= edit->column2 && x < edit->column1) || c == '\n') @@ -631,15 +632,28 @@ static void pipe_mail (const edit_buffer_t * buf, char *to, char *subject, char *cc) { FILE *p = 0; - char *s; + char *s = NULL; to = name_quote (to, FALSE); - subject = name_quote (subject, FALSE); - cc = name_quote (cc, FALSE); - s = g_strconcat ("mail -s ", subject, *cc ? " -c " : "", cc, " ", to, (char *) NULL); - g_free (to); - g_free (subject); - g_free (cc); + if (to != NULL) + { + subject = name_quote (subject, FALSE); + if (subject != NULL) + { + cc = name_quote (cc, FALSE); + if (cc == NULL) + s = g_strdup_printf ("mail -s %s %s", subject, to); + else + { + s = g_strdup_printf ("mail -s %s -c %s %s", subject, cc, to); + g_free (cc); + } + + g_free (subject); + } + + g_free (to); + } if (s != NULL) { @@ -1255,72 +1269,6 @@ edit_close_cmd (WEdit * edit) return ret; } -/* --------------------------------------------------------------------------------------------- */ -/** - if mark2 is -1 then marking is from mark1 to the cursor. - Otherwise its between the markers. This handles this. - Returns FALSE if no text is marked. - */ - -gboolean -eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark) -{ - long end_mark_curs; - - if (edit->mark1 == edit->mark2) - { - *start_mark = *end_mark = 0; - edit->column2 = edit->column1 = 0; - return FALSE; - } - - if (edit->end_mark_curs < 0) - end_mark_curs = edit->buffer.curs1; - else - end_mark_curs = edit->end_mark_curs; - - if (edit->mark2 >= 0) - { - *start_mark = MIN (edit->mark1, edit->mark2); - *end_mark = MAX (edit->mark1, edit->mark2); - } - else - { - *start_mark = MIN (edit->mark1, end_mark_curs); - *end_mark = MAX (edit->mark1, end_mark_curs); - edit->column2 = edit->curs_col + edit->over_col; - } - - if (edit->column_highlight - && ((edit->mark1 > end_mark_curs && edit->column1 < edit->column2) - || (edit->mark1 < end_mark_curs && edit->column1 > edit->column2))) - { - off_t start_bol, start_eol; - off_t end_bol, end_eol; - long col1, col2; - off_t diff1, diff2; - - start_bol = edit_buffer_get_bol (&edit->buffer, *start_mark); - start_eol = edit_buffer_get_eol (&edit->buffer, start_bol - 1) + 1; - end_bol = edit_buffer_get_bol (&edit->buffer, *end_mark); - end_eol = edit_buffer_get_eol (&edit->buffer, *end_mark); - col1 = MIN (edit->column1, edit->column2); - col2 = MAX (edit->column1, edit->column2); - - diff1 = edit_move_forward3 (edit, start_bol, col2, 0) - - edit_move_forward3 (edit, start_bol, col1, 0); - diff2 = edit_move_forward3 (edit, end_bol, col2, 0) - - edit_move_forward3 (edit, end_bol, col1, 0); - - *start_mark -= diff1; - *end_mark += diff2; - *start_mark = MAX (*start_mark, start_eol); - *end_mark = MIN (*end_mark, end_eol); - } - - return TRUE; -} - /* --------------------------------------------------------------------------------------------- */ void @@ -1398,6 +1346,7 @@ edit_block_move_cmd (WEdit * edit) off_t size; long c1, c2, b_width; long x, x2; + off_t b1, b2; c1 = MIN (edit->column1, edit->column2); c2 = MAX (edit->column1, edit->column2); @@ -1409,8 +1358,9 @@ edit_block_move_cmd (WEdit * edit) x2 = x + edit->over_col; /* do nothing when cursor inside first line of selected area */ - if ((edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1) == - edit_buffer_get_eol (&edit->buffer, start_mark)) && x2 > c1 && x2 <= c2) + b1 = edit_buffer_get_eol (&edit->buffer, edit->buffer.curs1); + b2 = edit_buffer_get_eol (&edit->buffer, start_mark); + if (b1 == b2 && x2 > c1 && x2 <= c2) return; if (edit->buffer.curs1 > start_mark @@ -1429,7 +1379,8 @@ edit_block_move_cmd (WEdit * edit) edit->over_col = MAX (0, edit->over_col - b_width); /* calculate the cursor pos after delete block */ - current = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), x, 0); + b1 = edit_buffer_get_current_bol (&edit->buffer); + current = edit_move_forward3 (edit, b1, x, 0); edit_cursor_move (edit, current - edit->buffer.curs1); edit_scroll_screen_over_cursor (edit); @@ -1443,6 +1394,7 @@ edit_block_move_cmd (WEdit * edit) else { off_t count, count_orig; + off_t x; current = edit->buffer.curs1; copy_buf = g_malloc0 (end_mark - start_mark); @@ -1453,9 +1405,8 @@ edit_block_move_cmd (WEdit * edit) copy_buf[end_mark - count - 1] = edit_delete (edit, TRUE); edit_scroll_screen_over_cursor (edit); - edit_cursor_move (edit, - current - edit->buffer.curs1 - - (((current - edit->buffer.curs1) > 0) ? end_mark - start_mark : 0)); + x = current > edit->buffer.curs1 ? end_mark - start_mark : 0; + edit_cursor_move (edit, current - edit->buffer.curs1 - x); edit_scroll_screen_over_cursor (edit); count_orig = count; while (count-- > start_mark) @@ -1475,19 +1426,19 @@ edit_block_move_cmd (WEdit * edit) } /* --------------------------------------------------------------------------------------------- */ -/** returns 1 if canceelled by user */ +/** returns FALSE if canceelled by user */ -int +gboolean edit_block_delete_cmd (WEdit * edit) { off_t start_mark, end_mark; if (eval_marks (edit, &start_mark, &end_mark)) - return edit_block_delete (edit); + return edit_block_delete (edit, start_mark, end_mark); edit_delete_line (edit); - return 0; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -1859,7 +1810,7 @@ edit_sort_cmd (WEdit * edit) edit->force |= REDRAW_COMPLETELY; - if (edit_block_delete_cmd (edit)) + if (!edit_block_delete_cmd (edit)) return 1; { @@ -1934,7 +1885,7 @@ edit_block_process_cmd (WEdit * edit, int macro_number) fname = g_strdup_printf ("%s.%i.sh", EDIT_HOME_MACRO_FILE, macro_number); macros_fname = g_build_filename (mc_config_get_data_path (), fname, (char *) NULL); - user_menu (edit, macros_fname, 0); + edit_user_menu (edit, macros_fname, 0); g_free (fname); g_free (macros_fname); edit->force |= REDRAW_COMPLETELY; -- cgit v1.2.3