diff options
Diffstat (limited to 'src/interface.h')
| -rw-r--r-- | src/interface.h | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/src/interface.h b/src/interface.h index a7968d1..9c3d31e 100644 --- a/src/interface.h +++ b/src/interface.h @@ -211,21 +211,73 @@ teco_interface_get_codepage(void) } static inline gssize -teco_interface_glyphs2bytes(teco_int_t pos) +teco_interface_glyphs2bytes_rel(teco_int_t pos_glyphs, gsize pos, teco_int_t n) { - return teco_view_glyphs2bytes(teco_interface_current_view, pos); + return teco_view_glyphs2bytes_rel(teco_interface_current_view, + pos_glyphs, pos, n); } static inline teco_int_t -teco_interface_bytes2glyphs(gsize pos) +teco_interface_bytes2glyphs_rel(teco_int_t pos_glyphs, gsize pos, gssize n) { - return teco_view_bytes2glyphs(teco_interface_current_view, pos); + return teco_view_bytes2glyphs_rel(teco_interface_current_view, + pos_glyphs, pos, n); } +/** + * Convert absolute glyph position to bytes. + * + * This allows for scanning around dot and should be used if + * pos can be expected to be close to dot. + * Dot in glyphs as set by teco_current_doc_set_dot() + * \b must be up to date for this to work. + */ +static inline gssize +teco_interface_glyphs2bytes_absdot(teco_int_t pos) +{ + teco_int_t dot = teco_current_doc_get_dot(); + gsize curpos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + return teco_interface_glyphs2bytes_rel(dot, curpos, pos-dot); +} + +/** + * Convert absolute byte position to glyphs. + * + * @see teco_interface_glyphs2bytes_absdot + */ +static inline teco_int_t +teco_interface_bytes2glyphs_absdot(gsize pos) +{ + teco_int_t dot = teco_current_doc_get_dot(); + gsize curpos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + return teco_interface_bytes2glyphs_rel(dot, curpos, pos-curpos); +} + +/** + * Convert relative glyph position to bytes. + * + * Dot in glyphs as set by teco_current_doc_set_dot() + * \b must be up to date for this to work. + */ static inline gssize -teco_interface_glyphs2bytes_relative(gsize pos, teco_int_t n) +teco_interface_glyphs2bytes_reldot(teco_int_t n) +{ + teco_int_t dot = teco_current_doc_get_dot(); + gsize curpos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + return teco_interface_glyphs2bytes_rel(dot, curpos, n); +} + +/** + * Convert relative byte position to glyphs. + * + * @see teco_interface_glyphs2bytes_reldot + */ +static inline teco_int_t +teco_interface_bytes2glyphs_reldot(gssize n) { - return teco_view_glyphs2bytes_relative(teco_interface_current_view, pos, n); + teco_int_t dot = teco_current_doc_get_dot(); + gsize curpos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + return teco_interface_bytes2glyphs_rel(dot, curpos, n); } static inline teco_int_t |
