gboolean command_search(const Arg *arg) { static short dir; /* last direction 1 forward, -1 backward*/ const char *query; static gboolean newsearch = true; gboolean forward; if (arg->i == 0) { #ifdef FEATURE_SEARCH_HIGHLIGHT webkit_web_view_unmark_text_matches(vb.gui.webview); vb.state.search_matches = 0; vb_update_statusbar(); #endif newsearch = true; return true; } /* copy search query for later use */ if (arg->s) { /* set search direction only when the searching is started */ dir = arg->i > 0 ? 1 : -1; query = arg->s; /* add new search query to history and search register */ vb_register_add('/', query); history_add(HISTORY_SEARCH, query, NULL); } else { /* no search phrase given - continue a previous search */ query = vb_register_get('/'); } forward = (arg->i * dir) > 0; if (query) { unsigned int count = abs(arg->i); if (newsearch) { #ifdef FEATURE_SEARCH_HIGHLIGHT /* highlight matches if the search is started new or continued * after switch to normal mode which calls this function with * COMMAND_SEARCH_OFF */ vb.state.search_matches = webkit_web_view_mark_text_matches(vb.gui.webview, query, false, 0); webkit_web_view_set_highlight_text_matches(vb.gui.webview, true); vb_update_statusbar(); #endif newsearch = false; /* skip first search because this is done during typing in ex * mode, else the search will mark the next match as active */ if (count) { count -= 1; } } while (count--) { if (!webkit_web_view_search_text(vb.gui.webview, query, false, forward, true)) { break; } }; } return true; }
static VbResult normal_open_clipboard(Client *c, const NormalCmdInfo *info) { Arg a = {info->key == 'P' ? TARGET_NEW : TARGET_CURRENT}; /* if register is not the default - read out of the internal register */ if (info->reg) { a.s = g_strdup(vb_register_get(c, info->reg)); } else { /* if no register is given use the system clipboard */ a.s = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); if (!a.s) { a.s = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_NONE)); } } if (a.s) { vb_load_uri(c, &a); g_free(a.s); return RESULT_COMPLETE; } return RESULT_ERROR; }
/** * Handles the keypress events from webview and inputbox. */ VbResult ex_keypress(int key) { GtkTextIter start, end; gboolean check_empty = false; GtkTextBuffer *buffer = vb.gui.buffer; GtkTextMark *mark; VbResult res; const char *text; /* delegate call to hint mode if this is active */ if (vb.mode->flags & FLAG_HINTING && RESULT_COMPLETE == hints_keypress(key)) { return RESULT_COMPLETE; } /* process the register */ if (info.phase == PHASE_REG) { info.reg = (char)key; info.phase = PHASE_REG; /* insert the register text at cursor position */ text = vb_register_get((char)key); if (text) { gtk_text_buffer_insert_at_cursor(buffer, text, strlen(text)); } res = RESULT_COMPLETE; } else { res = RESULT_COMPLETE; switch (key) { case KEY_TAB: complete(1); break; case KEY_SHIFT_TAB: complete(-1); break; case CTRL('['): case CTRL('C'): vb_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); check_empty = 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); } check_empty = true; 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 everything 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; case CTRL('R'): info.phase = PHASE_REG; vb.mode->flags |= FLAG_NOMAP; res = RESULT_MORE; 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 {