editor: Fix highlight selection panic (#25141)
Use the latest selection state for highlighting instead of the state before debounce. Release Notes: - N/A
This commit is contained in:
parent
e57b9e5f83
commit
043c4ed296
1 changed files with 13 additions and 13 deletions
|
@ -4782,24 +4782,24 @@ impl Editor {
|
||||||
self.clear_background_highlights::<SelectedTextHighlight>(cx);
|
self.clear_background_highlights::<SelectedTextHighlight>(cx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if self.selections.count() != 1 || self.selections.line_mode {
|
|
||||||
self.clear_background_highlights::<SelectedTextHighlight>(cx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let selection = self.selections.newest::<Point>(cx);
|
|
||||||
if selection.is_empty() || selection.start.row != selection.end.row {
|
|
||||||
self.clear_background_highlights::<SelectedTextHighlight>(cx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let debounce = EditorSettings::get_global(cx).selection_highlight_debounce;
|
let debounce = EditorSettings::get_global(cx).selection_highlight_debounce;
|
||||||
self.selection_highlight_task = Some(cx.spawn_in(window, |editor, mut cx| async move {
|
self.selection_highlight_task = Some(cx.spawn_in(window, |editor, mut cx| async move {
|
||||||
cx.background_executor()
|
cx.background_executor()
|
||||||
.timer(Duration::from_millis(debounce))
|
.timer(Duration::from_millis(debounce))
|
||||||
.await;
|
.await;
|
||||||
let Some(matches_task) = editor
|
let Some(Some(matches_task)) = editor
|
||||||
.read_with(&mut cx, |editor, cx| {
|
.update_in(&mut cx, |editor, _, cx| {
|
||||||
|
if editor.selections.count() != 1 || editor.selections.line_mode {
|
||||||
|
editor.clear_background_highlights::<SelectedTextHighlight>(cx);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let selection = editor.selections.newest::<Point>(cx);
|
||||||
|
if selection.is_empty() || selection.start.row != selection.end.row {
|
||||||
|
editor.clear_background_highlights::<SelectedTextHighlight>(cx);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||||
cx.background_spawn(async move {
|
Some(cx.background_spawn(async move {
|
||||||
let mut ranges = Vec::new();
|
let mut ranges = Vec::new();
|
||||||
let buffer_ranges =
|
let buffer_ranges =
|
||||||
vec![buffer.anchor_before(0)..buffer.anchor_after(buffer.len())];
|
vec![buffer.anchor_before(0)..buffer.anchor_after(buffer.len())];
|
||||||
|
@ -4837,7 +4837,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ranges
|
ranges
|
||||||
})
|
}))
|
||||||
})
|
})
|
||||||
.log_err()
|
.log_err()
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue