layout: Find preset width for new columns
Browse files at this commite2576879216a39e5c45b9d2906531bc2065e724cParent: 94eeeca1 changed file +17 -1
- src/layout/scrolling.rs +17 -1
src/layout/scrolling.rsmodified+17 -1
| @@ -3934,12 +3934,28 @@ impl<W: LayoutElement> Column<W> { | |||
| 3934 | .default_column_display | 3934 | .default_column_display |
| 3935 | .unwrap_or(options.layout.default_column_display); | 3935 | .unwrap_or(options.layout.default_column_display); |
| 3936 | 3936 | ||
| 3937 | + // Try to match width to a preset width. Consider the following case: a terminal (foot) | ||
| 3938 | + // sizes itself to the terminal grid. We open it with default-column-width 0.5. It shrinks | ||
| 3939 | + // by a few pixels to evenly match the terminal grid. Then we press | ||
| 3940 | + // switch-preset-column-width intending to go to proportion 0.667, but the preset width | ||
| 3941 | + // matching code picks the proportion 0.5 preset because it's the next smallest width after | ||
| 3942 | + // the current foot's window width. Effectively, this makes the first | ||
| 3943 | + // switch-preset-column-width press ignored. | ||
| 3944 | + // | ||
| 3945 | + // However, here, we do know that width = proportion 0.5 (regardless of what the window | ||
| 3946 | + // opened with), and we can match it to a preset right away, if one exists. | ||
| 3947 | + let preset_width_idx = options | ||
| 3948 | + .layout | ||
| 3949 | + .preset_column_widths | ||
| 3950 | + .iter() | ||
| 3951 | + .position(|preset| width == ColumnWidth::from(*preset)); | ||
| 3952 | + | ||
| 3937 | let mut rv = Self { | 3953 | let mut rv = Self { |
| 3938 | tiles: vec![], | 3954 | tiles: vec![], |
| 3939 | data: vec![], | 3955 | data: vec![], |
| 3940 | active_tile_idx: 0, | 3956 | active_tile_idx: 0, |
| 3941 | width, | 3957 | width, |
| 3942 | - preset_width_idx: None, | 3958 | + preset_width_idx, |
| 3943 | is_full_width, | 3959 | is_full_width, |
| 3944 | is_pending_maximized: false, | 3960 | is_pending_maximized: false, |
| 3945 | is_pending_fullscreen: false, | 3961 | is_pending_fullscreen: false, |