aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/ducks/ui/keyboard.js
blob: 30fd76e1d618100da03e395dba839108dbfc84ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { Key } from "../../utils"
import { selectTab } from "./flow"
import * as flowsActions from "../flows"


export function onKeyDown(e) {
    console.debug("onKeyDown", e)
    if (e.ctrlKey) {
        return () => {
        }
    }
    var key      = e.keyCode
    var shiftKey = e.shiftKey
    e.preventDefault()
    return (dispatch, getState) => {

        const flow = getState().flows.byId[getState().flows.selected[0]]

        switch (key) {
            case Key.K:
            case Key.UP:
                dispatch(flowsActions.selectRelative(-1))
                break

            case Key.J:
            case Key.DOWN:
                dispatch(flowsActions.selectRelative(+1))
                break

            case Key.SPACE:
            case Key.PAGE_DOWN:
                dispatch(flowsActions.selectRelative(+10))
                break

            case Key.PAGE_UP:
                dispatch(flowsActions.selectRelative(-10))
                break

            case Key.END:
                dispatch(flowsActions.selectRelative(+1e10))
                break

            case Key.HOME:
                dispatch(flowsActions.selectRelative(-1e10))
                break

            case Key.ESC:
                dispatch(flowsActions.select(null))
                break

            case Key.LEFT: {
                if (!flow) break
                let tabs       = ['request', 'response', 'error'].filter(k => flow[k]).concat(['details']),
                    currentTab = getState().ui.flow.tab,
                    nextTab    = tabs[(tabs.indexOf(currentTab) - 1 + tabs.length) % tabs.length]
                dispatch(selectTab(nextTab))
                break
            }

            case Key.TAB:
            case Key.RIGHT: {
                if (!flow) break
                let tabs       = ['request', 'response', 'error'].filter(k => flow[k]).concat(['details']),
                    currentTab = getState().ui.flow.tab,
                    nextTab    = tabs[(tabs.indexOf(currentTab) + 1) % tabs.length]
                dispatch(selectTab(nextTab))
                break
            }

            case Key.D: {
                if (!flow) {
                    return
                }
                if (shiftKey) {
                    dispatch(flowsActions.duplicate(flow))
                } else {
                    dispatch(flowsActions.remove(flow))
                }
                break
            }

            case Key.A: {
                if (shiftKey) {
                    dispatch(flowsActions.resumeAll())
                } else if (flow && flow.intercepted) {
                    dispatch(flowsActions.resume(flow))
                }
                break
            }

            case Key.R: {
                if (!shiftKey && flow) {
                    dispatch(flowsActions.replay(flow))
                }
                break
            }

            case Key.V: {
                if (!shiftKey && flow && flow.modified) {
                    dispatch(flowsActions.revert(flow))
                }
                break
            }

            case Key.X: {
                if (shiftKey) {
                    dispatch(flowsActions.killAll())
                } else if (flow && flow.intercepted) {
                    dispatch(flowsActions.kill(flow))
                }
                break
            }

            case Key.Z: {
                if (!shiftKey) {
                    dispatch(flowsActions.clear())
                }
                break
            }


            default:
                return
        }
    }
}