From bf7675246ffaf06ab42d00d8af03a21de6f79a89 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Mon, 3 Jan 2011 23:04:02 +0000 Subject: [PATCH] Ticket #2463 (do not reset selection after execute user menu) do not reset selection after execute user menu Signed-off-by: Ilia Maslakov --- src/editor/edit-impl.h | 2 +- src/editor/edit.c | 26 ++++++++++++++++++++------ src/editor/editcmd.c | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 55a5707fa..26ffaf6cb 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -289,7 +289,7 @@ 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); int edit_insert_column_of_text_from_file (WEdit * edit, int file); -int 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_forward_cmd (WEdit * edit); void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block); diff --git a/src/editor/edit.c b/src/editor/edit.c index 8241e6d8a..56d28d5fe 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -480,7 +480,7 @@ edit_load_file (WEdit * edit) if (*edit->filename) { edit->undo_stack_disable = 1; - if (!edit_insert_file (edit, edit->filename)) + if (edit_insert_file (edit, edit->filename) == 0) { edit_clean (edit); return 1; @@ -1699,8 +1699,13 @@ user_menu (WEdit * edit) } if (rc == 0) - edit_insert_file (edit, block_file); + { + long ins_len; + ins_len = edit_insert_file (edit, block_file); + if (nomark == 0 && ins_len > 0) + edit_set_markers (edit, start_mark, start_mark + ins_len, 0, 0); + } /* truncate block file */ fd = fopen (block_file, "w"); if (fd != NULL) @@ -2012,11 +2017,12 @@ edit_write_stream (WEdit * edit, FILE * f) } /* --------------------------------------------------------------------------------------------- */ -/** inserts a file at the cursor, returns 1 on success */ -int +/** inserts a file at the cursor, returns count of inserted bytes on success */ +long edit_insert_file (WEdit * edit, const char *filename) { char *p; + long ins_len = 0; p = edit_get_filter (filename); if (p != NULL) @@ -2027,6 +2033,7 @@ edit_insert_file (WEdit * edit, const char *filename) if (f != NULL) { edit_insert_stream (edit, f); + ins_len = edit->curs1 - current; edit_cursor_move (edit, current - edit->curs1); if (pclose (f) > 0) { @@ -2062,25 +2069,32 @@ edit_insert_file (WEdit * edit, const char *filename) blocklen = mc_read (file, buf, sizeof (VERTICAL_MAGIC)); if (blocklen > 0) { - /* if contain signature VERTICAL_MAGIC tnen it vertical block */ + /* if contain signature VERTICAL_MAGIC then it vertical block */ if (memcmp (buf, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)) == 0) vertical_insertion = 1; else mc_lseek (file, 0, SEEK_SET); } if (vertical_insertion) + { blocklen = edit_insert_column_of_text_from_file (edit, file); + } else + { while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) + { for (i = 0; i < blocklen; i++) edit_insert (edit, buf[i]); + } + } + ins_len = edit->curs1 - current; edit_cursor_move (edit, current - edit->curs1); g_free (buf); mc_close (file); if (blocklen != 0) return 0; } - return 1; + return ins_len; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index d91619177..e6079d3df 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -2617,7 +2617,7 @@ edit_insert_file_cmd (WEdit * edit) } else { - if (edit_insert_file (edit, exp)) + if (edit_insert_file (edit, exp) != 0) { g_free (exp); edit->force |= REDRAW_COMPLETELY;