Fixed the easy search bugs
This commit is contained in:
parent
08b6fd09f9
commit
ec8876bb40
2 changed files with 37 additions and 16 deletions
|
@ -149,6 +149,13 @@ impl TerminalContainer {
|
||||||
associated_directory: None,
|
associated_directory: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn connected(&self) -> Option<ViewHandle<TerminalView>> {
|
||||||
|
match &self.content {
|
||||||
|
TerminalContainerContent::Connected(vh) => Some(vh.clone()),
|
||||||
|
TerminalContainerContent::Error(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View for TerminalContainer {
|
impl View for TerminalContainer {
|
||||||
|
@ -428,28 +435,42 @@ impl SearchableItem for TerminalContainer {
|
||||||
matches: Vec<Self::Match>,
|
matches: Vec<Self::Match>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<usize> {
|
) -> Option<usize> {
|
||||||
if let TerminalContainerContent::Connected(connected) = &self.content {
|
let connected = self.connected();
|
||||||
if let Some(selection_head) = connected.read(cx).terminal().read(cx).selection_head {
|
// Selection head might have a value if there's a selection that isn't
|
||||||
|
// associated with a match. Therefore, if there are no matches, we should
|
||||||
|
// report None, no matter the state of the terminal
|
||||||
|
let res = if matches.len() > 0 && connected.is_some() {
|
||||||
|
if let Some(selection_head) = connected
|
||||||
|
.unwrap()
|
||||||
|
.read(cx)
|
||||||
|
.terminal()
|
||||||
|
.read(cx)
|
||||||
|
.selection_head
|
||||||
|
{
|
||||||
// If selection head is contained in a match. Return that match
|
// If selection head is contained in a match. Return that match
|
||||||
for (ix, search_match) in matches.iter().enumerate() {
|
if let Some(ix) = matches
|
||||||
if search_match.contains(&selection_head) {
|
.iter()
|
||||||
return Some(ix);
|
.enumerate()
|
||||||
}
|
.find(|(_, search_match)| {
|
||||||
|
search_match.contains(&selection_head)
|
||||||
// If not contained, return the next match after the selection head
|
|| search_match.start() > &selection_head
|
||||||
if search_match.start() > &selection_head {
|
})
|
||||||
return Some(ix);
|
.map(|(ix, _)| ix)
|
||||||
}
|
{
|
||||||
|
Some(ix)
|
||||||
|
} else {
|
||||||
|
// If no selection after selection head, return the last match
|
||||||
|
Some(matches.len().saturating_sub(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no selection after selection head, return the last match
|
|
||||||
return Some(matches.len().saturating_sub(1));
|
|
||||||
} else {
|
} else {
|
||||||
|
// Matches found but no active selection, return the first one
|
||||||
Some(0)
|
Some(0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
};
|
||||||
|
|
||||||
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,8 +91,8 @@ impl TerminalView {
|
||||||
if !cx.is_self_focused() {
|
if !cx.is_self_focused() {
|
||||||
this.has_new_content = true;
|
this.has_new_content = true;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
cx.emit(Event::Wakeup);
|
|
||||||
}
|
}
|
||||||
|
cx.emit(Event::Wakeup);
|
||||||
}
|
}
|
||||||
Event::Bell => {
|
Event::Bell => {
|
||||||
this.has_bell = true;
|
this.has_bell = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue