Skip to content

Commit

Permalink
Merge pull request #1 from INeddHelp/deepsource-autofix-1f9314a7
Browse files Browse the repository at this point in the history
reduce match statement into an if-let statement
  • Loading branch information
INeddHelp authored May 9, 2023
2 parents 5c70c41 + 4f5a2e6 commit 810f5e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
7 changes: 2 additions & 5 deletions src/gui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ impl Menu {

impl EventHandler for Menu {
fn handle_event(&mut self, event: &Event) {
match event {
Event::MouseClick(x, y) => {
// TODO: handle click event
}
_ => {}
if let Event::MouseClick(x, y) = event {
// TODO: handle click event
}
}
}
47 changes: 22 additions & 25 deletions src/gui/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,35 @@ impl Textbox {
}

pub fn handle_event(&mut self, event: &Event) {
match event {
Event::Key(key) => {
match key {
Key::Backspace => {
if self.cursor_pos > 0 {
self.text.remove(self.cursor_pos - 1);
self.cursor_pos -= 1;
}
if let Event::Key(key) = event {
match key {
Key::Backspace => {
if self.cursor_pos > 0 {
self.text.remove(self.cursor_pos - 1);
self.cursor_pos -= 1;
}
Key::Delete => {
if self.cursor_pos < self.text.len() {
self.text.remove(self.cursor_pos);
}
}
Key::Left => {
if self.cursor_pos > 0 {
self.cursor_pos -= 1;
}
}
Key::Delete => {
if self.cursor_pos < self.text.len() {
self.text.remove(self.cursor_pos);
}
Key::Right => {
if self.cursor_pos < self.text.len() {
self.cursor_pos += 1;
}
}
Key::Left => {
if self.cursor_pos > 0 {
self.cursor_pos -= 1;
}
Key::Char(c) => {
self.text.insert(self.cursor_pos, *c);
}
Key::Right => {
if self.cursor_pos < self.text.len() {
self.cursor_pos += 1;
}
_ => {}
}
Key::Char(c) => {
self.text.insert(self.cursor_pos, *c);
self.cursor_pos += 1;
}
_ => {}
}
_ => {}
}
}
}
Expand Down

0 comments on commit 810f5e0

Please sign in to comment.