Skip to content

Commit

Permalink
Tricket #3761: mcedit: wrong deletion of marked column.
Browse files Browse the repository at this point in the history
If mark column (Shitf+F3) and select the column from left to right, from
up to down, it can be properly deleted later with F8.
But if select it from right to left, from up to down, erasing with F8
keeps the first line of the selected block.

Solution: don't call eval_marks() several times while deleting vertical
block.

  * (edit_block_delete_cmd): calculate mark positions here and pass them...
  * (edit_block_delete): ...through here...
  * (edit_delete_column_of_text): ...to here.

Signed-off-by: Andrew Borodin <[email protected]>
  • Loading branch information
aborodin committed Dec 31, 2023
1 parent 1541952 commit b50470f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/editor/editcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,11 @@ 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;
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);
Expand Down Expand Up @@ -500,15 +498,11 @@ edit_delete_column_of_text (WEdit * edit)
/** if success return 0 */

static int
edit_block_delete (WEdit * edit)
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);

Expand Down Expand Up @@ -542,7 +536,7 @@ edit_block_delete (WEdit * edit)

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 */
Expand Down Expand Up @@ -1496,7 +1490,7 @@ 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);

Expand Down

0 comments on commit b50470f

Please sign in to comment.