commit 23285e7d7675b3e55b8cc0e547854202e77f96da
parent 873b0e0dcc0168a75d871e23b5138b357f6e235d
Author: William Casarin <jb55@jb55.com>
Date: Thu, 6 Mar 2025 14:46:54 -0800
nevernest some note posting code
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 68 insertions(+), 64 deletions(-)
diff --git a/crates/notedeck_columns/src/ui/note/post.rs b/crates/notedeck_columns/src/ui/note/post.rs
@@ -191,76 +191,80 @@ impl<'a> PostView<'a> {
cursor_index: usize,
textedit_output: &TextEditOutput,
) {
- let mut delete_mention = None;
- if let Some(mention) = &self.draft.buffer.get_mention(cursor_index) {
- if mention.info.mention_type == MentionType::Pending {
- if ui.ctx().input(|r| r.key_pressed(egui::Key::Escape)) {
- delete_mention = Some(mention.index);
- } else {
- let mention_str = self.draft.buffer.get_mention_string(mention);
-
- if !mention_str.is_empty() {
- if let Some(mention_hint) = &mut self.draft.cur_mention_hint {
- if mention_hint.index != mention.index {
- mention_hint.index = mention.index;
- mention_hint.pos = calculate_mention_hints_pos(
- textedit_output,
- mention.info.start_index,
- );
- }
- mention_hint.text = mention_str.to_owned();
- } else {
- self.draft.cur_mention_hint = Some(MentionHint {
- index: mention.index,
- text: mention_str.to_owned(),
- pos: calculate_mention_hints_pos(
- textedit_output,
- mention.info.start_index,
- ),
- });
- }
- }
+ let mention = if let Some(mention) = self.draft.buffer.get_mention(cursor_index) {
+ mention
+ } else {
+ return;
+ };
- if let Some(hint) = &self.draft.cur_mention_hint {
- let hint_rect = {
- let mut hint_rect = self.inner_rect;
- hint_rect.set_top(hint.pos.y);
- hint_rect
- };
+ if mention.info.mention_type != MentionType::Pending {
+ return;
+ }
- if let Ok(res) = self.ndb.search_profile(txn, mention_str, 10) {
- let resp = SearchResultsView::new(self.img_cache, self.ndb, txn, &res)
- .show_in_rect(hint_rect, ui);
-
- match resp {
- ui::search_results::SearchResultsResponse::SelectResult(
- selection,
- ) => {
- if let Some(hint_index) = selection {
- if let Some(pk) = res.get(hint_index) {
- let record = self.ndb.get_profile_by_pubkey(txn, pk);
-
- self.draft.buffer.select_mention_and_replace_name(
- mention.index,
- get_display_name(record.ok().as_ref()).name(),
- Pubkey::new(**pk),
- );
- self.draft.cur_mention_hint = None;
- }
- }
- }
- ui::search_results::SearchResultsResponse::DeleteMention => {
- self.draft.buffer.delete_mention(mention.index)
- }
- }
- }
- }
+ if ui.ctx().input(|r| r.key_pressed(egui::Key::Escape)) {
+ self.draft.buffer.delete_mention(mention.index);
+ return;
+ }
+
+ let mention_str = self.draft.buffer.get_mention_string(&mention);
+
+ if !mention_str.is_empty() {
+ if let Some(mention_hint) = &mut self.draft.cur_mention_hint {
+ if mention_hint.index != mention.index {
+ mention_hint.index = mention.index;
+ mention_hint.pos =
+ calculate_mention_hints_pos(textedit_output, mention.info.start_index);
}
+ mention_hint.text = mention_str.to_owned();
+ } else {
+ self.draft.cur_mention_hint = Some(MentionHint {
+ index: mention.index,
+ text: mention_str.to_owned(),
+ pos: calculate_mention_hints_pos(textedit_output, mention.info.start_index),
+ });
}
}
- if let Some(mention_to_delete) = delete_mention {
- self.draft.buffer.delete_mention(mention_to_delete);
+ let hint_rect = {
+ let hint = if let Some(hint) = &self.draft.cur_mention_hint {
+ hint
+ } else {
+ return;
+ };
+
+ let mut hint_rect = self.inner_rect;
+ hint_rect.set_top(hint.pos.y);
+ hint_rect
+ };
+
+ let res = if let Ok(res) = self.ndb.search_profile(txn, mention_str, 10) {
+ res
+ } else {
+ return;
+ };
+
+ let resp =
+ SearchResultsView::new(self.img_cache, self.ndb, txn, &res).show_in_rect(hint_rect, ui);
+
+ match resp {
+ ui::search_results::SearchResultsResponse::SelectResult(selection) => {
+ if let Some(hint_index) = selection {
+ if let Some(pk) = res.get(hint_index) {
+ let record = self.ndb.get_profile_by_pubkey(txn, pk);
+
+ self.draft.buffer.select_mention_and_replace_name(
+ mention.index,
+ get_display_name(record.ok().as_ref()).name(),
+ Pubkey::new(**pk),
+ );
+ self.draft.cur_mention_hint = None;
+ }
+ }
+ }
+
+ ui::search_results::SearchResultsResponse::DeleteMention => {
+ self.draft.buffer.delete_mention(mention.index)
+ }
}
}