summaryrefslogtreecommitdiff
path: root/src/inlinebox.c
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2019-08-25 09:30:35 +0300
committerdefanor <defanor@uberspace.net>2019-08-25 09:30:35 +0300
commit153125149d217d866d6347f76f65345db46257c2 (patch)
tree80e50043aa5a01093f5c8dab114a66b3afa6f825 /src/inlinebox.c
parentf308e319f3170a2949624e211adf75002ee5d3f1 (diff)
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.
Diffstat (limited to 'src/inlinebox.c')
-rw-r--r--src/inlinebox.c36
1 files changed, 13 insertions, 23 deletions
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,