Lv_textarea_text_is_selected returning incorrect value

if I ask the question lv_textarea_text_is_selected, I’d expect true to be returned if there was a selection on the text area, but the return values are opposite of what I’d expect. From lv_textarea.c:

bool lv_textarea_text_is_selected(const lv_obj_t * obj)
{
    LV_ASSERT_OBJ(obj, MY_CLASS);
#if LV_LABEL_TEXT_SELECTION
     lv_textarea_t * ta = (lv_textarea_t *)obj;
    if((lv_label_get_text_selection_start(ta->label) == LV_DRAW_LABEL_NO_TXT_SEL ||
        lv_label_get_text_selection_end(ta->label) == LV_DRAW_LABEL_NO_TXT_SEL)) {
        return true;
    }
    else {
        return false;
    }
#else
    (void)obj; /*Unused*/
    return false;
#endif
}

LV_DRAW_LABEL_NO_TXT_SEL is the value set when you call lv_textarea_clear_selection, so if either start or end are set to this, there is no selection, so shouldn’t “text_is_selected” return false, not true?

P.S. In the v8.0.0. documentation for Keyboard, the example “Keyboard with text area” has a broken link for the code. I’m having general issues trying to highlight text in a text area associated with a keyboard and delete /replace when a key is pressed, so I want to start with “clean” code from an example in the simulator to see what’s up.

You are right! They should be != LV_DRAW_LABEL_NO_TXT_SEL.

Which link? They seem working to me.

I tried the link again some time after posting, and it was working - assumed you had fixed it :slight_smile:

One of the issues I was trying to narrow down was highlighting of selected text in a textarea in v8.0.1. I wasn’t seeing the highlighting style applied on highlighted text in a textarea. It didn’t work when I applied the style to the textarea:

lv_obj_add_style(entryTextarea, &style_selected, LV_PART_SELECTED);

But it worked when I applied it to the textareas label:

lv_obj_add_style(lv_textarea_get_label(entryTextarea), &style_selected, LV_PART_SELECTED);

The v8 textarea documentation says the textarea has a part LV_PART_SELECTED for the style of the highlighted text, so its either a) a code bug, b) a documention bug, or c) I’m doing something wrong :slight_smile:

One other thing related to the keyboard - I saw a post about repeated characters from a keyboard appearing in the associated text area in v8, and an offered solution was debouncing the keyboard. However, I had the same issue in v8, in code that worked in v7. I believe it is to do with the default keyboard event handler in conjunction with allowing multiple event handlers in v8. In v7, if you added your own custom event handler, I think that automatically deleted the default event, which you could then later call from the custom event. In v8, the same code I believe will add your custom event handler in conjunction with the default event handler, rather than deleting it as it did in v7, causing this behavior. I’d suggest updating the v8 documentation to be a little more specific on this.

Correct.

Also correct. It can be removed using lv_obj_remove_event_cb(kb, lv_keyboard_def_event_cb).

Currently, there is a small paragraph under the events section of the keyboard page:

The keyboard has a default event handler . . . You can remove it and replace it with a custom event handler if you wish.

I’ve added a more obvious warning that this behavior is different from v7, since a lot of users will be upgrading.

Thanks. That one took me a while, as it wasn’t a ‘breaking’ change and although the documentation did say “remove” it looked very similar to the v7 documentation and didn’t register until later. Your note in the docs should do the trick!

It was between a) and b). LVGL can’t see the bg_color of the selected text if it’s set on the text area. I’ve updated the docs to make it clear that bg_color should be set on the label.