(
key: usize,
shift_key: bool,
control_key: bool,
alt_key: bool,
meta_key: bool,
)
| 627 | } |
| 628 | |
| 629 | fn key_press_to_command_and_param( |
| 630 | key: usize, |
| 631 | shift_key: bool, |
| 632 | control_key: bool, |
| 633 | alt_key: bool, |
| 634 | meta_key: bool, |
| 635 | ) -> Result<(NavigationCommand, NavigationParam)> { |
| 636 | // key press mapping should probably be stored externally (registry) with an app that allows changes |
| 637 | // for now, we build in the defaults |
| 638 | |
| 639 | // this is a hack to map alt+ctl+arrow to ctl+arrow to change table mappings (github.com/NSoiffer/MathCAT/issues/105) |
| 640 | // if this change sticks, choose_command() needs to be changed and this hack should go away |
| 641 | let mut alt_key = alt_key; |
| 642 | if alt_key && control_key && [VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN].contains(&key) { |
| 643 | alt_key = false; |
| 644 | } |
| 645 | if alt_key || meta_key { |
| 646 | bail!("Invalid argument to key_press_to_command_and_param"); |
| 647 | } |
| 648 | |
| 649 | let command; |
| 650 | let param; |
| 651 | match key { |
| 652 | VK_LEFT => { |
| 653 | command = choose_command(shift_key, control_key, NavigationCommand::Move, NavigationCommand::Read, NavigationCommand::Move, NavigationCommand::Describe); |
| 654 | param = choose_param( shift_key, control_key, NavigationParam::Previous, NavigationParam::Previous, NavigationParam::CellPrevious, NavigationParam::Previous); |
| 655 | }, |
| 656 | VK_RIGHT => { |
| 657 | command = choose_command(shift_key, control_key, NavigationCommand::Move, NavigationCommand::Read, NavigationCommand::Move, NavigationCommand::Describe); |
| 658 | param = choose_param( shift_key, control_key, NavigationParam::Next, NavigationParam::Next, NavigationParam::CellNext, NavigationParam::Next); |
| 659 | }, |
| 660 | VK_UP => { |
| 661 | command = choose_command(shift_key, control_key, NavigationCommand::Zoom, NavigationCommand::ChangeNavMode, NavigationCommand::Move, NavigationCommand::Zoom); |
| 662 | param = choose_param( shift_key, control_key, NavigationParam::Previous, NavigationParam::Previous, NavigationParam::CellUp, NavigationParam::Start); |
| 663 | }, |
| 664 | VK_DOWN => { |
| 665 | command = choose_command(shift_key, control_key, NavigationCommand::Zoom, NavigationCommand::ChangeNavMode, NavigationCommand::Move, NavigationCommand::Zoom); |
| 666 | param = choose_param( shift_key, control_key, NavigationParam::Next, NavigationParam::Next, NavigationParam::CellDown, NavigationParam::End); |
| 667 | }, |
| 668 | VK_RETURN => { |
| 669 | command = choose_command(shift_key, control_key, NavigationCommand::Locate, NavigationCommand::Last, NavigationCommand::Locate, NavigationCommand::Last); |
| 670 | param = choose_param( shift_key, control_key, NavigationParam::Previous,NavigationParam::Last, NavigationParam::Last, NavigationParam::Last); |
| 671 | }, |
| 672 | VK_SPACE => { |
| 673 | command = choose_command(shift_key, control_key, NavigationCommand::Read, NavigationCommand::ToggleSpeakMode, NavigationCommand::Read, NavigationCommand::Describe); |
| 674 | param = choose_param( shift_key, control_key, NavigationParam::Current, NavigationParam::Last, NavigationParam::CellCurrent, NavigationParam::Current); |
| 675 | }, |
| 676 | |
| 677 | VK_HOME => { |
| 678 | command = choose_command(shift_key, control_key, NavigationCommand::Move, NavigationCommand::Move, NavigationCommand::Move, NavigationCommand::ReadTo); |
| 679 | param = choose_param( shift_key, control_key, NavigationParam::Start,NavigationParam::ColStart, NavigationParam::LineStart, NavigationParam::Start); |
| 680 | }, |
| 681 | VK_END => { |
| 682 | command = choose_command(shift_key, control_key, NavigationCommand::Move, NavigationCommand::Move, NavigationCommand::Move, NavigationCommand::ReadTo); |
| 683 | param = choose_param( shift_key, control_key, NavigationParam::End, NavigationParam::ColEnd, NavigationParam::LineEnd, NavigationParam::End); |
| 684 | }, |
| 685 | VK_BACK => { |
| 686 | command = NavigationCommand::MoveLastLocation; |
no test coverage detected