From 6eec759623c7d77e01370c504543a29887c28034 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 2 Jul 2011 18:16:27 +0300 Subject: [PATCH] Start fixing cursor motion around invisible text. Hit a MAJOR design problem in pushing and popping bidi iterator state. src/xdisp.c (reseat_1): Call bidi_init_it to resync the bidi iterator with IT's position. (handle_stop, back_to_previous_visible_line_start, reseat_1): Reset the from_disp_prop_p flag. src/bidi.c (bidi_cache_search): Don't assume bidi_cache_last_idx is always valid if bidi_cache_idx is valid. (bidi_cache_find_level_change): xassert that bidi_cache_last_idx is valid if it's going to be used. --- src/ChangeLog | 10 ++++++++++ src/bidi.c | 6 +++++- src/xdisp.c | 7 +++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index c2da733feb1..1a443e848a7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,15 @@ 2011-07-02 Eli Zaretskii + * xdisp.c (reseat_1): Call bidi_init_it to resync the bidi + iterator with IT's position. + (handle_stop, back_to_previous_visible_line_start, reseat_1): + Reset the from_disp_prop_p flag. + + * bidi.c (bidi_cache_search): Don't assume bidi_cache_last_idx is + always valid if bidi_cache_idx is valid. + (bidi_cache_find_level_change): xassert that bidi_cache_last_idx + is valid if it's going to be used. + * dispextern.h (struct iterator_stack_entry, struct it): New member from_disp_prop_p. diff --git a/src/bidi.c b/src/bidi.c index 87978058a5b..05c16a70f94 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -352,8 +352,10 @@ bidi_cache_search (EMACS_INT charpos, int level, int dir) { int i, i_start; - if (bidi_cache_idx) + if (bidi_cache_idx > bidi_cache_start) { + if (bidi_cache_last_idx == -1) + bidi_cache_last_idx = bidi_cache_idx - 1; if (charpos < bidi_cache[bidi_cache_last_idx].charpos) { dir = -1; @@ -418,6 +420,8 @@ bidi_cache_find_level_change (int level, int dir, int before) int i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1; int incr = before ? 1 : 0; + xassert (!dir || bidi_cache_last_idx >= 0); + if (!dir) dir = -1; else if (!incr) diff --git a/src/xdisp.c b/src/xdisp.c index 7c1b2051e57..c3d5fd9479b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -2915,6 +2915,7 @@ handle_stop (struct it *it) { it->ignore_overlay_strings_at_pos_p = 1; it->string_from_display_prop_p = 0; + it->from_disp_prop_p = 0; handle_overlay_change_p = 0; } handled = HANDLED_RECOMPUTE_PROPS; @@ -5542,6 +5543,7 @@ back_to_previous_visible_line_start (struct it *it) --IT_BYTEPOS (it2); it2.sp = 0; it2.string_from_display_prop_p = 0; + it2.from_disp_prop_p = 0; if (handle_display_prop (&it2) == HANDLED_RETURN && !NILP (val = get_char_property_and_overlay (make_number (pos), Qdisplay, Qnil, &overlay)) @@ -5740,12 +5742,13 @@ reseat_1 (struct it *it, struct text_pos pos, int set_stop_p) it->multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters)); it->sp = 0; it->string_from_display_prop_p = 0; + it->from_disp_prop_p = 0; it->face_before_selective_p = 0; if (it->bidi_p) { - it->bidi_it.first_elt = 1; + bidi_init_it (IT_CHARPOS (*it), IT_BYTEPOS (*it), FRAME_WINDOW_P (it->f), + &it->bidi_it); it->bidi_it.paragraph_dir = NEUTRAL_DIR; - it->bidi_it.disp_pos = -1; it->bidi_it.string.s = NULL; it->bidi_it.string.lstring = Qnil; it->bidi_it.string.bufpos = 0; -- 2.11.4.GIT