nevernest some note posting code

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-03-06 14:46:54 -08:00
parent 873b0e0dcc
commit 23285e7d76

View File

@@ -191,51 +191,63 @@ impl<'a> PostView<'a> {
cursor_index: usize, cursor_index: usize,
textedit_output: &TextEditOutput, textedit_output: &TextEditOutput,
) { ) {
let mut delete_mention = None; let mention = if let Some(mention) = self.draft.buffer.get_mention(cursor_index) {
if let Some(mention) = &self.draft.buffer.get_mention(cursor_index) { mention
if mention.info.mention_type == MentionType::Pending {
if ui.ctx().input(|r| r.key_pressed(egui::Key::Escape)) {
delete_mention = Some(mention.index);
} else { } else {
let mention_str = self.draft.buffer.get_mention_string(mention); return;
};
if mention.info.mention_type != MentionType::Pending {
return;
}
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 !mention_str.is_empty() {
if let Some(mention_hint) = &mut self.draft.cur_mention_hint { if let Some(mention_hint) = &mut self.draft.cur_mention_hint {
if mention_hint.index != mention.index { if mention_hint.index != mention.index {
mention_hint.index = mention.index; mention_hint.index = mention.index;
mention_hint.pos = calculate_mention_hints_pos( mention_hint.pos =
textedit_output, calculate_mention_hints_pos(textedit_output, mention.info.start_index);
mention.info.start_index,
);
} }
mention_hint.text = mention_str.to_owned(); mention_hint.text = mention_str.to_owned();
} else { } else {
self.draft.cur_mention_hint = Some(MentionHint { self.draft.cur_mention_hint = Some(MentionHint {
index: mention.index, index: mention.index,
text: mention_str.to_owned(), text: mention_str.to_owned(),
pos: calculate_mention_hints_pos( pos: calculate_mention_hints_pos(textedit_output, mention.info.start_index),
textedit_output,
mention.info.start_index,
),
}); });
} }
} }
if let Some(hint) = &self.draft.cur_mention_hint {
let hint_rect = { let hint_rect = {
let hint = if let Some(hint) = &self.draft.cur_mention_hint {
hint
} else {
return;
};
let mut hint_rect = self.inner_rect; let mut hint_rect = self.inner_rect;
hint_rect.set_top(hint.pos.y); hint_rect.set_top(hint.pos.y);
hint_rect hint_rect
}; };
if let Ok(res) = self.ndb.search_profile(txn, mention_str, 10) { let res = if let Ok(res) = self.ndb.search_profile(txn, mention_str, 10) {
let resp = SearchResultsView::new(self.img_cache, self.ndb, txn, &res) res
.show_in_rect(hint_rect, ui); } else {
return;
};
let resp =
SearchResultsView::new(self.img_cache, self.ndb, txn, &res).show_in_rect(hint_rect, ui);
match resp { match resp {
ui::search_results::SearchResultsResponse::SelectResult( ui::search_results::SearchResultsResponse::SelectResult(selection) => {
selection,
) => {
if let Some(hint_index) = selection { if let Some(hint_index) = selection {
if let Some(pk) = res.get(hint_index) { if let Some(pk) = res.get(hint_index) {
let record = self.ndb.get_profile_by_pubkey(txn, pk); let record = self.ndb.get_profile_by_pubkey(txn, pk);
@@ -249,20 +261,12 @@ impl<'a> PostView<'a> {
} }
} }
} }
ui::search_results::SearchResultsResponse::DeleteMention => { ui::search_results::SearchResultsResponse::DeleteMention => {
self.draft.buffer.delete_mention(mention.index) self.draft.buffer.delete_mention(mention.index)
} }
} }
} }
}
}
}
}
if let Some(mention_to_delete) = delete_mention {
self.draft.buffer.delete_mention(mention_to_delete);
}
}
fn focused(&self, ui: &egui::Ui) -> bool { fn focused(&self, ui: &egui::Ui) -> bool {
ui.ctx() ui.ctx()