Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Warepire/5877fe8fbdbfcc78921878bcff199c61 to your computer and use it in GitHub Desktop.
Save Warepire/5877fe8fbdbfcc78921878bcff199c61 to your computer and use it in GitHub Desktop.
From c92084c13fbfe343cf8c97222f78681609e7a694 Mon Sep 17 00:00:00 2001
From: Kenneth Lyons <ixjlyons@gmail.com>
Date: Sat, 9 Apr 2016 12:11:09 -0700
Subject: [PATCH] Add function to get selection position.
---
src/vte/vteterminal.h | 4 ++++
src/vtegtk.cc | 24 ++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index 95ffac6d..87594411 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -347,6 +347,10 @@ char *vte_terminal_get_text_range(VteTerminal *terminal,
gpointer user_data,
GArray *attributes) _VTE_GNUC_NONNULL(1) G_GNUC_MALLOC;
_VTE_PUBLIC
+void vte_terminal_get_selection_position(VteTerminal *terminal,
+ glong *column,
+ glong *row) _VTE_GNUC_NONNULL(1);
+_VTE_PUBLIC
void vte_terminal_get_cursor_position(VteTerminal *terminal,
glong *column,
glong *row) _VTE_GNUC_NONNULL(1);
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 9bf51673..0db09df6 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2197,6 +2197,30 @@ vte_terminal_get_selection(VteTerminal *terminal)
return g_strdup (IMPL(terminal)->m_selection[VTE_SELECTION_PRIMARY]->str);
}
+/**
+ * vte_terminal_get_selection_position:
+ * @terminal: a #VteTerminal
+ * @column: (out) (allow-none): a location to store the column, or %NULL
+ * @row: (out) (allow-none): a location to store the row, or %NULL
+ *
+ * Reads the location of the first row/column of the current selection.
+ */
+void
+vte_terminal_get_selection_position(VteTerminal *terminal,
+ long *column,
+ long *row)
+{
+ g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+ auto impl = IMPL(terminal);
+ if (column) {
+ *column = impl->m_selection_resolved.start_column();
+ }
+ if (row) {
+ *row = impl->m_selection_resolved.start_row();
+ }
+}
+
/**
* vte_terminal_get_cursor_position:
* @terminal: a #VteTerminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment