Page MenuHome

Add set selection function to text api

Authored by Gyro Gearloose (pink.vertex) on Nov 9 2015, 11:53 AM.



There is no operator/api function available to set the cursor and selection passing line and column as arguments.

See How to set cursor position in the text editor?

Diff Detail

rB Blender

Event Timeline

Gyro Gearloose (pink.vertex) retitled this revision from to Add set selection function to text api.
Gyro Gearloose (pink.vertex) updated this object.
Gyro Gearloose (pink.vertex) set the repository for this revision to rB Blender.
Campbell Barton (campbellbarton) requested changes to this revision.EditedAug 1 2019, 11:07 AM

In general this is useful, there is a problem though.

The character values are incompatible with Text.current_character which don't account for multi-byte characters.

The RNA properties current_character and select_end_character should be wrapped by get/set functions to make the values index the characters instead of the bytes, then they will be compatible with inputs for this function.

This revision now requires changes to proceed.Aug 1 2019, 11:07 AM

These functions have been moved into BLI_string_utf8 so there is no need to define this inline.

int BLI_str_utf8_offset_to_index(const char *str, int offset);
int BLI_str_utf8_offset_from_index(const char *str, int index);
int BLI_str_utf8_offset_to_column(const char *str, int offset);
int BLI_str_utf8_offset_from_column(const char *str, int column);

This patch deals with set selection: D5881

A different diff ended up being committed.