Commit 494c76dd authored by Mehdi Sadeghi's avatar Mehdi Sadeghi Committed by Sébastien Wilmet
Browse files

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.
parent 5fe43a10
......@@ -2088,6 +2088,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);
......@@ -2095,7 +2098,23 @@ move_cursor_words (GtkTextView *text_view,
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment