After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 686477 - pango attributes in ClutterText cannot be set while editable
pango attributes in ClutterText cannot be set while editable
Status: RESOLVED FIXED
Product: clutter
Classification: Platform
Component: ClutterText
git master
Other Linux
: Normal normal
: ---
Assigned To: clutter-maint
clutter-maint
Depends on:
Blocks:
 
 
Reported: 2012-10-19 15:39 UTC by Tomeu Vizoso
Modified: 2013-01-16 22:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
illustrates problem (1.30 KB, patch)
2012-10-19 15:39 UTC, Tomeu Vizoso
reviewed Details | Review
Allow setting pango attributes to editable text (2.24 KB, patch)
2012-12-17 19:04 UTC, Nirbheek Chauhan
reviewed Details | Review
Allow setting pango attributes to editable text + interactive test (4.87 KB, patch)
2013-01-05 06:43 UTC, Nirbheek Chauhan
committed Details | Review

Description Tomeu Vizoso 2012-10-19 15:39:22 UTC
Which would be useful for doing things such as the red underline on syntax errors in text fields.

The patch attached illustrates the problem, but I'm not sure it's the correct solution.
Comment 1 Tomeu Vizoso 2012-10-19 15:39:48 UTC
Created attachment 226834 [details] [review]
illustrates problem
Comment 2 Emmanuele Bassi (:ebassi) 2012-10-19 16:02:49 UTC
Review of attachment 226834 [details] [review]:

there's an issue of attributes coming from the markup: we don't want that, because Pango is unable to parse incomplete markup, and chokes immediately — i.e. you either get the full markup → attributes, or you don't.

GtkEntry got support for attributes recently: you could have a look at how it's been implemented.

::: clutter/clutter-text.c
@@ +502,3 @@
+  /* This will merge the markup attributes and the attributes
+     property if needed */
+  clutter_text_ensure_effective_attributes (text);

instead of merging the attributes between the ones set using set_attributes() and the ones coming from the markup(), you could do something:

  if (!priv->editable)
    clutter_text_ensure_effective_attributes (text);
  else
    {
      if (priv->effective_attrs)
        pango_attr_list_unref (priv->effective_attrs);

      priv->effective_attrs = pango_attr_list_ref (priv->attrs);
    }

or move the check inside clutter_text_ensure_effective_attrs() entirely.
Comment 3 Nirbheek Chauhan 2012-12-17 19:04:27 UTC
Created attachment 231761 [details] [review]
Allow setting pango attributes to editable text

(In reply to comment #2)
> Review of attachment 226834 [details] [review]:
> 
> there's an issue of attributes coming from the markup: we don't want that,
> because Pango is unable to parse incomplete markup, and chokes immediately —
> i.e. you either get the full markup → attributes, or you don't.
> 
> GtkEntry got support for attributes recently: you could have a look at how it's
> been implemented.
> 

Did you mean this commit? — http://git.gnome.org/browse/gtk+/commit/?id=1ac2982265c87a6164a986b6df161b1af011c944

As you say, it looks like GtkEntry does not merge attributes, and completely ignores markup. I suppose we should do the same here.

> instead of merging the attributes between the ones set using set_attributes()
> and the ones coming from the markup(), you could do something:
> 
[snip]
> or move the check inside clutter_text_ensure_effective_attrs() entirely.

The attached patch does exactly this. Apologies in advance for any screwups — I'm new to this code. :)

Should we mention this quirk in the documentation somewhere? I think developers might get confused when markup doesn't get applied as they expect it to.
Comment 4 Emmanuele Bassi (:ebassi) 2012-12-18 00:39:09 UTC
Review of attachment 231761 [details] [review]:

looks okay; it would be nice to have a test case in the interactive test suite, or an example.

::: clutter/clutter-text.c
@@ +414,3 @@
 
+  /* There's no attributes, and we ignore markup attributes for editable */
+  if (priv->attrs == NULL && priv->editable)

this condition could be folded into the previous check, for instance:

  if (priv->attrs == NULL && (priv->editable || priv->markup_attrs == NULL))
    return;
Comment 5 Nirbheek Chauhan 2013-01-04 10:42:25 UTC
(In reply to comment #4)
> Review of attachment 231761 [details] [review]:
> 
> looks okay; it would be nice to have a test case in the interactive test suite,
> or an example.
> 

Would interactive/test-text-field.c do? The test currently adds "<i>some</i> text" to the entry field, which does not work.

> ::: clutter/clutter-text.c
> @@ +414,3 @@
> 
> +  /* There's no attributes, and we ignore markup attributes for editable */
> +  if (priv->attrs == NULL && priv->editable)
> 
> this condition could be folded into the previous check, for instance:
> 
>   if (priv->attrs == NULL && (priv->editable || priv->markup_attrs == NULL))
>     return;

Oops, I don't know how I missed that. Will fix it in the next revision of the patch. :)
Comment 6 Nirbheek Chauhan 2013-01-05 06:43:25 UTC
Created attachment 232810 [details] [review]
Allow setting pango attributes to editable text + interactive test
Comment 7 Emmanuele Bassi (:ebassi) 2013-01-16 22:58:23 UTC
thanks for the patch; pushed to the master and clutter-1.14 branches.