Show correct number of characters selected (#16420)
This commit is contained in:
parent
8841d6faad
commit
5e6e465294
2 changed files with 93 additions and 6 deletions
|
@ -12,11 +12,11 @@ use ui::{
|
|||
use util::paths::FILE_ROW_COLUMN_DELIMITER;
|
||||
use workspace::{item::ItemHandle, StatusItemView, Workspace};
|
||||
|
||||
#[derive(Copy, Clone, Default, PartialOrd, PartialEq)]
|
||||
struct SelectionStats {
|
||||
lines: usize,
|
||||
characters: usize,
|
||||
selections: usize,
|
||||
#[derive(Copy, Clone, Debug, Default, PartialOrd, PartialEq)]
|
||||
pub(crate) struct SelectionStats {
|
||||
pub lines: usize,
|
||||
pub characters: usize,
|
||||
pub selections: usize,
|
||||
}
|
||||
|
||||
pub struct CursorPosition {
|
||||
|
@ -44,7 +44,10 @@ impl CursorPosition {
|
|||
self.selected_count.selections = editor.selections.count();
|
||||
let mut last_selection: Option<Selection<usize>> = None;
|
||||
for selection in editor.selections.all::<usize>(cx) {
|
||||
self.selected_count.characters += selection.end - selection.start;
|
||||
self.selected_count.characters += buffer
|
||||
.text_for_range(selection.start..selection.end)
|
||||
.map(|t| t.chars().count())
|
||||
.sum::<usize>();
|
||||
if last_selection
|
||||
.as_ref()
|
||||
.map_or(true, |last_selection| selection.id > last_selection.id)
|
||||
|
@ -106,6 +109,11 @@ impl CursorPosition {
|
|||
}
|
||||
text.push(')');
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn selection_stats(&self) -> &SelectionStats {
|
||||
&self.selected_count
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for CursorPosition {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue