acp: Remove invalid creases on edit (#36708)
Release Notes: - N/A Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
This commit is contained in:
parent
210727412c
commit
48f51c0c60
1 changed files with 30 additions and 24 deletions
|
@ -11,7 +11,7 @@ use assistant_slash_commands::codeblock_fence_for_path;
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
use editor::{
|
use editor::{
|
||||||
Addon, Anchor, AnchorRangeExt, ContextMenuOptions, ContextMenuPlacement, Editor, EditorElement,
|
Addon, Anchor, AnchorRangeExt, ContextMenuOptions, ContextMenuPlacement, Editor, EditorElement,
|
||||||
EditorEvent, EditorMode, EditorStyle, ExcerptId, FoldPlaceholder, MultiBuffer,
|
EditorEvent, EditorMode, EditorSnapshot, EditorStyle, ExcerptId, FoldPlaceholder, MultiBuffer,
|
||||||
SemanticsProvider, ToOffset,
|
SemanticsProvider, ToOffset,
|
||||||
actions::Paste,
|
actions::Paste,
|
||||||
display_map::{Crease, CreaseId, FoldId},
|
display_map::{Crease, CreaseId, FoldId},
|
||||||
|
@ -140,11 +140,11 @@ impl MessageEditor {
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
let mut subscriptions = Vec::new();
|
let mut subscriptions = Vec::new();
|
||||||
if prevent_slash_commands {
|
subscriptions.push(cx.subscribe_in(&editor, window, {
|
||||||
subscriptions.push(cx.subscribe_in(&editor, window, {
|
let semantics_provider = semantics_provider.clone();
|
||||||
let semantics_provider = semantics_provider.clone();
|
move |this, editor, event, window, cx| {
|
||||||
move |this, editor, event, window, cx| {
|
if let EditorEvent::Edited { .. } = event {
|
||||||
if let EditorEvent::Edited { .. } = event {
|
if prevent_slash_commands {
|
||||||
this.highlight_slash_command(
|
this.highlight_slash_command(
|
||||||
semantics_provider.clone(),
|
semantics_provider.clone(),
|
||||||
editor.clone(),
|
editor.clone(),
|
||||||
|
@ -152,9 +152,12 @@ impl MessageEditor {
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let snapshot = editor.update(cx, |editor, cx| editor.snapshot(window, cx));
|
||||||
|
this.mention_set.remove_invalid(snapshot);
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
}
|
}));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
editor,
|
editor,
|
||||||
|
@ -730,11 +733,6 @@ impl MessageEditor {
|
||||||
editor.display_map.update(cx, |map, cx| {
|
editor.display_map.update(cx, |map, cx| {
|
||||||
let snapshot = map.snapshot(cx);
|
let snapshot = map.snapshot(cx);
|
||||||
for (crease_id, crease) in snapshot.crease_snapshot.creases() {
|
for (crease_id, crease) in snapshot.crease_snapshot.creases() {
|
||||||
// Skip creases that have been edited out of the message buffer.
|
|
||||||
if !crease.range().start.is_valid(&snapshot.buffer_snapshot) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(mention) = contents.get(&crease_id) else {
|
let Some(mention) = contents.get(&crease_id) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
@ -1482,17 +1480,6 @@ impl MentionSet {
|
||||||
self.text_thread_summaries.insert(path, task);
|
self.text_thread_summaries.insert(path, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drain(&mut self) -> impl Iterator<Item = CreaseId> {
|
|
||||||
self.fetch_results.clear();
|
|
||||||
self.thread_summaries.clear();
|
|
||||||
self.text_thread_summaries.clear();
|
|
||||||
self.directories.clear();
|
|
||||||
self.uri_by_crease_id
|
|
||||||
.drain()
|
|
||||||
.map(|(id, _)| id)
|
|
||||||
.chain(self.images.drain().map(|(id, _)| id))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn contents(
|
pub fn contents(
|
||||||
&self,
|
&self,
|
||||||
project: &Entity<Project>,
|
project: &Entity<Project>,
|
||||||
|
@ -1703,6 +1690,25 @@ impl MentionSet {
|
||||||
anyhow::Ok(contents)
|
anyhow::Ok(contents)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn drain(&mut self) -> impl Iterator<Item = CreaseId> {
|
||||||
|
self.fetch_results.clear();
|
||||||
|
self.thread_summaries.clear();
|
||||||
|
self.text_thread_summaries.clear();
|
||||||
|
self.directories.clear();
|
||||||
|
self.uri_by_crease_id
|
||||||
|
.drain()
|
||||||
|
.map(|(id, _)| id)
|
||||||
|
.chain(self.images.drain().map(|(id, _)| id))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_invalid(&mut self, snapshot: EditorSnapshot) {
|
||||||
|
for (crease_id, crease) in snapshot.crease_snapshot.creases() {
|
||||||
|
if !crease.range().start.is_valid(&snapshot.buffer_snapshot) {
|
||||||
|
self.uri_by_crease_id.remove(&crease_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SlashCommandSemanticsProvider {
|
struct SlashCommandSemanticsProvider {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue