forked from AuroraMiddleware/gtk
TextView—Fix inverted movements by arrows in RTL
Using Ctrl + left/right to skip between words, or left/right to cancel a selection, were causing movement on the screen in the opposite direction of the glyph on the key. This was surprising and awful UX for RTL users. This is based on a patch covering the former case by: Author: Mehdi Sadeghi <mehdi@mehdix.org> Date: Sat Feb 18 02:16:00 2017 +0000 https://bugzilla.gnome.org/show_bug.cgi?id=136059
This commit is contained in:
parent
393e7aacc6
commit
3e5d5f8899
@ -43,6 +43,7 @@
|
||||
#include "gtkselectionprivate.h"
|
||||
#include "gtktextbufferrichtext.h"
|
||||
#include "gtktextdisplay.h"
|
||||
#include "gtktextiterprivate.h"
|
||||
#include "gtktextview.h"
|
||||
#include "gtkimmulticontext.h"
|
||||
#include "gtkprivate.h"
|
||||
@ -6415,6 +6416,17 @@ move_cursor (GtkTextView *text_view,
|
||||
gtk_text_view_check_cursor_blink (text_view);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
iter_line_is_rtl (GtkTextIter *iter, GtkTextLayout *layout)
|
||||
{
|
||||
GtkTextLine *line = _gtk_text_iter_get_text_line (iter);
|
||||
GtkTextLineDisplay *display = gtk_text_layout_get_line_display (layout, line, FALSE);
|
||||
const gchar *text = pango_layout_get_text (display->layout);
|
||||
PangoDirection pango_dir = pango_find_base_dir (text, -1);
|
||||
|
||||
return pango_dir == PANGO_DIRECTION_RTL;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_text_view_move_cursor (GtkTextView *text_view,
|
||||
GtkMovementStep step,
|
||||
@ -6509,15 +6521,19 @@ gtk_text_view_move_cursor (GtkTextView *text_view,
|
||||
|
||||
if (! extend_selection)
|
||||
{
|
||||
gboolean move_forward = count > 0;
|
||||
GtkTextIter sel_bound;
|
||||
|
||||
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &sel_bound,
|
||||
gtk_text_buffer_get_selection_bound (get_buffer (text_view)));
|
||||
|
||||
if (iter_line_is_rtl (&insert, priv->layout))
|
||||
move_forward = !move_forward;
|
||||
|
||||
/* if we move forward, assume the cursor is at the end of the selection;
|
||||
* if we move backward, assume the cursor is at the start
|
||||
*/
|
||||
if (count > 0)
|
||||
if (move_forward)
|
||||
gtk_text_iter_order (&sel_bound, &insert);
|
||||
else
|
||||
gtk_text_iter_order (&insert, &sel_bound);
|
||||
@ -6549,6 +6565,9 @@ gtk_text_view_move_cursor (GtkTextView *text_view,
|
||||
break;
|
||||
|
||||
case GTK_MOVEMENT_WORDS:
|
||||
if (iter_line_is_rtl (&newplace, priv->layout))
|
||||
count *= -1;
|
||||
|
||||
if (count < 0)
|
||||
gtk_text_iter_backward_visible_word_starts (&newplace, -count);
|
||||
else if (count > 0)
|
||||
|
Loading…
Reference in New Issue
Block a user