mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
tagging: determine if the user is typing a @tag in the draft area
This commit is contained in:
parent
1ff2f1dad9
commit
77086f7005
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user