[maemo-developers] Word completion in Fremantle

From: Cornelius Hald hald at icandy.de
Date: Fri Nov 13 12:21:59 EET 2009

> sorry for the delay in answering.

Don´t worry :)

> I understand that what you really want is that the suggested text has
> the same attributes (size, font) as the text around it. It seems a
> pretty obvious thing, taking into account that different editors (i.e.
> Notes) allow for different sizes and fonts.

For most applications (including Notes) it´s working out of the box. The 
problem is, that I use the text view in a (maybe) non-standard way. I´ll 
try to explain:

Let´s assume we want to write the word "Halloween" in bold and once we 
have written "Hallo" the auto completion kicks in and sets the preedit 
text "ween". The "ween" part should also be bold.

In Notes the cursor is always between the starting and ending 
GtkTextTag. So everything you type will automatically be bold. Gtk takes 
care of that and will push the end tag further to the right with every 
entered character. So in the case of "Halloween" it looks like that:

  H a l l o
^         ^
<b>      </b>          <- GtkTextTags

Now the preedit text is inserted at the cursor position:

  H a l l o w e e n
^                 ^
<b>              </b>  <- GtkTextTags

Because the preedit text is inserted between the GtkTextTags the preedit 
text is automatically formatted in the same manner as the first part of 
the text. This is the reason why it works for most editors out of the box.

Now in Conboy I had to do the handling of formatting differently. It 
works like that:
There is a set of "active formatting tags" and with each keypress those 
tags are applied to the just inserted character. Basically like this:

  H     a     l     ...
  ^     ^     ^
<b>   <b>   <b>
</b>  </b>  </b>

GtkTextBuffer now automatically merges those tags together to one. The 
result looks like this:

  H a l l o
  ^       ^
<b>     </b>           <- GtkTextTags

Now the cursor is on the right side of the character 'o' and the word 
completion inserts the preedit text at the cursor position. This time 
however the cursor is outside the GtkTextTags and therefore the preedit 
text does not get the specified formatting. The result would be:

  H a l l o w e e n
  ^       ^
<b>     </b>           <- GtkTextTags

"Hallo" is bold "ween" not.

Please note this problem only exists for the preedit text. Once the user 
presses the right-cursor button the preedit text is normally inserted 
into the GtkTextBuffer and I can apply tags as I do it with every key 
press. With bold is not that bad, but with different font sizes it looks 
really ugly.

This is the reason why I was looking for a way to apply tags to the 
preedit text. I know I could (theoretically) change my code to make sure 
that the cursor is always inside the tags and not outside. But this 
would be a very intrusive change to the code with many side effects. So 
I would like to avoid that.

> If that is the case, yes, extending the class would be overkill. From
> the IM context it is possible to get a list of Pango attributes for the
> insert position and return them together with the preedit text. This
> would solve the problem.

I´ve seen that. But it would only solve the problem if I´m able to 
change those Pango attribtues. Because the Pango attributes are 
generated by looking at the GtkTextTags. Unfortunately I couldn´t find a 
way to change the Pango attributes from outside the context.

> I am aware that the IM code at stage.maemo.org hasn't been updated in a
> while, so maybe what I just said will be in the final version :-)

Ok, so if there have been changes to that code it might still be 
possible. OTOH it looks like HildonIMContext does not introduce own API 
at all, but just overwrites some methods of GtkIMContext, therefore the 
API of GtkIMContext should apply and with this API I see now way of 
altering those Pango attributes.

Thanks a lot for your reply and if you have other suggestions or 
corrections I would be very happy to hear them. At the moment I think I 
have to live with it or change my code. If changing my own code would be 
easy I would have done that already of course...

More information about the maemo-developers mailing list