From e71f5d99fe97bb132f16571764213601e3160eb6 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 11 Jan 2012 21:45:42 +0200 Subject: [PATCH] Fix the last part of bug #10464 with mouse highlight at end of line. src/xdisp.c (rows_from_pos_range): Handle the case where the highlight ends on a newline. (mouse_face_from_buffer_pos): Fix off-by-one error in calculating he end column for display of highlight that ends on a newline before a R2L line. --- src/ChangeLog | 8 ++++++++ src/xdisp.c | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4c74a76e2aa..4fbfa52df3a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2012-01-11 Eli Zaretskii + + * xdisp.c (rows_from_pos_range): Handle the case where the + highlight ends on a newline. (Bug#10464) + (mouse_face_from_buffer_pos): Fix off-by-one error in calculating + he end column for display of highlight that ends on a newline + before a R2L line. + 2012-01-11 Glenn Morris * lread.c (init_lread): If no-site-lisp, remove site-lisp dirs diff --git a/src/xdisp.c b/src/xdisp.c index c3bda5594b2..dc046886039 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -25899,14 +25899,15 @@ rows_from_pos_range (struct window *w, for ( ; row->enabled_p && MATRIX_ROW_BOTTOM_Y (row) <= last_y; row++) { struct glyph_row *next = row + 1; + EMACS_INT next_start = MATRIX_ROW_START_CHARPOS (next); if (!next->enabled_p || next >= MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w) /* The first row >= START whose range of displayed characters does NOT intersect the range [START_CHARPOS..END_CHARPOS] is the row END + 1. */ - || (start_charpos < MATRIX_ROW_START_CHARPOS (next) - && end_charpos < MATRIX_ROW_START_CHARPOS (next)) + || (start_charpos < next_start + && end_charpos < next_start) || ((start_charpos > MATRIX_ROW_END_CHARPOS (next) || (start_charpos == MATRIX_ROW_END_CHARPOS (next) && !next->ends_at_zv_p @@ -25925,12 +25926,26 @@ rows_from_pos_range (struct window *w, but none of the characters it displays are in the range, it is also END + 1. */ struct glyph *g = next->glyphs[TEXT_AREA]; + struct glyph *s = g; struct glyph *e = g + next->used[TEXT_AREA]; while (g < e) { if (((BUFFERP (g->object) || INTEGERP (g->object)) - && start_charpos <= g->charpos && g->charpos < end_charpos) + && (start_charpos <= g->charpos && g->charpos < end_charpos + /* If the buffer position of the first glyph in + the row is equal to END_CHARPOS, it means + the last character to be highlighted is the + newline of ROW, and we must consider NEXT as + END, not END+1. */ + || ((!next->reversed_p && g == s + || next->reversed_p && g == e - 1) + && (g->charpos == end_charpos + /* Special case for when NEXT is an + empty line at ZV. */ + || (g->charpos == -1 + && !row->ends_at_zv_p + && next_start == end_charpos))))) /* A glyph that comes from DISP_STRING is by definition to be highlighted. */ || EQ (g->object, disp_string)) @@ -25942,6 +25957,13 @@ rows_from_pos_range (struct window *w, *end = row; break; } + /* The first row that ends at ZV must be the last to be + highlighted. */ + else if (next->ends_at_zv_p) + { + *end = next; + break; + } } } } @@ -26255,6 +26277,19 @@ mouse_face_from_buffer_pos (Lisp_Object window, } x += end->pixel_width; } + /* If we exited the above loop because we arrived at the last + glyph of the row, and its buffer position is still not in + range, it means the last character in range is the preceding + newline. Bump the end column and x values to get past the + last glyph. */ + if (end == glyph + && BUFFERP (end->object) + && (end->charpos < start_charpos + || end->charpos >= end_charpos)) + { + x += end->pixel_width; + ++end; + } hlinfo->mouse_face_end_x = x; hlinfo->mouse_face_end_col = end - r2->glyphs[TEXT_AREA]; } -- 2.11.4.GIT