ratatui_toolkit/widgets/code_diff/widget/methods/toggle_focus.rs
1//! Method to toggle focus between sidebar and diff view.
2
3use crate::widgets::code_diff::code_diff::CodeDiff;
4
5impl CodeDiff {
6 /// Toggles focus between the sidebar and diff view.
7 ///
8 /// When sidebar is focused, navigation keys move through files.
9 /// When diff view is focused, navigation keys scroll the diff.
10 ///
11 /// # Example
12 ///
13 /// ```rust
14 /// use ratatui_toolkit::code_diff::{CodeDiff, DiffConfig};
15 ///
16 /// let mut diff = CodeDiff::new()
17 /// .with_config(DiffConfig::new().sidebar_enabled(true));
18 ///
19 /// assert!(diff.sidebar_focused);
20 /// diff.toggle_focus();
21 /// assert!(!diff.sidebar_focused);
22 /// ```
23 pub fn toggle_focus(&mut self) {
24 self.sidebar_focused = !self.sidebar_focused;
25 self.file_tree.focused = self.sidebar_focused;
26 }
27}