[vte] widget: Add API to get selected text
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Add API to get selected text
- Date: Sun, 3 Jul 2022 19:49:05 +0000 (UTC)
commit 3ed53bfaa7344ce5b7727a60a2d33315b15201e5
Author: Jamie Murphy <hello jamiethalacker dev>
Date: Sun Jul 3 21:48:03 2022 +0200
widget: Add API to get selected text
Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/2563
src/vte/vteterminal.h | 3 +++
src/vtegtk.cc | 32 ++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
---
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index 0d3cf51c..6f8a7751 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -358,6 +358,9 @@ gboolean vte_terminal_get_allow_hyperlink(VteTerminal *terminal) _VTE_CXX_NOEXCE
_VTE_PUBLIC
gboolean vte_terminal_get_has_selection(VteTerminal *terminal) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1);
+_VTE_PUBLIC
+char* vte_terminal_get_text_selected(VteTerminal* terminal) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1);
+
/* Set what happens when the user strikes backspace or delete. */
_VTE_PUBLIC
void vte_terminal_set_backspace_binding(VteTerminal *terminal,
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index dba6ed76..034c023b 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -5576,6 +5576,38 @@ catch (...)
return false;
}
+/**
+ * vte_terminal_get_text_selected:
+ * @terminal: a #VteTerminal
+ *
+ * Gets the currently selected text.
+ *
+ * Returns: (transfer full) (nullable): a newly allocated string containing the selected text, or %NULL if
there is no selection
+ *
+ * Since: 0.70
+ */
+char*
+vte_terminal_get_text_selected(VteTerminal* terminal) noexcept
+try
+{
+ g_return_val_if_fail(VTE_IS_TERMINAL(terminal), nullptr);
+
+ auto const selection = IMPL(terminal)->m_selection_resolved;
+ return vte_terminal_get_text_range(terminal,
+ selection.start_row(),
+ selection.start_column(),
+ selection.last_row(),
+ selection.end_column(),
+ nullptr,
+ nullptr,
+ nullptr);
+}
+catch (...)
+{
+ vte::log_exception();
+ return nullptr;
+}
+
/**
* vte_terminal_get_icon_title:
* @terminal: a #VteTerminal
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]