mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 05:28:35 +00:00
Fix problematic TextCallbackData::selection implementation
This commit is contained in:
parent
fef6509a6e
commit
592af95697
@ -1051,7 +1051,20 @@ impl TextCallbackData {
|
||||
/// This Range is given in `usize` so that it might be used in indexing
|
||||
/// operations more easily. To quickly grab the selected text, use [selected](Self::selected).
|
||||
pub fn selection(&self) -> Range<usize> {
|
||||
unsafe { (*(self.0)).SelectionStart as usize..(*(self.0)).SelectionEnd as usize }
|
||||
let (start, end) = unsafe {
|
||||
(
|
||||
(*(self.0)).SelectionStart as usize,
|
||||
(*(self.0)).SelectionEnd as usize,
|
||||
)
|
||||
};
|
||||
// Avoid returning a range with start > end, which would be problematic. For example, it
|
||||
// would cause panics when used to index the string buffer and would also cause Self::has_selection
|
||||
// to return a false negative.
|
||||
if start < end {
|
||||
start..end
|
||||
} else {
|
||||
end..start
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the selected text directly. Note that if no text is selected,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user