Page MenuHomePhabricator

Explain how to use Grapheme_Cluster/word_boundaries movements on Canvas.Text
Closed, ResolvedPublic

Description

I'm just putting it here so we have information about it for posterity.

There's no more garpheme_cluster_next, delete and etc. These were removed because they were redundant and can be easily achieved using other functions.

The descriptions here also apply to word_start/end.

For simplicity I'm going to mark clusters as repeated capital letters, so AAA is a cluster of 3 characters. The first position (beginning of the text) is 0.

Consider the text: AAAbc def
Now, if the cursor is at position 0 both cluster_start and end do nothing, as it's already at a cluster boundary. At positions 1 and 2 they move to 0 and 3 respectively. At position 3 they again not move because they are already at a cluster limit.

To implement moving to the next cluster position (cluster_next) you'd need to do:

if (!efl2_text_cursor_cluster_end(cur))
  {
     efl2_text_cursor_char_next(cur);
     efl2_text_cursor_cluster_end(cur);
  }

This will make it so every position from 0 to 2 will move you to position 3 and from position 3 you'd move to position 4.

For prev:

if (!efl2_text_cursor_cluster_start(cur))
  {
     efl2_text_cursor_char_prev(cur);
     efl2_text_cursor_cluster_start(cur);
  }

Again, for positions 1-3 you'd move to position 0. From position 4 to position 3.

To delete the cluster after the cursor (hitting the delete key) you'd therefore do:

efl2_text_cursor_cluster_start(cur);
efl2_text_cursor_copy(cur, start);
efl2_text_cursor_char_next(cur);
efl2_text_cursor_cluster_end(cur);
efl2_text_cursor_range_delete(start, cur);

To set the coordinates of a grapheme:

efl2_text_cursor_coord_set(cur, x, y);
efl2_text_cursor_cluster_start(cur);
tasn created this task.Oct 11 2019, 1:21 AM
tasn closed this task as Resolved.