Merge branch '2504_vertical_persistent_block_mark'

* 2504_vertical_persistent_block_mark:
  mark inserted from file
  Ticket #2504 (Verical block is unmarked after copy/move)
This commit is contained in:
Ilia Maslakov 2011-03-17 08:52:04 +00:00
commit 3fec8a4282
3 changed files with 115 additions and 84 deletions

View File

@ -285,8 +285,11 @@ 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 (WEdit * edit, const char *filename, long start, long finish);
int edit_save_block_cmd (WEdit * edit); int edit_save_block_cmd (WEdit * edit);
int edit_insert_file_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);
int edit_insert_column_of_text_from_file (WEdit * edit, int file); 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 *start_pos, long *end_pos, int *col1, int *col2);
long edit_insert_file (WEdit * edit, const char *filename); long edit_insert_file (WEdit * edit, const char *filename);
int edit_load_back_cmd (WEdit * edit); int edit_load_back_cmd (WEdit * edit);
int edit_load_forward_cmd (WEdit * edit); int edit_load_forward_cmd (WEdit * edit);

View File

@ -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 static int
edit_backspace (WEdit * edit, const int byte_delete) edit_backspace (WEdit * edit, const int byte_delete)
{ {
@ -2074,7 +2060,17 @@ edit_insert_file (WEdit * edit, const char *filename)
} }
if (vertical_insertion) if (vertical_insertion)
{ {
blocklen = edit_insert_column_of_text_from_file (edit, file); long mark1, mark2;
int c1, c2;
blocklen = edit_insert_column_of_text_from_file (edit, file, &mark1, &mark2, &c1, &c2);
edit_set_markers (edit, edit->curs1, mark2, c1, c2);
/* highlight inserted text then not persistent blocks */
if (!option_persistent_selections)
{
if (!edit->column_highlight)
edit_push_undo_action (edit, COLUMN_OFF);
edit->column_highlight = 1;
}
} }
else else
{ {
@ -2083,7 +2079,16 @@ edit_insert_file (WEdit * edit, const char *filename)
for (i = 0; i < blocklen; i++) for (i = 0; i < blocklen; i++)
edit_insert (edit, buf[i]); edit_insert (edit, buf[i]);
} }
/* highlight inserted text then not persistent blocks */
if (!option_persistent_selections)
{
edit_set_markers (edit, edit->curs1, current, 0, 0);
if (edit->column_highlight)
edit_push_undo_action (edit, COLUMN_ON);
edit->column_highlight = 0;
}
} }
edit->force |= REDRAW_PAGE;
ins_len = edit->curs1 - current; ins_len = edit->curs1 - current;
edit_cursor_move (edit, current - edit->curs1); edit_cursor_move (edit, current - edit->curs1);
g_free (buf); g_free (buf);
@ -3944,8 +3949,6 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
edit_block_delete_cmd (edit); edit_block_delete_cmd (edit);
break; break;
case CK_Move: case CK_Move:
if (option_cursor_beyond_eol && edit->over_col > 0)
edit_insert_over (edit);
edit_block_move_cmd (edit); edit_block_move_cmd (edit);
break; break;

View File

