1
//! Intents of the rows-like widgets: selects, rows lists and the split tag list.
2

            
3
use super::{Intent, apply_editor_intent};
4
use crate::widgets::{RowsWidget, SelectWidget, SplitsWidget};
5

            
6
263
pub(super) fn apply_select_intent(sw: &mut SelectWidget, intent: Intent) {
7
263
    match intent {
8
87
        Intent::SelectNext => sw.next(),
9
19
        Intent::SelectPrev => sw.prev(),
10
37
        Intent::SelectConfirm => sw.confirm(),
11
64
        Intent::SelectOpen => sw.open_list(),
12
8
        Intent::SelectCancel => sw.cancel(),
13
3
        Intent::SelectPick(index) => sw.pick(index),
14
6
        Intent::SelectPageUp => sw.page(false),
15
15
        Intent::SelectPageDown => sw.page(true),
16
16
        Intent::InsertChar(c) => sw.filter_push(c),
17
8
        Intent::DeleteBackward => sw.filter_pop(),
18
        _ => {}
19
    }
20
263
}
21

            
22
91
pub(super) fn apply_rows_intent(rw: &mut RowsWidget, intent: Intent) {
23
91
    match intent {
24
18
        Intent::CellNext => rw.advance_cell(),
25
1
        Intent::CellPrev => rw.retreat_cell(),
26
1
        Intent::RowNext => rw.next_row(),
27
        Intent::RowPrev => rw.prev_row(),
28
3
        Intent::SplitAddRow => rw.add_row(),
29
2
        Intent::SplitRemoveRow => rw.remove_row(),
30
43
        Intent::InsertChar(c) if rw.is_empty() && !c.is_whitespace() => {
31
1
            rw.add_row();
32
1
            apply_rows_intent(rw, intent);
33
        }
34
        intent => {
35
65
            if let Some(select) = rw.focused_select_mut() {
36
19
                apply_select_intent(select, intent);
37
46
            } else if let Some(editor) = rw.focused_editor_mut() {
38
44
                apply_editor_intent(editor, intent);
39
2
            }
40
        }
41
    }
42
91
}
43

            
44
58
pub(super) fn apply_tags_intent(sw: &mut SplitsWidget, intent: Intent) {
45
58
    match intent {
46
        Intent::ToggleSplitTags => {
47
            sw.close_tags();
48
        }
49
5
        Intent::SplitAddRow => sw.add_tag(),
50
        Intent::InsertChar(c)
51
21
            if !c.is_whitespace() && sw.tags().is_some_and(RowsWidget::is_empty) =>
52
        {
53
1
            sw.add_tag();
54
1
            apply_tags_intent(sw, intent);
55
        }
56
        intent => {
57
52
            if let Some(rw) = sw.tags_mut() {
58
52
                apply_rows_intent(rw, intent);
59
            }
60
        }
61
    }
62
58
}