--- gtktextview.c	Sun Mar  3 13:07:29 2002
+++ gtktextview.c.split_cursor	Sun Mar  3 10:20:38 2002
@@ -6095,28 +6123,76 @@ gtk_text_view_mark_set_handler (GtkTextB
     gtk_text_view_reset_im_context (text_view);
 }
 
+static GtkTextDirection
+get_strong_direction (GtkTextView *text_view,
+		      GtkTextIter *iter)
+{
+  gint y;
+  GSList *lines;
+  GtkTextLine *line;
+  GtkTextLineDisplay *line_display;
+  GtkTextDirection result;
+
+  /* Horrible hack since we dont' have access to _gtk_text_iter_get_text_line (iter);
+   */
+  gtk_text_layout_get_line_yrange (text_view->layout, iter, &y, 0);
+  lines = gtk_text_layout_get_lines (text_view->layout, y, y + 1, NULL);
+
+  if (!lines)
+    return GTK_TEXT_DIR_LTR;
+
+  line = lines->data;
+  g_slist_free (lines);
+
+  line_display = gtk_text_layout_get_line_display (text_view->layout, line, FALSE);
+  result = line_display->direction;
+  gtk_text_layout_free_line_display (text_view->layout, line_display);
+
+  return result;
+}
+
 static void
-gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
-                                      gint        *x,
-                                      gint        *y)
+get_visible_cursor_pos (GtkTextView  *text_view,
+			GdkRectangle *cursor_pos)
 {
-  GdkRectangle strong_pos;
+  GdkRectangle strong_pos, weak_pos;
   GtkTextIter insert;
-
+      
   gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
-                                    gtk_text_buffer_get_mark (get_buffer (text_view),
-                                                              "insert"));
+                                    gtk_text_buffer_get_mark (get_buffer (text_view), "insert"));
+  gtk_text_layout_get_cursor_locations (text_view->layout, &insert, &strong_pos, &weak_pos);
+  
+  switch (text_view->layout->cursor_direction)
+    {
+    case GTK_TEXT_DIR_LTR:
+      *cursor_pos = (get_strong_direction (text_view, &insert) == GTK_TEXT_DIR_LTR) ? strong_pos : weak_pos;
+      break;
+    case GTK_TEXT_DIR_RTL:
+      *cursor_pos = (get_strong_direction (text_view, &insert) == GTK_TEXT_DIR_LTR) ? weak_pos : strong_pos;
+      break;
+    case GTK_TEXT_DIR_NONE:
+      *cursor_pos = strong_pos;
+      break;
+    }
+}
 
+static void
+gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
+                                      gint        *x,
+                                      gint        *y)
+{
+  GdkRectangle cursor_pos;
+  
   if ((x && text_view->virtual_cursor_x == -1) ||
       (y && text_view->virtual_cursor_y == -1))
-    gtk_text_layout_get_cursor_locations (text_view->layout, &insert, &strong_pos, NULL);
+    get_visible_cursor_pos (text_view, &cursor_pos);
 
   if (x)
     {
       if (text_view->virtual_cursor_x != -1)
         *x = text_view->virtual_cursor_x;
       else
-        *x = strong_pos.x;
+        *x = cursor_pos.x;
     }
 
   if (y)
@@ -6124,7 +6200,7 @@ gtk_text_view_get_virtual_cursor_pos (Gt
       if (text_view->virtual_cursor_x != -1)
         *y = text_view->virtual_cursor_y;
       else
-        *y = strong_pos.y + strong_pos.height / 2;
+        *y = cursor_pos.y + cursor_pos.height / 2;
     }
 }
 
@@ -6133,18 +6209,13 @@ gtk_text_view_set_virtual_cursor_pos (Gt
                                       gint         x,
                                       gint         y)
 {
-  GdkRectangle strong_pos;
-  GtkTextIter insert;
-
-  gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
-                                    gtk_text_buffer_get_mark (get_buffer (text_view),
-                                                              "insert"));
+  GdkRectangle cursor_pos;
 
   if (x == -1 || y == -1)
-    gtk_text_layout_get_cursor_locations (text_view->layout, &insert, &strong_pos, NULL);
+    get_visible_cursor_pos (text_view, &cursor_pos);
 
-  text_view->virtual_cursor_x = (x == -1) ? strong_pos.x : x;
-  text_view->virtual_cursor_y = (y == -1) ? strong_pos.y + strong_pos.height / 2 : y;
+  text_view->virtual_cursor_x = (x == -1) ? cursor_pos.x : x;
+  text_view->virtual_cursor_y = (y == -1) ? cursor_pos.y + cursor_pos.height / 2 : y;
 }
 
 /* Quick hack of a popup menu
