1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 14:56:39 +02:00

core: move function gui_input_move_to_buffer to gui-buffer.c

This commit is contained in:
Sébastien Helleu
2022-12-31 10:40:00 +01:00
parent 05839983d4
commit 73bac5491b
7 changed files with 82 additions and 83 deletions
+68
View File
@@ -4390,6 +4390,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.
*/