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,
|
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 {
|
} else {
|
||||||
if ui.ctx().input(|r| r.key_pressed(egui::Key::Escape)) {
|
return;
|
||||||
delete_mention = Some(mention.index);
|
};
|
||||||
} else {
|
|
||||||
let mention_str = self.draft.buffer.get_mention_string(mention);
|
|
||||||
|
|
||||||
if !mention_str.is_empty() {
|
if mention.info.mention_type != MentionType::Pending {
|
||||||
if let Some(mention_hint) = &mut self.draft.cur_mention_hint {
|
return;
|
||||||
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(hint) = &self.draft.cur_mention_hint {
|
if ui.ctx().input(|r| r.key_pressed(egui::Key::Escape)) {
|
||||||
let hint_rect = {
|
self.draft.buffer.delete_mention(mention.index);
|
||||||
let mut hint_rect = self.inner_rect;
|
return;
|
||||||
hint_rect.set_top(hint.pos.y);
|
}
|
||||||
hint_rect
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(res) = self.ndb.search_profile(txn, mention_str, 10) {
|
let mention_str = self.draft.buffer.get_mention_string(&mention);
|
||||||
let resp = SearchResultsView::new(self.img_cache, self.ndb, txn, &res)
|
|
||||||
.show_in_rect(hint_rect, ui);
|
|
||||||
|
|
||||||
match resp {
|
if !mention_str.is_empty() {
|
||||||
ui::search_results::SearchResultsResponse::SelectResult(
|
if let Some(mention_hint) = &mut self.draft.cur_mention_hint {
|
||||||
selection,
|
if mention_hint.index != mention.index {
|
||||||
) => {
|
mention_hint.index = mention.index;
|
||||||
if let Some(hint_index) = selection {
|
mention_hint.pos =
|
||||||
if let Some(pk) = res.get(hint_index) {
|
calculate_mention_hints_pos(textedit_output, mention.info.start_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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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 {
|
let hint_rect = {
|
||||||
self.draft.buffer.delete_mention(mention_to_delete);
|
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