diff --git a/internal/editor/state.go b/internal/editor/state.go index 8fbadaf..9a177be 100644 --- a/internal/editor/state.go +++ b/internal/editor/state.go @@ -1857,6 +1857,10 @@ func markDirty() { } // EditorLayout computes the element tree for the editor page. +// FindBarHeight is the find bar's height; buildFindBar and EditorLayout +// (which shrinks the text area to make room) both use it. +const FindBarHeight = ui.Dp(40) + // buildFindBar lays out the in-file search bar: [input][counter][prev][next] // [close], full screen width, directly below the margin-free top bar (the // bars merge, so this one does too; inner content keeps the margin). The @@ -1866,7 +1870,7 @@ func markDirty() { func buildFindBar(screenWidth ui.Dp) ui.Element { margin := ui.Dp(10) gap := ui.Dp(8) - h := ui.Dp(40) + h := FindBarHeight topY := ui.Dp(32) // top bar height (see EditorLayout) // Right-hand button column: prev, next, close. @@ -1988,7 +1992,12 @@ func EditorLayout(screenWidth, screenHeight ui.Dp, wordWrap bool) []ui.Element { } // --- Editor text area --- + // While the find bar is open it sits in [32, 32+FindBarHeight); shrink the + // text area from the top so the first visible line is not covered. editorY := statusBarRegion.Y + statusBarRegion.H + if TheState.Editor.Find.Visible { + editorY += FindBarHeight + } editorH := bottomBarRegion.Y - editorY editorRegion := ui.Region{ X: margin, Y: editorY, diff --git a/internal/test/e2e/find_test.go b/internal/test/e2e/find_test.go index 05b015b..fcacd1b 100644 --- a/internal/test/e2e/find_test.go +++ b/internal/test/e2e/find_test.go @@ -80,6 +80,12 @@ func TestRealFile_FindBarAndNavigation(t *testing.T) { if focus.(string) != "find_bar" { t.Fatalf("focus %q, want find_bar", focus) } + // The text area must shrink from the top while the find bar is open so + // the first line is not covered: region top = top bar (32) + FindBarHeight. + reg, _ := h.Inspect(func(st *editor.State) any { return st.EditorRegion }) + if got := reg.(ui.Region); got.Y != ui.Dp(32)+editor.FindBarHeight { + t.Fatalf("editor region top %d, want %d (find bar must not cover text)", int(got.Y), int(ui.Dp(32)+editor.FindBarHeight)) + } // Type the query through the same channel main uses. h.Logic().FindQueryChan() <- "NEEDLE" // case-insensitive