summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-07-09 15:56:36 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-07-10 10:34:26 +0200
commit6f496fee3ca649144621fcf15e4906fde9fbb9fc (patch)
treecf559b1a1df7619bc0c0651ea4833b8810505ad3
parent2927f36b3e3cf86228547937cc4c5c8874bc1f85 (diff)
GtkTextView not auto-scrolling to insertion point on losing selection
In the data browser (Data Sources, shift+ctrl+f4), entering a multiline cell selects all. On cursoring to the right, the selection is lost and the cursor is placed at the end but gtk doesn't auto-scroll to the cursor so if the text needs scrolling to see the cursor it is off screen. Another cursor move makes gtk auto-scroll as wanted. So on losing selection do an initial scroll ourselves here which gives me what I want. Change-Id: I2c2f703ae173078bc38f2dab99cf8620720e88e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98441 Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--vcl/unx/gtk3/gtk3gtkinst.cxx30
1 files changed, 28 insertions, 2 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 1b94d454ba82..6a8adcbc9ad5 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -12399,9 +12399,10 @@ private:
gulong m_nChangedSignalId; // we don't disable/enable this one, it's to implement max-length
gulong m_nInsertTextSignalId;
gulong m_nCursorPosSignalId;
+ gulong m_nHasSelectionSignalId; // we don't disable/enable this one, its to implement auto-scroll to cursor on losing selection
gulong m_nVAdjustChangedSignalId;
- static void signalChanged(GtkTextView*, gpointer widget)
+ static void signalChanged(GtkTextBuffer*, gpointer widget)
{
GtkInstanceTextView* pThis = static_cast<GtkInstanceTextView*>(widget);
SolarMutexGuard aGuard;
@@ -12430,12 +12431,35 @@ private:
}
}
- static void signalCursorPosition(GtkTextView*, GParamSpec*, gpointer widget)
+ static void signalCursorPosition(GtkTextBuffer*, GParamSpec*, gpointer widget)
{
GtkInstanceTextView* pThis = static_cast<GtkInstanceTextView*>(widget);
pThis->signal_cursor_position();
}
+ static void signalHasSelection(GtkTextBuffer*, GParamSpec*, gpointer widget)
+ {
+ GtkInstanceTextView* pThis = static_cast<GtkInstanceTextView*>(widget);
+ pThis->signal_has_selection();
+ }
+
+ void signal_has_selection()
+ {
+ /*
+ in the data browser (Data Sources, shift+ctrl+f4), entering a
+ multiline cell selects all, on cursoring to the right, the selection
+ is lost and the cursor is at the end but gtk doesn't auto-scroll to
+ the cursor so if the text needs scrolling to see the cursor it is off
+ screen, another cursor makes gtk auto-scroll as wanted. So on losing
+ selection help gtk out and do the initial scroll ourselves here
+ */
+ if (!gtk_text_buffer_get_has_selection(m_pTextBuffer))
+ {
+ GtkTextMark* pMark = gtk_text_buffer_get_insert(m_pTextBuffer);
+ gtk_text_view_scroll_mark_onscreen(m_pTextView, pMark);
+ }
+ }
+
static void signalVAdjustValueChanged(GtkAdjustment*, gpointer widget)
{
GtkInstanceTextView* pThis = static_cast<GtkInstanceTextView*>(widget);
@@ -12453,6 +12477,7 @@ public:
, m_nChangedSignalId(g_signal_connect(m_pTextBuffer, "changed", G_CALLBACK(signalChanged), this))
, m_nInsertTextSignalId(g_signal_connect_after(m_pTextBuffer, "insert-text", G_CALLBACK(signalInserText), this))
, m_nCursorPosSignalId(g_signal_connect(m_pTextBuffer, "notify::cursor-position", G_CALLBACK(signalCursorPosition), this))
+ , m_nHasSelectionSignalId(g_signal_connect(m_pTextBuffer, "notify::has-selection", G_CALLBACK(signalHasSelection), this))
, m_nVAdjustChangedSignalId(g_signal_connect(m_pVAdjustment, "value-changed", G_CALLBACK(signalVAdjustValueChanged), this))
{
}
@@ -12659,6 +12684,7 @@ public:
g_signal_handler_disconnect(m_pTextBuffer, m_nInsertTextSignalId);
g_signal_handler_disconnect(m_pTextBuffer, m_nChangedSignalId);
g_signal_handler_disconnect(m_pTextBuffer, m_nCursorPosSignalId);
+ g_signal_handler_disconnect(m_pTextBuffer, m_nHasSelectionSignalId);
}
};