From 2af4b5be014194a656eeaff4fcc7bb844d287947 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 13 Mar 2013 11:23:07 +0000 Subject: Make textarea_get_caret private. --- desktop/textarea.c | 55 +++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'desktop/textarea.c') diff --git a/desktop/textarea.c b/desktop/textarea.c index b73ebbfc1..b16d78381 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -168,6 +168,36 @@ static void textarea_normalise_text(struct textarea *ta, } +/** + * Get the caret's position + * + * \param ta Text area + * \return 0-based character index of caret location, or -1 on error + */ +static int textarea_get_caret(struct textarea *ta) +{ + unsigned int c_off = 0, b_off; + + /* Ensure caret isn't hidden */ + if (ta->caret_pos.char_off < 0) + textarea_set_caret(ta, 0); + + /* if the text is a trailing NUL only */ + if (ta->text.utf8_len == 0) + return 0; + + if (ta->caret_pos.line >= ta->line_count) + return ta->text.utf8_len; + + /* Calculate character offset of this line's start */ + for (b_off = 0; b_off < ta->lines[ta->caret_pos.line].b_start; + b_off = utf8_next(ta->text.data, ta->text.len, b_off)) + c_off++; + + return c_off + ta->caret_pos.char_off; +} + + /** * Selects a character range in the textarea and redraws it * @@ -1500,31 +1530,6 @@ bool textarea_set_caret(struct textarea *ta, int caret) } -/* exported interface, documented in textarea.h */ -int textarea_get_caret(struct textarea *ta) -{ - unsigned int c_off = 0, b_off; - - /* Ensure caret isn't hidden */ - if (ta->caret_pos.char_off < 0) - textarea_set_caret(ta, 0); - - /* if the text is a trailing NUL only */ - if (ta->text.utf8_len == 0) - return 0; - - if (ta->caret_pos.line >= ta->line_count) - return ta->text.utf8_len; - - /* Calculate character offset of this line's start */ - for (b_off = 0; b_off < ta->lines[ta->caret_pos.line].b_start; - b_off = utf8_next(ta->text.data, ta->text.len, b_off)) - c_off++; - - return c_off + ta->caret_pos.char_off; -} - - /* exported interface, documented in textarea.h */ void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale, const struct rect *clip, const struct redraw_context *ctx) -- cgit v1.2.3