Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier way to implement mouse action #5274

Closed

Conversation

hunterliao29
Copy link
Contributor

@hunterliao29 hunterliao29 commented Dec 24, 2022

Developed an easier way to implement mouse action.

mouse_actions: HashMap<MouseEventKind, Vec<(Rect, MappableCommand)>>

pub fn add_mouse_action(
        &mut self,
        mouse_event: MouseEventKind,
        area: Rect,
        action: MappableCommand,
    ) {
        if self.mosue_enable {
            match self.mouse_actions.get_mut(&mouse_event) {
                Some(commands) => commands.push((area, action)),
                None => {
                    self.mouse_actions.insert(mouse_event, vec![(area, action)]);
                }
            }
        }
    }

let has_click_action = |kind, row, column| match self.mouse_actions.get(kind) {
    Some(commands) => commands.iter().rev().find(|(area, _)| {
        if area.x <= column
            && area.x + area.width > column
            && area.y <= row
            && area.y + area.height > row
        {
            return true;
        }
        false
    }),
    None => None,
};

if let Some((_, cmd)) = has_click_action(&kind, row, column) {
    cmd.execute(cxt);
    return EventResult::Consumed(None);
}

@archseer
Copy link
Member

Partial duplicate of #5041 but I need to review the implementation

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Dec 24, 2022
@hunterliao29 hunterliao29 marked this pull request as draft December 24, 2022 16:48
@hunterliao29 hunterliao29 marked this pull request as ready for review December 24, 2022 20:47
@hunterliao29 hunterliao29 force-pushed the bufferline_mouse branch 5 times, most recently from d608f08 to 54c2f84 Compare December 27, 2022 03:57
@hunterliao29 hunterliao29 marked this pull request as draft December 27, 2022 04:04
@hunterliao29 hunterliao29 changed the title bufferline mouse actions: switch and close Easier way to implement mouse action Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants