diff options
Diffstat (limited to 'src/gui/gui-buffer.c')
-rw-r--r-- | src/gui/gui-buffer.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index f871e5593..b4f0d9ce0 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -4391,6 +4391,74 @@ gui_buffer_undo_free_all (struct t_gui_buffer *buffer) } /* + * Moves buffer input content and undo data to another buffer. + */ + +void +gui_buffer_input_move_to_buffer (struct t_gui_buffer *from_buffer, + struct t_gui_buffer *to_buffer) +{ + int is_command; + + /* + * move of input is allowed if: + * - 2 buffers are different + * - input_share is not set to "none" + * - input buffer in first buffer is not empty + */ + if (!from_buffer || !to_buffer || (from_buffer == to_buffer) + || (CONFIG_INTEGER(config_look_input_share) == CONFIG_LOOK_INPUT_SHARE_NONE) + || !from_buffer->input_buffer || !from_buffer->input_buffer[0]) + return; + + /* + * if input is command and that only text is allowed, + * or if input is text and that only command is allowed, + * then do nothing + */ + is_command = (string_input_for_buffer (from_buffer->input_buffer) == NULL) ? 1 : 0; + if ((is_command && (CONFIG_INTEGER(config_look_input_share) == CONFIG_LOOK_INPUT_SHARE_TEXT)) + || (!is_command && (CONFIG_INTEGER(config_look_input_share) == CONFIG_LOOK_INPUT_SHARE_COMMANDS))) + return; + + /* + * if overwrite is off and that input of target buffer is not empty, + * then do nothing + */ + if ((!CONFIG_BOOLEAN(config_look_input_share_overwrite)) + && to_buffer->input_buffer && to_buffer->input_buffer[0]) + return; + + /* move input_buffer */ + if (to_buffer->input_buffer) + free (to_buffer->input_buffer); + to_buffer->input_buffer = from_buffer->input_buffer; + to_buffer->input_buffer_alloc = from_buffer->input_buffer_alloc; + to_buffer->input_buffer_size = from_buffer->input_buffer_size; + to_buffer->input_buffer_length = from_buffer->input_buffer_length; + to_buffer->input_buffer_pos = from_buffer->input_buffer_pos; + to_buffer->input_buffer_1st_display = from_buffer->input_buffer_1st_display; + gui_buffer_input_buffer_init (from_buffer); + + /* move undo data */ + gui_buffer_undo_free_all (to_buffer); + (to_buffer->input_undo_snap)->data = (from_buffer->input_undo_snap)->data; + (to_buffer->input_undo_snap)->pos = (from_buffer->input_undo_snap)->pos; + to_buffer->input_undo = from_buffer->input_undo; + to_buffer->last_input_undo = from_buffer->last_input_undo; + to_buffer->ptr_input_undo = from_buffer->ptr_input_undo; + to_buffer->input_undo_count = from_buffer->input_undo_count; + (from_buffer->input_undo_snap)->data = NULL; + (from_buffer->input_undo_snap)->pos = 0; + from_buffer->input_undo = NULL; + from_buffer->last_input_undo = NULL; + from_buffer->ptr_input_undo = NULL; + from_buffer->input_undo_count = 0; + + gui_completion_stop (from_buffer->completion); +} + +/* * Searches for a visited buffer in list of visited buffers. */ |