mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 17:14:21 +01:00
nevernest some note posting code
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -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);
|
||||
let mention = if let Some(mention) = self.draft.buffer.get_mention(cursor_index) {
|
||||
mention
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
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 mention.info.mention_type != MentionType::Pending {
|
||||
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 ui.ctx().input(|r| r.key_pressed(egui::Key::Escape)) {
|
||||
self.draft.buffer.delete_mention(mention.index);
|
||||
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);
|
||||
let mention_str = self.draft.buffer.get_mention_string(&mention);
|
||||
|
||||
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 !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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user