[gnome-builder/wip/libide-merge] add keybindings to search for word under cursor
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide-merge] add keybindings to search for word under cursor
- Date: Sun, 22 Mar 2015 02:52:40 +0000 (UTC)
commit fcf6c1a0c14f711ac99fab89339745ab8aabb469
Author: Christian Hergert <christian hergert me>
Date: Sat Mar 21 19:52:33 2015 -0700
add keybindings to search for word under cursor
This is useful to quickly search documentation for the word currently
underneath the cursor. This is similar to <shift>k in vim, except that
we are using devhelp rather than man pages.
data/keybindings/default.css | 8 +++++++-
data/keybindings/emacs.css | 7 +++++++
data/keybindings/vim.css | 8 ++++++++
libide/ide-source-view.c | 11 +++++++++++
libide/ide-source-view.h | 1 +
src/editor/gb-editor-frame.c | 27 +++++++++++++++++++++++++++
6 files changed, 61 insertions(+), 1 deletions(-)
---
diff --git a/data/keybindings/default.css b/data/keybindings/default.css
index 49693ca..8d085fc 100644
--- a/data/keybindings/default.css
+++ b/data/keybindings/default.css
@@ -16,7 +16,13 @@
bind "<ctrl>Page_Down" { "action" ("view-stack", "next-view", "") };
bind "<ctrl>KP_Page_Down" { "action" ("view-stack", "next-view", "") };
- /* toggle header/source */
+ bind "F2" { "clear-selection" ()
+ "movement" (previous-word-end, 0, 1, 1)
+ "movement" (next-word-start, 0, 1, 0)
+ "movement" (next-word-end, 1, 0, 1)
+ "request-documentation" ()
+ "clear-count" ()
+ "clear-selection" () };
bind "F4" { "action" ("view", "find-other-file", "") };
bind "F9" { "action" ("view", "preview", "") };
}
diff --git a/data/keybindings/emacs.css b/data/keybindings/emacs.css
index 630db06..67e0008 100644
--- a/data/keybindings/emacs.css
+++ b/data/keybindings/emacs.css
@@ -56,6 +56,13 @@
bind "<alt>p" { "move-error" (up) };
bind "<ctrl>j" { "action" ("view-grid", "focus-neighbor", "3") };
bind "<shift><ctrl>j" { "action" ("view-stack", "split-down", "") };
+ bind "F2" { "clear-selection" ()
+ "movement" (previous-word-end, 0, 1, 1)
+ "movement" (next-word-start, 0, 1, 0)
+ "movement" (next-word-end, 1, 0, 1)
+ "request-documentation" ()
+ "clear-count" ()
+ "clear-selection" () };
/* swap between header/source */
bind "<alt>o" { "action" ("view", "find-other-file", "") };
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 215c84e..0fe27cf 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -180,6 +180,14 @@
"movement" (first-nonspace-char, 0, 1, 0)
"clear-count" () };
+ bind "<shift>k" { "clear-selection" ()
+ "movement" (previous-word-end, 0, 1, 1)
+ "movement" (next-word-start, 0, 1, 0)
+ "movement" (next-word-end, 1, 0, 1)
+ "request-documentation" ()
+ "clear-count" ()
+ "clear-selection" () };
+
/* swallow the current character and go to insert */
bind "s" { "begin-macro" ()
"set-mode" ("vim-insert", permanent)
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 00bd8b0..cbd356f 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -213,6 +213,7 @@ enum {
PUSH_SELECTION,
PUSH_SNIPPET,
REPLAY_MACRO,
+ REQUEST_DOCUMENTATION,
RESTORE_INSERT_MARK,
SAVE_INSERT_MARK,
SELECTION_THEATRIC,
@@ -5226,6 +5227,16 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
1,
G_TYPE_BOOLEAN);
+ gSignals [REQUEST_DOCUMENTATION] =
+ g_signal_new ("request-documentation",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (IdeSourceViewClass, request_documentation),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
gSignals [RESTORE_INSERT_MARK] =
g_signal_new ("restore-insert-mark",
G_TYPE_FROM_CLASS (klass),
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index b622d1d..7235ed4 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -256,6 +256,7 @@ struct _IdeSourceViewClass
const GtkTextIter *location);
void (*replay_macro) (IdeSourceView *self,
gboolean use_count);
+ void (*request_documentation) (IdeSourceView *self);
void (*restore_insert_mark) (IdeSourceView *self);
void (*save_insert_mark) (IdeSourceView *self);
void (*selection_theatric) (IdeSourceView *self,
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index d688d35..9e4b721 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -338,6 +338,27 @@ gb_editor_frame__source_view_focus_in_event (GbEditorFrame *self,
}
static void
+gb_editor_frame__source_view_request_documentation (GbEditorFrame *self,
+ IdeSourceView *source_view)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter begin;
+ GtkTextIter end;
+ GVariant *param;
+ g_autofree gchar *text = NULL;
+
+ g_assert (GB_IS_EDITOR_FRAME (self));
+ g_assert (IDE_IS_SOURCE_VIEW (source_view));
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view));
+ gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+ text = gtk_text_iter_get_slice (&begin, &end);
+
+ param = g_variant_new_string (text);
+ gb_widget_activate_action (GTK_WIDGET (self), "workbench", "search-docs", param);
+}
+
+static void
gb_editor_frame_constructed (GObject *object)
{
GbEditorFrame *self = (GbEditorFrame *)object;
@@ -356,6 +377,12 @@ gb_editor_frame_constructed (GObject *object)
self,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (self->source_view,
+ "request-documentation",
+ G_CALLBACK (gb_editor_frame__source_view_request_documentation),
+ self,
+ G_CONNECT_SWAPPED);
+
g_signal_connect_object (self->search_entry,
"key-press-event",
G_CALLBACK (gb_editor_frame__search_key_press_event),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]