Skip to content

Commit 362a8a7

Browse files
committed
fix: fix focus change in color-picker
1 parent 44ad2f3 commit 362a8a7

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

src/ui/components/issue_conversation.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,16 +1582,22 @@ impl Component for IssueConversation {
15821582
self.open_close_popup();
15831583
return Ok(());
15841584
}
1585-
ct_event!(keycode press Tab) | ct_event!(keycode press BackTab)
1586-
if self.input_state.is_focused() =>
1587-
{
1585+
ct_event!(keycode press Tab) if self.input_state.is_focused() => {
15881586
let action_tx = self.action_tx.as_ref().ok_or_else(|| {
15891587
AppError::Other(anyhow!(
15901588
"issue conversation action channel unavailable"
15911589
))
15921590
})?;
15931591
action_tx.send(Action::ForceFocusChange).await?;
15941592
}
1593+
ct_event!(keycode press SHIFT-BackTab) if self.input_state.is_focused() => {
1594+
let action_tx = self.action_tx.as_ref().ok_or_else(|| {
1595+
AppError::Other(anyhow!(
1596+
"issue conversation action channel unavailable"
1597+
))
1598+
})?;
1599+
action_tx.send(Action::ForceFocusChangeRev).await?;
1600+
}
15951601
ct_event!(keycode press Esc) if self.body_paragraph_state.is_focused() => {
15961602
let action_tx = self.action_tx.as_ref().ok_or_else(|| {
15971603
AppError::Other(anyhow!(

src/ui/components/label_list.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ enum LabelEditMode {
9494
},
9595
}
9696

97+
impl LabelEditMode {
98+
fn input(&self) -> Option<&TextInputState> {
99+
match self {
100+
LabelEditMode::Adding { input } => Some(input),
101+
LabelEditMode::CreateColor { input, .. } => Some(input),
102+
_ => None,
103+
}
104+
}
105+
}
106+
97107
#[derive(Debug)]
98108
struct PopupLabelSearchState {
99109
input: TextInputState,
@@ -482,7 +492,6 @@ impl LabelList {
482492
return;
483493
}
484494
let input = TextInputState::new_focused();
485-
input.focus.set(true);
486495
self.state.focus.set(false);
487496
self.popup_search = Some(PopupLabelSearchState {
488497
input,
@@ -925,6 +934,7 @@ impl Component for LabelList {
925934
match key.code {
926935
crossterm::event::KeyCode::Char('a') => {
927936
if self.state.is_focused() {
937+
self.state.focus.set(false);
928938
let input = TextInputState::new_focused();
929939
next_mode = Some(LabelEditMode::Adding { input });
930940
handled = true;
@@ -938,6 +948,7 @@ impl Component for LabelList {
938948
}
939949
crossterm::event::KeyCode::Char('f') => {
940950
if self.state.is_focused() {
951+
self.state.focus.set(false);
941952
self.open_popup_search();
942953
handled = true;
943954
}
@@ -977,6 +988,7 @@ impl Component for LabelList {
977988
match key.code {
978989
crossterm::event::KeyCode::Char('y')
979990
| crossterm::event::KeyCode::Char('Y') => {
991+
self.state.focus.set(false);
980992
let mut input = TextInputState::new_focused();
981993
input.set_text(DEFAULT_COLOR);
982994
let picker = ColorPickerState::with_initial_hex(DEFAULT_COLOR);
@@ -1002,7 +1014,10 @@ impl Component for LabelList {
10021014
picker,
10031015
} => {
10041016
let mut skip_input = false;
1005-
if matches!(event, ct_event!(keycode press Tab)) {
1017+
if matches!(
1018+
event,
1019+
ct_event!(keycode press Tab) | ct_event!(keycode press SHIFT-BackTab)
1020+
) {
10061021
skip_input = true;
10071022
}
10081023
if matches!(picker.handle(event, Regular), Outcome::Changed) {
@@ -1227,14 +1242,16 @@ impl Component for LabelList {
12271242
impl HasFocus for LabelList {
12281243
fn build(&self, builder: &mut rat_widget::focus::FocusBuilder) {
12291244
let tag = builder.start(self);
1230-
builder.widget(&self.state);
1245+
builder.leaf_widget(&self.state);
12311246
if let Some(popup) = &self.popup_search {
1232-
builder.widget(&popup.input);
1233-
builder.widget(&popup.list_state);
1247+
builder.leaf_widget(&popup.input);
1248+
builder.leaf_widget(&popup.list_state);
1249+
}
1250+
if let Some(input) = self.mode.input() {
1251+
builder.leaf_widget(input);
12341252
}
1235-
if let LabelEditMode::CreateColor { input, picker, .. } = &self.mode {
1236-
builder.widget(input);
1237-
builder.widget(picker);
1253+
if let LabelEditMode::CreateColor { picker, .. } = &self.mode {
1254+
builder.leaf_widget(picker);
12381255
}
12391256
builder.end(tag);
12401257
}

0 commit comments

Comments
 (0)