Load bindings for the navigation in the sidebar.
(python_input: PythonInput)
| 223 | |
| 224 | |
| 225 | def load_sidebar_bindings(python_input: PythonInput) -> KeyBindings: |
| 226 | """ |
| 227 | Load bindings for the navigation in the sidebar. |
| 228 | """ |
| 229 | bindings = KeyBindings() |
| 230 | |
| 231 | handle = bindings.add |
| 232 | sidebar_visible = Condition(lambda: python_input.show_sidebar) |
| 233 | |
| 234 | @handle("up", filter=sidebar_visible) |
| 235 | @handle("c-p", filter=sidebar_visible) |
| 236 | @handle("k", filter=sidebar_visible) |
| 237 | def _(event: E) -> None: |
| 238 | "Go to previous option." |
| 239 | python_input.selected_option_index = ( |
| 240 | python_input.selected_option_index - 1 |
| 241 | ) % python_input.option_count |
| 242 | |
| 243 | @handle("down", filter=sidebar_visible) |
| 244 | @handle("c-n", filter=sidebar_visible) |
| 245 | @handle("j", filter=sidebar_visible) |
| 246 | def _(event: E) -> None: |
| 247 | "Go to next option." |
| 248 | python_input.selected_option_index = ( |
| 249 | python_input.selected_option_index + 1 |
| 250 | ) % python_input.option_count |
| 251 | |
| 252 | @handle("right", filter=sidebar_visible) |
| 253 | @handle("l", filter=sidebar_visible) |
| 254 | @handle(" ", filter=sidebar_visible) |
| 255 | def _(event: E) -> None: |
| 256 | "Select next value for current option." |
| 257 | option = python_input.selected_option |
| 258 | option.activate_next() |
| 259 | |
| 260 | @handle("left", filter=sidebar_visible) |
| 261 | @handle("h", filter=sidebar_visible) |
| 262 | def _(event: E) -> None: |
| 263 | "Select previous value for current option." |
| 264 | option = python_input.selected_option |
| 265 | option.activate_previous() |
| 266 | |
| 267 | @handle("c-c", filter=sidebar_visible) |
| 268 | @handle("c-d", filter=sidebar_visible) |
| 269 | @handle("c-d", filter=sidebar_visible) |
| 270 | @handle("enter", filter=sidebar_visible) |
| 271 | @handle("escape", filter=sidebar_visible) |
| 272 | def _(event: E) -> None: |
| 273 | "Hide sidebar." |
| 274 | python_input.show_sidebar = False |
| 275 | event.app.layout.focus_last() |
| 276 | |
| 277 | return bindings |
| 278 | |
| 279 | |
| 280 | def load_confirm_exit_bindings(python_input: PythonInput) -> KeyBindings: |