Beispiel #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 ();
        }
    }
}
Beispiel #2
0
void
gui_input_delete_previous_word ()
{
    int length_deleted, size_deleted;
    char *start, *string;
    
    if (gui_current_window->buffer->input)
    {
        if (gui_current_window->buffer->input_buffer_pos > 0)
        {
            start = utf8_add_offset (gui_current_window->buffer->input_buffer,
                                      gui_current_window->buffer->input_buffer_pos - 1);
            string = start;
            while (string && (string[0] == ' '))
            {
                string = utf8_prev_char (gui_current_window->buffer->input_buffer, string);
            }
            if (string)
            {
                while (string && (string[0] != ' '))
                {
                    string = utf8_prev_char (gui_current_window->buffer->input_buffer, string);
                }
                if (string)
                {
                    while (string && (string[0] == ' '))
                    {
                        string = utf8_prev_char (gui_current_window->buffer->input_buffer, string);
                    }
                }
            }
            
            if (string)
                string = utf8_next_char (utf8_next_char (string));
            else
                string = gui_current_window->buffer->input_buffer;
            
            size_deleted = utf8_next_char (start) - string;
            length_deleted = utf8_strnlen (string, size_deleted);
            
            gui_input_clipboard_copy (string, size_deleted);
            
            gui_input_move (gui_current_window->buffer, string, string + size_deleted, strlen (string + size_deleted));
            
            gui_current_window->buffer->input_buffer_size -= size_deleted;
            gui_current_window->buffer->input_buffer_length -= length_deleted;
            gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0';
            gui_current_window->buffer->input_buffer_pos -= length_deleted;
            gui_input_optimize_size (gui_current_window->buffer);
            gui_completion_stop (gui_current_window->buffer->completion, 1);
            gui_input_text_changed_modifier_and_signal (gui_current_window->buffer);
        }
    }
}
Beispiel #3
0
void
gui_input_delete_previous_char ()
{
    char *pos, *pos_last;
    int char_size, size_to_move;
    
    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);
            pos_last = utf8_prev_char (gui_current_window->buffer->input_buffer, pos);
            char_size = pos - pos_last;
            size_to_move = strlen (pos);
            gui_input_move (gui_current_window->buffer, pos_last, pos, size_to_move);
            gui_current_window->buffer->input_buffer_size -= char_size;
            gui_current_window->buffer->input_buffer_length--;
            gui_current_window->buffer->input_buffer_pos--;
            gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0';
            gui_input_optimize_size (gui_current_window->buffer);
            gui_completion_stop (gui_current_window->buffer->completion, 1);
            gui_input_text_changed_modifier_and_signal (gui_current_window->buffer);
        }
    }
}
Beispiel #4
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));
}
Beispiel #5
0
static void
text_model_keysym(void *data,
		  struct text_model *text_model,
		  uint32_t serial,
		  uint32_t time,
		  uint32_t key,
		  uint32_t state,
		  uint32_t modifiers)
{
	struct text_entry *entry = data;
	const char *state_label = "release";
	const char *key_label = "Unknown";
	const char *new_char;

	if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
		state_label = "pressed";
	}

	if (key == XKB_KEY_Left ||
	    key == XKB_KEY_Right) {
		if (state != WL_KEYBOARD_KEY_STATE_RELEASED)
			return;

		if (key == XKB_KEY_Left)
			new_char = utf8_prev_char(entry->text, entry->text + entry->cursor);
		else
			new_char = utf8_next_char(entry->text + entry->cursor);

		if (new_char != NULL) {
			entry->cursor = new_char - entry->text;
			if (!(modifiers & entry->keysym.shift_mask))
				entry->anchor = entry->cursor;
			widget_schedule_redraw(entry->widget);
		}

		return;
	}

	switch (key) {
		case XKB_KEY_Tab:
			key_label = "Tab";
			break;
		case XKB_KEY_KP_Enter:
		case XKB_KEY_Return:
			key_label = "Enter";
			break;
	}

	fprintf(stderr, "%s key was %s.\n", key_label, state_label);
}
Beispiel #6
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 ();
        }
    }
}
Beispiel #7
0
void
gui_input_transpose_chars ()
{
    char *start, *prev_char, saved_char[5];
    int size_prev_char, size_start_char;
    int pos_prev_char, pos_start;
    
    if (gui_current_window->buffer->input)
    {
        if ((gui_current_window->buffer->input_buffer_pos > 0)
            && (gui_current_window->buffer->input_buffer_length > 1))
        {
            if (gui_current_window->buffer->input_buffer_pos == gui_current_window->buffer->input_buffer_length)
                gui_current_window->buffer->input_buffer_pos--;
            
            start = utf8_add_offset (gui_current_window->buffer->input_buffer,
                                     gui_current_window->buffer->input_buffer_pos);
            pos_start = start - gui_current_window->buffer->input_buffer;
            prev_char = utf8_prev_char (gui_current_window->buffer->input_buffer,
                                        start);
            pos_prev_char = prev_char - gui_current_window->buffer->input_buffer;
            size_prev_char = start - prev_char;
            size_start_char = utf8_char_size (start);
            
            memcpy (saved_char, prev_char, size_prev_char);
            memcpy (prev_char, start, size_start_char);
            memcpy (prev_char + size_start_char, saved_char, size_prev_char);
            
            gui_current_window->buffer->input_buffer_pos++;
            
            gui_completion_stop (gui_current_window->buffer->completion, 1);
            
            gui_input_text_changed_modifier_and_signal (gui_current_window->buffer);
        }
    }
}
Beispiel #8
0
static void
key_handler(struct window *window,
	    struct input *input, uint32_t time,
	    uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
	    void *data)
{
	struct editor *editor = data;
	struct text_entry *entry;
	const char *new_char;
	char text[16];

	if (!editor->active_entry)
		return;

	entry = editor->active_entry;

	if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
		return;

	switch (sym) {
		case XKB_KEY_BackSpace:
			text_entry_commit_and_reset(entry);

			new_char = utf8_prev_char(entry->text, entry->text + entry->cursor);
			if (new_char != NULL)
				text_entry_delete_text(entry,
						       new_char - entry->text,
						       (entry->text + entry->cursor) - new_char);
			break;
		case XKB_KEY_Delete:
			text_entry_commit_and_reset(entry);

			new_char = utf8_next_char(entry->text + entry->cursor);
			if (new_char != NULL)
				text_entry_delete_text(entry,
						       entry->cursor,
						       new_char - (entry->text + entry->cursor));
			break;
		case XKB_KEY_Left:
			text_entry_commit_and_reset(entry);

			new_char = utf8_prev_char(entry->text, entry->text + entry->cursor);
			if (new_char != NULL) {
				entry->cursor = new_char - entry->text;
				entry->anchor = entry->cursor;
				widget_schedule_redraw(entry->widget);
			}
			break;
		case XKB_KEY_Right:
			text_entry_commit_and_reset(entry);

			new_char = utf8_next_char(entry->text + entry->cursor);
			if (new_char != NULL) {
				entry->cursor = new_char - entry->text;
				entry->anchor = entry->cursor;
				widget_schedule_redraw(entry->widget);
			}
			break;
		default:
			if (xkb_keysym_to_utf8(sym, text, sizeof(text)) <= 0)
				break;

			text_entry_commit_and_reset(entry);

			text_entry_insert_at_cursor(entry, text, 0, 0);
			break;
	}

	widget_schedule_redraw(entry->widget);
}