tagging: determine if the user is typing a @tag in the draft area

This commit is contained in:
Mike Dilger 2023-10-24 09:44:59 +13:00
parent 1ff2f1dad9
commit 77086f7005
3 changed files with 47 additions and 10 deletions

View File

@ -342,15 +342,42 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
});
}
let draft_response = ui.add(
text_edit_multiline!(app, app.draft_data.draft)
.id_source("compose_area")
.hint_text("Type your message here")
.desired_width(f32::INFINITY)
.lock_focus(true)
.interactive(app.draft_data.repost.is_none())
.layouter(&mut layouter),
);
let text_edit_area_id = egui::Id::new("compose_area");
// Determine if we are in tagging mode
{
app.draft_data.tagging_search_substring = None;
let text_edit_state =
egui::TextEdit::load_state(ctx, text_edit_area_id).unwrap_or_default();
let ccursor_range = text_edit_state.ccursor_range().unwrap_or_default();
// debugging:
// ui.label(format!("{}-{}", ccursor_range.primary.index,
// ccursor_range.secondary.index));
if ccursor_range.primary.index <= app.draft_data.draft.len() {
let precursor = &app.draft_data.draft[0..ccursor_range.primary.index];
if let Some(captures) = GLOBALS.tagging_regex.captures(precursor) {
if let Some(first_capture) = captures.get(1) {
app.draft_data.tagging_search_substring =
Some(first_capture.as_str().to_owned());
}
}
}
};
// Temporary for debugging:
if let Some(tagging) = &app.draft_data.tagging_search_substring {
ui.label(format!("TAGGING SEARCH SUBSTRING = {}", tagging));
}
let text_edit_area = text_edit_multiline!(app, app.draft_data.draft)
.id(text_edit_area_id)
.hint_text("Type your message here")
.desired_width(f32::INFINITY)
.lock_focus(true)
.interactive(app.draft_data.repost.is_none())
.layouter(&mut layouter);
let draft_response = ui.add(text_edit_area);
if app.draft_needs_focus {
draft_response.request_focus();
app.draft_needs_focus = false;

View File

@ -282,6 +282,9 @@ pub struct DraftData {
pub repost: Option<Id>,
pub replying_to: Option<Id>,
pub tag_someone: String,
// If the user is typing a @tag, this is what they typed
pub tagging_search_substring: Option<String>,
}
impl Default for DraftData {
@ -295,8 +298,10 @@ impl Default for DraftData {
// The following are ignored for DMs
repost: None,
tag_someone: "".to_owned(),
replying_to: None,
tag_someone: "".to_owned(),
tagging_search_substring: None,
}
}
}
@ -311,6 +316,7 @@ impl DraftData {
self.repost = None;
self.replying_to = None;
self.tag_someone = "".to_owned();
self.tagging_search_substring = None;
}
}

View File

@ -114,6 +114,9 @@ pub struct Globals {
/// Hashtag regex
pub hashtag_regex: Regex,
/// Tagging regex
pub tagging_regex: Regex,
/// LMDB storage
pub storage: Storage,
@ -173,6 +176,7 @@ lazy_static! {
ui_invalidate_all: AtomicBool::new(false),
current_zap: PRwLock::new(ZapState::None),
hashtag_regex: Regex::new(r"(?:^|\W)(#[\w\p{Extended_Pictographic}]+)(?:$|\W)").unwrap(),
tagging_regex: Regex::new(r"(?:^|\s+)@(\S+)$").unwrap(),
storage,
events_processed: AtomicU32::new(0),
filter_engine,