From c0f257f889a5e15410dc92b9110aa032c4eea7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=B8=BD?= <18717730+xiaobai050@users.noreply.github.com> Date: Fri, 9 Oct 2026 20:20:36 +0800 Subject: [PATCH] Complete resize strategy integration and remove placeholder UI --- kittens/resize_window/main.go | 35 +++++++------------------- kittens/resize_window/main.py | 4 +-- kittens/resize_window/settings_test.go | 15 +++++------ kittens/resize_window/strategies.go | 6 ++--- 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/kittens/resize_window/main.go b/kittens/resize_window/main.go index da9b4d1e4..43f554078 100644 --- a/kittens/resize_window/main.go +++ b/kittens/resize_window/main.go @@ -192,8 +192,8 @@ func (h *handler) window_on_key(e *loop.KeyEvent) error { } func (h *handler) draw_screen() { - if h.page == "" && h.active_strategy() == "edge" && edge_strategy != nil { - h.draw_edge_screen() + if h.page == "" && h.active_strategy() == "edge" { + h.active_hooks().Draw(h) return } lp, ctx := h.lp, h.ctx @@ -204,18 +204,8 @@ func (h *handler) draw_screen() { h.draw_settings_page() return } - title := "Resize this window" - if h.active_strategy() == "edge" { - title = "Resize an edge" - } - lp.Println(lp.SprintStyled("bold fg=white", title)) - window, edge := "1: Window", "2: Edge" - if h.active_strategy() == "window" { - window = ctx.Green(window) - } else { - edge = ctx.Green(edge) - } - lp.Println("Strategy: " + window + " " + edge) + lp.Println(lp.SprintStyled("bold fg=white", "Resize this window")) + lp.Println("Strategy: " + ctx.Green("1: Window") + " 2: Edge") p := h.active_preferences() modifier := "Alt" if p.Modifier == "shift" { @@ -223,18 +213,11 @@ func (h *handler) draw_screen() { } lp.Println(ctx.Green("M") + ": " + modifier + " " + ctx.Green("F") + ": " + p.Fraction + " (change settings)") lp.Println() - if h.active_strategy() == "window" { - lp.Println(" " + ctx.Green("W") + "ider") - lp.Println(" " + ctx.Green("N") + "arrower") - lp.Println(" " + ctx.Green("T") + "aller") - lp.Println(" " + ctx.Green("S") + "horter") - lp.Println(" " + ctx.Red("R") + "eset") - } else if hooks := h.active_hooks(); hooks != nil && hooks.Draw != nil { - hooks.Draw(h) - } else { - lp.Println("Edge strategy is not available yet.") - lp.Println("Its modifier and fraction can still be saved.") - } + lp.Println(" " + ctx.Green("W") + "ider") + lp.Println(" " + ctx.Green("N") + "arrower") + lp.Println(" " + ctx.Green("T") + "aller") + lp.Println(" " + ctx.Green("S") + "horter") + lp.Println(" " + ctx.Red("R") + "eset") lp.Println(lp.SprintStyled("italic", "Esc") + ": quit " + lp.SprintStyled("italic", "Ctrl") + ": double step size") lp.Println(lp.SprintStyled("italic", modifier) + ": " + p.Fraction + " of the remaining steps") status := "Settings saved automatically" diff --git a/kittens/resize_window/main.py b/kittens/resize_window/main.py index 325fa8186..78406904a 100644 --- a/kittens/resize_window/main.py +++ b/kittens/resize_window/main.py @@ -33,8 +33,8 @@ Choose the initial resize strategy. Window changes pane width or height; edge selects an internal pane edge with H/J/K/L or arrow keys, then moves its divider along that axis. A sole available edge is selected automatically. In Splits, either strategy uses R to restore the proportions saved when resize -mode opened. Switching strategies preserves this snapshot. Edge resizing is -currently limited to Splits; other layouts retain Window's usual reset behavior. +mode opened. Switching strategies preserves this snapshot. Edge resizing uses +the Splits layout; other layouts retain Window's usual reset behavior. When omitted, uses the strategy saved from the resize page. Inside the page, 1 and 2 choose a strategy, M switches its Alt/Shift modifier, and F changes its fraction. Each strategy's settings are saved separately. diff --git a/kittens/resize_window/settings_test.go b/kittens/resize_window/settings_test.go index 385bf36da..20c4092d0 100644 --- a/kittens/resize_window/settings_test.go +++ b/kittens/resize_window/settings_test.go @@ -144,23 +144,24 @@ func TestResizeSettingsModifiers(t *testing.T) { } } -func TestResizeStrategyPlaceholderAndHooks(t *testing.T) { +func TestResizeStrategyHooks(t *testing.T) { old := edge_strategy t.Cleanup(func() { edge_strategy = old }) - edge_strategy = nil + if edge_strategy == nil || edge_strategy.OnKey == nil || edge_strategy.OnText == nil || edge_strategy.Draw == nil { + t.Fatal("Edge strategy is missing its interaction handlers") + } s := default_settings() s.Strategy = "edge" - // No loop: falling back to window resizing would panic instead of quietly - // leaving the pane alone when an implementation is unavailable. - h := &handler{settings: s, opts: &Options{}} + // No loop: accidentally routing Window keys to a resize would panic. + h := &handler{settings: s, opts: &Options{}, edge_ready: true} for _, text := range []string{"w", "W", "n", "t", "s"} { if err := h.on_text(text); err != nil { t.Fatal(err) } } - e := &loop.KeyEvent{Key: "w", Mods: loop.ALT, Type: loop.PRESS} + e := &loop.KeyEvent{Key: "w", Type: loop.PRESS} if err := h.on_key(e); err != nil || e.Handled { - t.Fatalf("placeholder handled a resize: %v", err) + t.Fatalf("Edge handled a Window resize key: %v", err) } keys, texts := 0, 0 edge_strategy = &strategy_hooks{ diff --git a/kittens/resize_window/strategies.go b/kittens/resize_window/strategies.go index cdd2e3fd1..c35ef184a 100644 --- a/kittens/resize_window/strategies.go +++ b/kittens/resize_window/strategies.go @@ -4,10 +4,8 @@ package resize_window import "github.com/kovidgoyal/kitty/tools/tui/loop" -// The edge implementation can register these hooks from its own file's init(). -// Settings keys and persistence are shared; all edge operations stay in that -// implementation. A nil registration is an unavailable strategy, never a -// fallback to resizing the whole window. +// Edge interaction uses these hooks while settings keys and persistence are +// shared with Window resizing. type strategy_hooks struct { OnActivate func(*handler) error OnDeactivate func(*handler) error