mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 10:04:32 +03:00
Ticket #2504 (Verical block is unmarked after copy/move)
Now mark of vertical block is not reset after copy/move. This make easy many copies/movements. Do nothing if cursor is in first line of selection.
This commit is contained in:
parent
bc3c848ab1
commit
dc6bd875c4
@ -285,7 +285,9 @@ void edit_get_match_keyword_cmd (WEdit * edit);
|
||||
int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
|
||||
int edit_save_block_cmd (WEdit * edit);
|
||||
int edit_insert_file_cmd (WEdit * edit);
|
||||
void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width);
|
||||
void edit_insert_over (WEdit * edit);
|
||||
void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2);
|
||||
int edit_insert_column_of_text_from_file (WEdit * edit, int file);
|
||||
long edit_insert_file (WEdit * edit, const char *filename);
|
||||
int edit_load_back_cmd (WEdit * edit);
|
||||
|
@ -676,20 +676,6 @@ edit_modification (WEdit * edit)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edit_insert_over (WEdit * edit)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < edit->over_col; i++)
|
||||
{
|
||||
edit_insert (edit, ' ');
|
||||
}
|
||||
edit->over_col = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
edit_backspace (WEdit * edit, const int byte_delete)
|
||||
{
|
||||
@ -2083,6 +2069,7 @@ edit_insert_file (WEdit * edit, const char *filename)
|
||||
for (i = 0; i < blocklen; i++)
|
||||
edit_insert (edit, buf[i]);
|
||||
}
|
||||
|
||||
}
|
||||
ins_len = edit->curs1 - current;
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
@ -3944,8 +3931,6 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
||||
edit_block_delete_cmd (edit);
|
||||
break;
|
||||
case CK_Move:
|
||||
if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||
edit_insert_over (edit);
|
||||
edit_block_move_cmd (edit);
|
||||
break;
|
||||
|
||||
|
@ -1887,10 +1887,26 @@ eval_marks (WEdit * edit, long *start_mark, long *end_mark)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width)
|
||||
edit_insert_over (WEdit * edit)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < edit->over_col; i++)
|
||||
{
|
||||
edit_insert (edit, ' ');
|
||||
}
|
||||
edit->over_col = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2)
|
||||
{
|
||||
long cursor;
|
||||
int i, col;
|
||||
|
||||
cursor = edit->curs1;
|
||||
col = edit_get_col (edit);
|
||||
for (i = 0; i < size; i++)
|
||||
@ -1934,6 +1950,10 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid
|
||||
}
|
||||
edit_insert (edit, data[i]);
|
||||
}
|
||||
*col1 = col;
|
||||
*col2 = col + width;
|
||||
*start_pos = cursor;
|
||||
*end_pos = edit->curs1;
|
||||
edit_cursor_move (edit, cursor - edit->curs1);
|
||||
}
|
||||
|
||||
@ -2010,6 +2030,9 @@ void
|
||||
edit_block_copy_cmd (WEdit * edit)
|
||||
{
|
||||
long start_mark, end_mark, current = edit->curs1;
|
||||
long col_delta = 0;
|
||||
long mark1, mark2;
|
||||
int c1, c2;
|
||||
int size;
|
||||
unsigned char *copy_buf;
|
||||
|
||||
@ -2025,7 +2048,8 @@ edit_block_copy_cmd (WEdit * edit)
|
||||
|
||||
if (edit->column_highlight)
|
||||
{
|
||||
edit_insert_column_of_text (edit, copy_buf, size, abs (edit->column2 - edit->column1));
|
||||
col_delta = abs (edit->column2 - edit->column1);
|
||||
edit_insert_column_of_text (edit, copy_buf, size, col_delta, &mark1, &mark2, &c1, &c2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2037,11 +2061,7 @@ edit_block_copy_cmd (WEdit * edit)
|
||||
edit_scroll_screen_over_cursor (edit);
|
||||
|
||||
if (edit->column_highlight)
|
||||
{
|
||||
edit_set_markers (edit, 0, 0, 0, 0);
|
||||
edit_push_undo_action (edit, COLUMN_ON);
|
||||
edit->column_highlight = 0;
|
||||
}
|
||||
edit_set_markers (edit, edit->curs1, mark2, c1, c2);
|
||||
else if (start_mark < current && end_mark > current)
|
||||
edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0);
|
||||
|
||||
@ -2054,75 +2074,71 @@ edit_block_copy_cmd (WEdit * edit)
|
||||
void
|
||||
edit_block_move_cmd (WEdit * edit)
|
||||
{
|
||||
long count;
|
||||
long current;
|
||||
unsigned char *copy_buf;
|
||||
unsigned char *copy_buf = NULL;
|
||||
long start_mark, end_mark;
|
||||
int deleted = 0;
|
||||
int x = 0;
|
||||
long line;
|
||||
|
||||
if (eval_marks (edit, &start_mark, &end_mark))
|
||||
return;
|
||||
if (edit->column_highlight)
|
||||
{
|
||||
edit_update_curs_col (edit);
|
||||
x = edit->curs_col;
|
||||
if (start_mark <= edit->curs1 && end_mark >= edit->curs1)
|
||||
if ((x > edit->column1 && x < edit->column2)
|
||||
|| (x > edit->column2 && x < edit->column1))
|
||||
return;
|
||||
}
|
||||
else if (start_mark <= edit->curs1 && end_mark >= edit->curs1)
|
||||
return;
|
||||
|
||||
if ((end_mark - start_mark) > option_max_undo / 2)
|
||||
if (edit_query_dialog2
|
||||
(_("Warning"),
|
||||
_
|
||||
("Block is large, you may not be able to undo this action"),
|
||||
_("C&ontinue"), _("&Cancel")))
|
||||
return;
|
||||
|
||||
edit_push_markers (edit);
|
||||
current = edit->curs1;
|
||||
if (edit->column_highlight)
|
||||
{
|
||||
long line;
|
||||
int size, c1, c2;
|
||||
line = edit->curs_line;
|
||||
if (edit->mark2 < 0)
|
||||
edit_mark_cmd (edit, 0);
|
||||
edit_push_markers (edit);
|
||||
|
||||
if (edit->column_highlight)
|
||||
{
|
||||
long mark1, mark2;
|
||||
int size;
|
||||
int b_width = 0;
|
||||
int c1, c2;
|
||||
int x, x2;
|
||||
|
||||
c1 = min (edit->column1, edit->column2);
|
||||
c2 = max (edit->column1, edit->column2);
|
||||
copy_buf = edit_get_block (edit, start_mark, end_mark, &size);
|
||||
if (x < c2)
|
||||
{
|
||||
edit_block_delete_cmd (edit);
|
||||
deleted = 1;
|
||||
}
|
||||
edit_move_to_line (edit, line);
|
||||
edit_cursor_move (edit,
|
||||
edit_move_forward3 (edit,
|
||||
edit_bol (edit, edit->curs1), x, 0) - edit->curs1);
|
||||
edit_insert_column_of_text (edit, copy_buf, size, c2 - c1);
|
||||
if (!deleted)
|
||||
{
|
||||
line = edit->curs_line;
|
||||
b_width = (c2 - c1);
|
||||
|
||||
edit_update_curs_col (edit);
|
||||
|
||||
x = edit->curs_col;
|
||||
edit_block_delete_cmd (edit);
|
||||
edit_move_to_line (edit, line);
|
||||
edit_cursor_move (edit,
|
||||
edit_move_forward3 (edit,
|
||||
edit_bol (edit,
|
||||
edit->curs1), x, 0) - edit->curs1);
|
||||
x2 = x + edit->over_col;
|
||||
|
||||
/* do nothing when cursor inside first line of selected area */
|
||||
if ((edit_eol (edit, edit->curs1) == edit_eol (edit, start_mark)) && (x2 > c1 && x2 <= c2))
|
||||
return;
|
||||
|
||||
if (edit->curs1 > start_mark && edit->curs1 < edit_eol (edit, end_mark))
|
||||
{
|
||||
if (x > c2)
|
||||
x -= b_width;
|
||||
else if (x > c1 && x <= c2)
|
||||
x = c1;
|
||||
}
|
||||
edit_set_markers (edit, 0, 0, 0, 0);
|
||||
edit_push_undo_action (edit, COLUMN_ON);
|
||||
edit->column_highlight = 0;
|
||||
/* save current selection into buffer */
|
||||
copy_buf = edit_get_block (edit, start_mark, end_mark, &size);
|
||||
|
||||
/* remove current selection */
|
||||
edit_block_delete_cmd (edit);
|
||||
|
||||
edit->over_col = max (0, edit->over_col - b_width);
|
||||
/* calculate the cursor pos after delete block */
|
||||
current = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0);
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
edit_scroll_screen_over_cursor (edit);
|
||||
|
||||
/* add TWS if need before block insertion */
|
||||
if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||
edit_insert_over (edit);
|
||||
|
||||
edit_insert_column_of_text (edit, copy_buf, size, b_width, &mark1, &mark2, &c1, &c2);
|
||||
edit_set_markers (edit, mark1, mark2, c1, c2);
|
||||
}
|
||||
else
|
||||
{
|
||||
long count;
|
||||
|
||||
current = edit->curs1;
|
||||
copy_buf = g_malloc0 (end_mark - start_mark);
|
||||
edit_cursor_move (edit, start_mark - edit->curs1);
|
||||
edit_scroll_screen_over_cursor (edit);
|
||||
@ -2141,6 +2157,7 @@ edit_block_move_cmd (WEdit * edit)
|
||||
edit_insert_ahead (edit, copy_buf[end_mark - count - 1]);
|
||||
edit_set_markers (edit, edit->curs1, edit->curs1 + end_mark - start_mark, 0, 0);
|
||||
}
|
||||
|
||||
edit_scroll_screen_over_cursor (edit);
|
||||
g_free (copy_buf);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
|
Loading…
Reference in New Issue
Block a user