Complete resize strategy integration and remove placeholder UI

This commit is contained in:
白鸽 2026-10-09 20:20:36 +08:00
parent c317e0f1be
commit c0f257f889
4 changed files with 21 additions and 39 deletions

View file

@ -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"

View file

@ -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.

View file

@ -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{

View file

@ -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