From 153125149d217d866d6347f76f65345db46257c2 Mon Sep 17 00:00:00 2001 From: defanor Date: Sun, 25 Aug 2019 09:30:35 +0300 Subject: Merge search and selection This reduces code and state duplication, though it may be useful to refactor them further, possibly using a model similar to Emacs marks. --- src/inlinebox.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'src/inlinebox.c') diff --git a/src/inlinebox.c b/src/inlinebox.c index 7eeaeae..f500114 100644 --- a/src/inlinebox.c +++ b/src/inlinebox.c @@ -165,29 +165,6 @@ inline_box_draw (GtkWidget *widget, sel_width, ibt->alloc.height); gtk_style_context_remove_class(styleCtx, "rubberband"); } - /* duplication here (todo) */ - if (ib->match_start <= text_position + text_len && - ib->match_end >= text_position) { - guint sel_start = ibt->alloc.x, sel_width = ibt->alloc.width; - gint x_pos; - if (ib->match_start > text_position) { - pango_layout_index_to_line_x(ibt->layout, - ib->match_start - text_position, - FALSE, NULL, &x_pos); - sel_start += x_pos / PANGO_SCALE; - sel_width -= x_pos / PANGO_SCALE; - } - if (ib->match_end < text_position + text_len) { - pango_layout_index_to_line_x(ibt->layout, - ib->match_end - text_position, - FALSE, NULL, &x_pos); - sel_width -= ibt->alloc.width - x_pos / PANGO_SCALE; - } - gtk_style_context_add_class(styleCtx, "rubberband"); - gtk_render_background(styleCtx, cr, sel_start, ibt->alloc.y, - sel_width, ibt->alloc.height); - gtk_style_context_remove_class(styleCtx, "rubberband"); - } gtk_render_layout(styleCtx, cr, ibt->alloc.x, ibt->alloc.y, ibt->layout); @@ -624,6 +601,19 @@ inline_box_get_text (InlineBox *ib) return result; } +guint +inline_box_get_text_length (InlineBox *ib) +{ + GList *child; + guint len = 0; + for (child = ib->children; child; child = child->next) { + if (IS_IB_TEXT(child->data)) { + len += strlen(pango_layout_get_text(IB_TEXT(child->data)->layout)); + } + } + return len; +} + gint inline_box_search (InlineBox *ib, guint start, -- cgit v1.2.3