Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

wcassels
Copy link
Contributor

Currently, when working with callbacks on an InputText, it's possible for TextCallbackData::selection() to return a range with start > end, eg. when selecting text by dragging from right to left. One resulting problem is that when you do this, TextCallbackData::has_selection() will return false, because the implementation is simply

pub fn has_selection(&self) -> bool {
    !self.selection().is_empty()
}

with stdlib's implementation of Range::is_empty() being

pub fn is_empty(&self) -> bool {
    !(self.start < self.end)
}

A bigger problem is that calling TextCallbackData::selected() with the selection in this state will cause a guaranteed panic, because the selection range is used to index the input buffer.

This MR provides one possible solution by ensuring the Range returned by TextCallbackData::selection() always satisfies start <= end.

@sanbox-irl
Copy link
Member

Nice catch! Thank ya for the work

@sanbox-irl sanbox-irl merged commit 592af95 into imgui-rs:main Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants