[gtksourceview/gnome-3-24] Force visual word movements for RTL
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gnome-3-24] Force visual word movements for RTL
- Date: Wed, 29 Mar 2017 14:18:55 +0000 (UTC)
commit 0f063fedef073e4fd6973aa476092981adc80977
Author: Mehdi Sadeghi <mehdi mehdix org>
Date: Sun Mar 19 22:18:38 2017 +0100
Force visual word movements for RTL
Upon pressing Ctrl-arrow keys, swap direction if
the pango direction of the current line is RTL.
Problem description by Daniel Boles:
Using Ctrl + Left or Right to jump by words was not accounting for the
possibility that the text was right-to-left. So, the observed direction
of movement was opposite to the direction of the arrow key pressed. This
was unintuitive and inconvenient for users editing RTL text.
This patch gets the Pango direction of the text in the current line when
Ctrl + an arrow key is pressed, and inverts the direction of movement if
it is RTL, thus ensuring that the pressed and observed direction match.
https://bugzilla.gnome.org/show_bug.cgi?id=778928
gtksourceview/gtksourceview.c | 21 ++++++++++++++++++++-
1 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 28ec45d..3674b26 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -2126,6 +2126,9 @@ move_cursor_words (GtkTextView *text_view,
GtkTextBuffer *buffer;
GtkTextIter insert;
GtkTextIter newplace;
+ GtkTextIter line_start;
+ GtkTextIter line_end;
+ gchar *line_text;
buffer = gtk_text_view_get_buffer (text_view);
@@ -2133,7 +2136,23 @@ move_cursor_words (GtkTextView *text_view,
&insert,
gtk_text_buffer_get_insert (buffer));
- newplace = insert;
+ line_start = line_end = newplace = insert;
+
+ /* Get the text of the current line for RTL analysis */
+ gtk_text_iter_set_line_offset (&line_start, 0);
+ gtk_text_iter_forward_line (&line_end);
+ line_text = gtk_text_iter_get_visible_text (&line_start, &line_end);
+
+ /* Swap direction for RTL to maintain visual cursor movement.
+ * Otherwise, cursor will move in opposite direction which is counter
+ * intuitve and causes confusion for RTL users.
+ */
+ if (pango_find_base_dir (line_text, -1) == PANGO_DIRECTION_RTL)
+ {
+ count *= -1;
+ }
+
+ g_free (line_text);
if (count < 0)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]