@ -1887,10 +1887,26 @@ eval_marks (WEdit * edit, long *start_mark, long *end_mark)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void 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; long cursor;
int i, col; int i, col;
cursor = edit->curs1; cursor = edit->curs1;
col = edit_get_col (edit); col = edit_get_col (edit);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
@ -1934,23 +1950,31 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid
} }
edit_insert (edit, data[i]); edit_insert (edit, data[i]);
} }
*col1 = col;
*col2 = col + width;
*start_pos = cursor;
*end_pos = edit->curs1;
edit_cursor_move (edit, cursor - edit->curs1); edit_cursor_move (edit, cursor - edit->curs1);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
int int
edit_insert_column_of_text_from_file (WEdit * edit, int file) edit_insert_column_of_text_from_file (WEdit * edit, int file,
long *start_pos, long *end_pos, int *col1, int *col2)
{ {
long cursor; long cursor;
int i, col; int col;
int blocklen = -1, width; int blocklen = -1, width = 0;
unsigned char *data; unsigned char *data;
cursor = edit->curs1; cursor = edit->curs1;
col = edit_get_col (edit); col = edit_get_col (edit);
data = g_malloc0 (TEMP_BUF_LEN); data = g_malloc0 (TEMP_BUF_LEN);
while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0) while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0)
{ {
int i;
for (width = 0; width < blocklen; width++) for (width = 0; width < blocklen; width++)
{ {
if (data[width] == '\n') if (data[width] == '\n')
@ -1998,9 +2022,13 @@ edit_insert_column_of_text_from_file (WEdit * edit, int file)
edit_insert (edit, data[i]); edit_insert (edit, data[i]);
} }
} }
*col1 = col;
*col2 = col + width;
*start_pos = cursor;
*end_pos = edit->curs1;
edit_cursor_move (edit, cursor - edit->curs1); edit_cursor_move (edit, cursor - edit->curs1);
g_free (data); g_free (data);
edit->force |= REDRAW_PAGE;
return blocklen; return blocklen;
} }
@ -2010,6 +2038,9 @@ void
edit_block_copy_cmd (WEdit * edit) edit_block_copy_cmd (WEdit * edit)
{ {
long start_mark, end_mark, current = edit->curs1; long start_mark, end_mark, current = edit->curs1;
long col_delta = 0;
long mark1, mark2;
int c1, c2;
int size; int size;
unsigned char *copy_buf; unsigned char *copy_buf;
@ -2025,7 +2056,8 @@ edit_block_copy_cmd (WEdit * edit)
if (edit->column_highlight) 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 else
{ {
@ -2037,11 +2069,7 @@ edit_block_copy_cmd (WEdit * edit)
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
if (edit->column_highlight) if (edit->column_highlight)
{ edit_set_markers (edit, edit->curs1, mark2, c1, c2);
edit_set_markers (edit, 0, 0, 0, 0);
edit_push_undo_action (edit, COLUMN_ON);
edit->column_highlight = 0;
}
else if (start_mark < current && end_mark > current) else if (start_mark < current && end_mark > current)
edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0); edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0);
@ -2054,75 +2082,71 @@ edit_block_copy_cmd (WEdit * edit)
void void
edit_block_move_cmd (WEdit * edit) edit_block_move_cmd (WEdit * edit)
{ {
long count;
long current; long current;
unsigned char *copy_buf; unsigned char *copy_buf = NULL;
long start_mark, end_mark; long start_mark, end_mark;
int deleted = 0; long line;
int x = 0;
if (eval_marks (edit, &start_mark, &end_mark)) if (eval_marks (edit, &start_mark, &end_mark))
return; 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;
line = edit->curs_line;
if (edit->mark2 < 0)
edit_mark_cmd (edit, 0);
edit_push_markers (edit); edit_push_markers (edit);
current = edit->curs1;
if (edit->column_highlight) if (edit->column_highlight)
{ {
long line; long mark1, mark2;
int size, c1, c2; int size;
line = edit->curs_line; int b_width = 0;
if (edit->mark2 < 0) int c1, c2;
edit_mark_cmd (edit, 0); int x, x2;
c1 = min (edit->column1, edit->column2); c1 = min (edit->column1, edit->column2);
c2 = max (edit->column1, edit->column2); c2 = max (edit->column1, edit->column2);
b_width = (c2 - c1);
edit_update_curs_col (edit);
x = edit->curs_col;
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;
}
/* save current selection into buffer */
copy_buf = edit_get_block (edit, start_mark, end_mark, &size); copy_buf = edit_get_block (edit, start_mark, end_mark, &size);
if (x < c2)
{ /* remove current selection */
edit_block_delete_cmd (edit); edit_block_delete_cmd (edit);
deleted = 1;
} edit->over_col = max (0, edit->over_col - b_width);
edit_move_to_line (edit, line); /* calculate the cursor pos after delete block */
edit_cursor_move (edit, current = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0);
edit_move_forward3 (edit, edit_cursor_move (edit, current - edit->curs1);
edit_bol (edit, edit->curs1), x, 0) - edit->curs1); edit_scroll_screen_over_cursor (edit);
edit_insert_column_of_text (edit, copy_buf, size, c2 - c1);
if (!deleted) /* add TWS if need before block insertion */
{ if (option_cursor_beyond_eol && edit->over_col > 0)
line = edit->curs_line; edit_insert_over (edit);
edit_update_curs_col (edit);
x = edit->curs_col; edit_insert_column_of_text (edit, copy_buf, size, b_width, &mark1, &mark2, &c1, &c2);
edit_block_delete_cmd (edit); edit_set_markers (edit, mark1, mark2, c1, c2);
edit_move_to_line (edit, line);
edit_cursor_move (edit,
edit_move_forward3 (edit,
edit_bol (edit,
edit->curs1), x, 0) - edit->curs1);
}
edit_set_markers (edit, 0, 0, 0, 0);
edit_push_undo_action (edit, COLUMN_ON);
edit->column_highlight = 0;
} }
else else
{ {
long count;
current = edit->curs1;
copy_buf = g_malloc0 (end_mark - start_mark); copy_buf = g_malloc0 (end_mark - start_mark);
edit_cursor_move (edit, start_mark - edit->curs1); edit_cursor_move (edit, start_mark - edit->curs1);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
@ -2141,6 +2165,7 @@ edit_block_move_cmd (WEdit * edit)
edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); 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_set_markers (edit, edit->curs1, edit->curs1 + end_mark - start_mark, 0, 0);
} }
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
g_free (copy_buf); g_free (copy_buf);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;