1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

Merge pull request #1259 from joltwallet/fix/txt_cursor_wrap

Fix cursor wrapping described in https://github.com/littlevgl/lvgl/is…
This commit is contained in:
Gabor Kiss-Vamosi 2019-11-11 12:28:50 +01:00 committed by GitHub
commit 8cf7824f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 33 deletions

View File

@ -266,6 +266,9 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
/**
* Get the next line of text. Check line length and break chars too.
*
* A line of txt includes the \n character.
*
* @param txt a '\0' terminated string
* @param font pointer to a font
* @param letter_space letter space
@ -295,18 +298,13 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
i += advance;
if(txt[i] == '\n') break;
if(txt[0] == '\n') break;
if(txt[i] == '\n'){
i++; /* Include the following newline in the current line */
break;
}
/* If this is the last of the string, make sure pointer is at NULL-terminator.
* This catches the case, for example of a string ending in "\n" */
if(txt[i] != '\0'){
uint32_t i_next = i;
int tmp;
uint32_t letter_next = lv_txt_encoded_next(txt, &i_next); /*Gets current character*/
tmp = i_next;
letter_next = lv_txt_encoded_next(txt, &i_next); /*Gets subsequent character*/
if(letter_next == '\0') i = tmp;
}
/*Always step at least one to avoid infinite loops*/

View File

@ -661,7 +661,15 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
while(txt[line_start] != '\0') {
new_line_start += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, max_w, flag);
if(pos->y <= y + letter_height) break; /*The line is found (stored in 'line_start')*/
if(pos->y <= y + letter_height) {
/*The line is found (stored in 'line_start')*/
/* Include the NULL terminator in the last line */
uint32_t tmp = new_line_start;
uint32_t letter;
letter = lv_txt_encoded_prev(txt, &tmp);
if(letter != '\n' && txt[new_line_start] == '\0' ) new_line_start++;
break;
}
y += letter_height + style->text.line_space;
line_start = new_line_start;
@ -682,7 +690,6 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
uint32_t letter;
uint32_t letter_next;
if(new_line_start > 0) {
while(i < new_line_start) {
/* Get the current letter.*/
letter = lv_txt_encoded_next(txt, &i);
@ -707,7 +714,6 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
x += style->text.letter_space;
i_act = i;
}
}
return lv_encoded_get_char_id(txt, i);
}