From cc7ce30fa6a2ebdb2e14d589b11520757e5a20e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 13 Feb 2016 12:22:18 +0100 Subject: text-motion: add functions to get/set position based on display width This is inherently a tricky thing to do because we cannot rely on the current display state. The reason being that the position/cursor which is modified might not currently be in the visible area. Tabs are a particular problem because they have a variable display width. However this new code is certainly not worse than the current behaviour which relies on text_line_char_{get,set} and thus simply counts graphemes. Not yet completely convinced that this is the right approach. --- text-motions.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'text-motions.h') diff --git a/text-motions.h b/text-motions.h index cf108b3..dfe3acc 100644 --- a/text-motions.h +++ b/text-motions.h @@ -43,6 +43,10 @@ size_t text_line_offset(Text*, size_t pos, size_t off); int text_line_char_get(Text*, size_t pos); /* get position of the `count' grapheme in the line containing `pos' */ size_t text_line_char_set(Text*, size_t pos, int count); +/* get display width of line upto `pos' */ +int text_line_width_get(Text*, size_t pos); +/* get position of character being displayed at `width' in line containing `pos' */ +size_t text_line_width_set(Text*, size_t pos, int width); /* move to the next/previous grapheme on the same line */ size_t text_line_char_next(Text*, size_t pos); size_t text_line_char_prev(Text*, size_t pos); -- cgit v1.2.3