示例#1
0
void
gui_input_move_previous_word ()
{
    char *pos;
    
    if (gui_current_window->buffer->input)
    {
        if (gui_current_window->buffer->input_buffer_pos > 0)
        {
            pos = utf8_add_offset (gui_current_window->buffer->input_buffer,
                                   gui_current_window->buffer->input_buffer_pos - 1);
            while (pos && (pos[0] == ' '))
            {
                pos = utf8_prev_char (gui_current_window->buffer->input_buffer, pos);
            }
            if (pos)
            {
                while (pos && (pos[0] != ' '))
                {
                    pos = utf8_prev_char (gui_current_window->buffer->input_buffer, pos);
                }
                if (pos)
                    pos = utf8_next_char (pos);
                else
                    pos = gui_current_window->buffer->input_buffer;
                gui_current_window->buffer->input_buffer_pos = utf8_pos (gui_current_window->buffer->input_buffer,
                                                             pos - gui_current_window->buffer->input_buffer);
            }
            else
                gui_current_window->buffer->input_buffer_pos = 0;
            
            gui_input_text_cursor_moved_signal ();
        }
    }
}
示例#2
0
TEST(Utf8, Move)
{
    char *ptr;

    /* previous/next char */
    POINTERS_EQUAL(NULL, utf8_prev_char (NULL, NULL));
    POINTERS_EQUAL(NULL, utf8_next_char (NULL));
    ptr = utf8_next_char (noel_valid);
    STRCMP_EQUAL("oël", ptr);
    ptr = utf8_next_char (ptr);
    STRCMP_EQUAL("ël", ptr);
    ptr = utf8_next_char (ptr);
    STRCMP_EQUAL("l", ptr);
    ptr = utf8_prev_char (noel_valid, ptr);
    ptr = utf8_prev_char (noel_valid, ptr);
    ptr = utf8_prev_char (noel_valid, ptr);
    STRCMP_EQUAL("noël", ptr);
    POINTERS_EQUAL(noel_valid, ptr);

    /* add offset */
    ptr = utf8_add_offset (noel_valid, 0);
    STRCMP_EQUAL(noel_valid, ptr);
    ptr = utf8_add_offset (noel_valid, 1);
    STRCMP_EQUAL("oël", ptr);
    ptr = utf8_add_offset (noel_valid, 3);
    STRCMP_EQUAL("l", ptr);

    /* real position */
    LONGS_EQUAL(0, utf8_real_pos (noel_valid, 0));
    LONGS_EQUAL(1, utf8_real_pos (noel_valid, 1));
    LONGS_EQUAL(2, utf8_real_pos (noel_valid, 2));
    LONGS_EQUAL(4, utf8_real_pos (noel_valid, 3));

    /* position */
    LONGS_EQUAL(0, utf8_pos (noel_valid, 0));
    LONGS_EQUAL(1, utf8_pos (noel_valid, 1));
    LONGS_EQUAL(2, utf8_pos (noel_valid, 2));
    LONGS_EQUAL(3, utf8_pos (noel_valid, 4));
}
示例#3
0
void
gui_input_move_next_word ()
{
    char *pos;
    
    if (gui_current_window->buffer->input)
    {
        if (gui_current_window->buffer->input_buffer_pos <
            gui_current_window->buffer->input_buffer_length)
        {
            pos = utf8_add_offset (gui_current_window->buffer->input_buffer,
                                   gui_current_window->buffer->input_buffer_pos);
            while (pos[0] && (pos[0] == ' '))
            {
                pos = utf8_next_char (pos);
            }
            if (pos[0])
            {
                while (pos[0] && (pos[0] != ' '))
                {
                    pos = utf8_next_char (pos);
                }
                if (pos[0])
                    gui_current_window->buffer->input_buffer_pos =
                        utf8_pos (gui_current_window->buffer->input_buffer,
                                  pos - gui_current_window->buffer->input_buffer);
                else
                    gui_current_window->buffer->input_buffer_pos = 
                        gui_current_window->buffer->input_buffer_length;
            }
            else
                gui_current_window->buffer->input_buffer_pos =
                    utf8_pos (gui_current_window->buffer->input_buffer,
                              utf8_prev_char (gui_current_window->buffer->input_buffer, pos) - gui_current_window->buffer->input_buffer);
            
            gui_input_text_cursor_moved_signal ();
        }
    }
}
示例#4
0
void
gui_input_complete (struct t_gui_buffer *buffer)
{
    int i;
    
    if (!buffer->completion)
        return;
    
    if (buffer->completion->word_found)
    {
        /* replace word with new completed word into input buffer */
        if (buffer->completion->diff_size > 0)
        {
            buffer->input_buffer_size +=
                buffer->completion->diff_size;
            buffer->input_buffer_length +=
                buffer->completion->diff_length;
            gui_input_optimize_size (buffer);
            buffer->input_buffer[buffer->input_buffer_size] = '\0';
            for (i = buffer->input_buffer_size - 1;
                 i >=  buffer->completion->position_replace +
                     (int)strlen (buffer->completion->word_found); i--)
            {
                buffer->input_buffer[i] =
                    buffer->input_buffer[i - buffer->completion->diff_size];
            }
        }
        else
        {
            for (i = buffer->completion->position_replace +
                     strlen (buffer->completion->word_found);
                 i < buffer->input_buffer_size; i++)
            {
                buffer->input_buffer[i] =
                    buffer->input_buffer[i - buffer->completion->diff_size];
            }
            buffer->input_buffer_size += buffer->completion->diff_size;
            buffer->input_buffer_length += buffer->completion->diff_length;
            gui_input_optimize_size (buffer);
            buffer->input_buffer[buffer->input_buffer_size] = '\0';
        }
            
        strncpy (buffer->input_buffer + buffer->completion->position_replace,
                 buffer->completion->word_found,
                 strlen (buffer->completion->word_found));
        buffer->input_buffer_pos =
            utf8_pos (buffer->input_buffer,
                      buffer->completion->position_replace) +
            utf8_strlen (buffer->completion->word_found);
        
        /* position is < 0 this means only one word was found to complete,
           so reinit to stop completion */
        if (buffer->completion->position >= 0)
            buffer->completion->position = utf8_real_pos (buffer->input_buffer,
                                                      buffer->input_buffer_pos);
        
        /* add space if needed after completion */
        if (buffer->completion->add_space)
        {
            if (buffer->input_buffer[utf8_real_pos (buffer->input_buffer,
                                                    buffer->input_buffer_pos)] != ' ')
                gui_input_insert_string (buffer, " ",
                                         buffer->input_buffer_pos);
            else
                buffer->input_buffer_pos++;
            if (buffer->completion->position >= 0)
                buffer->completion->position++;
        }
        gui_input_text_changed_modifier_and_signal (buffer);
    }
}