Skip to content

Commit 81b58b6

Browse files
committed
feat: Added cmt+T, opt+tab and opt+shift+tab keybinds
1 parent b2eece2 commit 81b58b6

2 files changed

Lines changed: 43 additions & 40 deletions

File tree

harbor/engine/src/render/mod.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl ApplicationHandler<AppEvent> for App {
173173
WindowEvent::Resized(size) => {
174174
state.resize(size.width, size.height);
175175
}
176+
WindowEvent::ModifiersChanged(m) => state.modifiers = m,
176177
WindowEvent::CursorMoved { position, .. } => {
177178
if state.layout.is_none() {
178179
return;
@@ -378,50 +379,21 @@ impl ApplicationHandler<AppEvent> for App {
378379
if !state.address_bar_active {
379380
match (code, key_state) {
380381
(KeyCode::Escape, ElementState::Pressed) => event_loop.exit(),
381-
(
382-
KeyCode::Digit0
383-
| KeyCode::Digit1
384-
| KeyCode::Digit2
385-
| KeyCode::Digit3
386-
| KeyCode::Digit4
387-
| KeyCode::Digit5
388-
| KeyCode::Digit6
389-
| KeyCode::Digit7
390-
| KeyCode::Digit8
391-
| KeyCode::Digit9,
392-
ElementState::Pressed,
393-
) => {
394-
let digit = match code {
395-
KeyCode::Digit0 => 0,
396-
KeyCode::Digit1 => 1,
397-
KeyCode::Digit2 => 2,
398-
KeyCode::Digit3 => 3,
399-
KeyCode::Digit4 => 4,
400-
KeyCode::Digit5 => 5,
401-
KeyCode::Digit6 => 6,
402-
KeyCode::Digit7 => 7,
403-
KeyCode::Digit8 => 8,
404-
KeyCode::Digit9 => 9,
405-
_ => unreachable!(),
406-
};
407-
408-
if digit < state.tab_datas.len() {
409-
let tab_data = &state.tab_datas[digit];
410-
411-
state.active_tab = digit;
412-
413-
if let Some(callbacks) = &self.callbacks {
414-
(callbacks.link_callback)(&tab_data.url);
382+
(KeyCode::KeyT, ElementState::Pressed) => {
383+
if cfg!(target_os = "macos") {
384+
if !state.modifiers.state().super_key() {
385+
return;
386+
}
387+
} else {
388+
if !state.modifiers.state().control_key() {
389+
return;
415390
}
416391
}
417-
}
418-
(KeyCode::Minus, ElementState::Pressed) => {
392+
419393
if let Some(state) = &mut self.state {
420394
state.tab_datas.insert(
421395
state.active_tab + 1,
422-
TabData::empty_from(String::from(
423-
"https://flavorless.hackclub.com/",
424-
)),
396+
TabData::empty_from(String::from("harbor:new")),
425397
);
426398

427399
state.active_tab += 1;
@@ -432,6 +404,34 @@ impl ApplicationHandler<AppEvent> for App {
432404
}
433405
}
434406
}
407+
(KeyCode::Tab, ElementState::Pressed) => {
408+
if !state.modifiers.state().alt_key() {
409+
return;
410+
}
411+
412+
let direction = if state.modifiers.state().shift_key() {
413+
-1
414+
} else {
415+
1
416+
};
417+
418+
if key_state == ElementState::Pressed {
419+
let num_tabs = state.tab_datas.len();
420+
421+
if num_tabs == 0 {
422+
return;
423+
}
424+
425+
state.active_tab = ((state.active_tab as isize + direction)
426+
.rem_euclid(num_tabs as isize))
427+
as usize;
428+
429+
if let Some(callbacks) = &self.callbacks {
430+
let tab_data = &state.tab_datas[state.active_tab];
431+
(callbacks.open_tab)(tab_data);
432+
}
433+
}
434+
}
435435
_ => {}
436436
}
437437
} else {

harbor/engine/src/render/state.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{cell::RefCell, collections::HashMap, ops::Deref, rc::Rc, sync::Arc};
22

33
use wgpu::util::DeviceExt;
4-
use winit::window::Window;
4+
use winit::{event::Modifiers, keyboard::ModifiersState, window::Window};
55

66
use crate::{
77
css::{
@@ -123,6 +123,8 @@ pub struct WindowState {
123123

124124
pub address_bar_active: bool,
125125
pub address_bar_input: String,
126+
127+
pub modifiers: Modifiers,
126128
}
127129

128130
impl WindowState {
@@ -1412,6 +1414,7 @@ impl WindowState {
14121414
cursor_position: (0.0, 0.0),
14131415
address_bar_active: false,
14141416
address_bar_input: String::new(),
1417+
modifiers: Modifiers::default(),
14151418
}
14161419
}
14171420

0 commit comments

Comments
 (0)