commit 83caa9f8143f1611c7ce86d32b473bdf19efd97f
parent ea4217d4c808917a93a86a822a6ed93122a3871c
Author: kernelkind <kernelkind@gmail.com>
Date: Sat, 1 Mar 2025 15:20:23 -0500
exit mention on double space
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/crates/notedeck_columns/src/post.rs b/crates/notedeck_columns/src/post.rs
@@ -330,6 +330,14 @@ impl PostBuffer {
}
}
+ pub fn delete_mention(&mut self, mention_key: usize) {
+ if let Some(mention_info) = self.mentions.get(&mention_key) {
+ self.mention_starts.remove(&mention_info.start_index);
+ self.mention_ends.remove(&mention_info.end_index);
+ self.mentions.remove(&mention_key);
+ }
+ }
+
pub fn is_empty(&self) -> bool {
self.text_buffer.is_empty()
}
@@ -510,6 +518,7 @@ impl TextBuffer for PostBuffer {
.map(|(&k, _)| k)
.collect();
+ let mut break_mentions = Vec::new();
for cur_end in pending_ends_to_update {
let mention_key = if let Some(mention_key) = self.mention_ends.get(&cur_end) {
*mention_key
@@ -531,6 +540,13 @@ impl TextBuffer for PostBuffer {
self.mention_starts.insert(new_start, mention_key);
mention_info.start_index = new_start;
} else {
+ if char_index == mention_info.end_index
+ && first_is_desired_char(&self.text_buffer, text, char_index, ' ')
+ {
+ // if the user wrote a double space at the end of the mention, break it
+ break_mentions.push(mention_key);
+ }
+
// text is being inserted inside this mention. Make sure it is in the pending state
mention_info.mention_type = MentionType::Pending;
}
@@ -541,6 +557,10 @@ impl TextBuffer for PostBuffer {
}
}
+ for mention_key in break_mentions {
+ self.delete_mention(mention_key);
+ }
+
if first_is_desired_char(&self.text_buffer, text, char_index, self.mention_indicator) {
// if a mention already exists where we're inserting the delim, remove it
let to_remove = self.get_mention(char_index).map(|old_mention| {