Пример #1
0
/**
 * Handles the keypress events from webview and inputbox.
 */
VbResult input_keypress(int key)
{
    static gboolean ctrlo = false;

    if (ctrlo) {
        /* if we are in ctrl-O mode perform the next keys as normal mode
         * commands until the command is complete or error */
        VbResult res = normal_keypress(key);
        if (res != RESULT_MORE) {
            ctrlo = false;
            /* Don't overwrite the mode label in case we landed in another
             * mode. This might occurre by CTRL-0 CTRL-Z or after running ex
             * command, where we mainly end up in normal mode. */
            if (vb.mode->id == 'i') {
                /* reenter the input mode */
                input_enter();
            }
        }
        return res;
    }

    switch (key) {
        case CTRL('['): /* esc */
            mode_enter('n');
            return RESULT_COMPLETE;

        case CTRL('O'):
            /* enter CTRL-0 mode to execute next command in normal mode */
            ctrlo           = true;
            vb.mode->flags |= FLAG_NOMAP;
            vb_update_mode_label("-- (input) --");
            return RESULT_MORE;

        case CTRL('T'):
            return input_open_editor();

        case CTRL('Z'):
            mode_enter('p');
            return RESULT_COMPLETE;
    }

    vb.state.processed_key = false;
    return RESULT_ERROR;
}
Пример #2
0
Файл: dom.c Проект: uggedal/vimb
static gboolean auto_insert(Element *element)
{
    /* don't change mode if we are in pass through mode */
    if (vb.mode->id != 'p' && dom_is_editable(element)) {
        mode_enter('i');

        return true;
    }
    return false;
}
Пример #3
0
/**
 * Handles the keypress events from webview and inputbox.
 */
VbResult ex_keypress(int key)
{
    GtkTextIter start, end;
    GtkTextBuffer *buffer = vb.gui.buffer;
    GtkTextMark *mark;

    /* delegate call to the submode */
    if (RESULT_COMPLETE == hints_keypress(key)) {
        return RESULT_COMPLETE;
    }

    switch (key) {
        case KEY_TAB:
            complete(1);
            break;

        case KEY_SHIFT_TAB:
            complete(-1);
            break;

        case CTRL('['):
        case CTRL('C'):
            mode_enter('n');
            vb_set_input_text("");
            break;

        case KEY_CR:
            input_activate();
            break;

        case KEY_UP:
            history(true);
            break;

        case KEY_DOWN:
            history(false);
            break;

        /* basic command line editing */
        case CTRL('H'):
            /* delete the last char before the cursor */
            mark = gtk_text_buffer_get_insert(buffer);
            gtk_text_buffer_get_iter_at_mark(buffer, &start, mark);
            gtk_text_buffer_backspace(buffer, &start, true, true);
            break;

        case CTRL('W'):
            /* delete word backward from cursor */
            mark = gtk_text_buffer_get_insert(buffer);
            gtk_text_buffer_get_iter_at_mark(buffer, &end, mark);

            /* copy the iter to build start and end point for deletion */
            start = end;

            /* move the iterator to the beginning of previous word */
            if (gtk_text_iter_backward_word_start(&start)) {
                gtk_text_buffer_delete(buffer, &start, &end);
            }
            break;

        case CTRL('B'):
            /* move the cursor direct behind the prompt */
            gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(vb.state.prompt));
            gtk_text_buffer_place_cursor(buffer, &start);
            break;

        case CTRL('E'):
            /* move the cursor to the end of line */
            gtk_text_buffer_get_end_iter(buffer, &start);
            gtk_text_buffer_place_cursor(buffer, &start);
            break;

        case CTRL('U'):
            /* remove everythings between cursor and prompt */
            mark = gtk_text_buffer_get_insert(buffer);
            gtk_text_buffer_get_iter_at_mark(buffer, &end, mark);
            gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(vb.state.prompt));
            gtk_text_buffer_delete(buffer, &start, &end);
            break;

        default:
            /* if is printable ascii char, than write it at the cursor
             * position into input box */
            if (key >= 0x20 && key <= 0x7e) {
                gtk_text_buffer_insert_at_cursor(buffer, (char[2]){key, 0}, 1);
            } else {