Skip to content

Commit 4faa620

Browse files
authored
Fix the page up/down bindings for OptionList (#3024)
* Fix the page up/down bindings for OptionList I'd had page_up and page_down bound when the actual names of the bindings are pageup and pagedown. This has always worked by sheer fluke because of where OptionList inherits from and by the coincidence of the action names. In other words: this commit has no substantive impact; but it does fix code that wasn't helpful and also makes the documentation more correct. * Correct the page up/down keys in the option list movement tests Turns out the pilot lets you press keys that don't actually exist. Who knew?!?
1 parent 080437c commit 4faa620

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/textual/widgets/_option_list.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class OptionList(ScrollView, can_focus=True):
130130
Binding("end", "last", "Last", show=False),
131131
Binding("enter", "select", "Select", show=False),
132132
Binding("home", "first", "First", show=False),
133-
Binding("page_down", "page_down", "Page Down", show=False),
134-
Binding("page_up", "page_up", "Page Up", show=False),
133+
Binding("pagedown", "page_down", "Page Down", show=False),
134+
Binding("pageup", "page_up", "Page Up", show=False),
135135
Binding("up", "cursor_up", "Up", show=False),
136136
]
137137
"""
@@ -141,8 +141,8 @@ class OptionList(ScrollView, can_focus=True):
141141
| end | Move the highlight to the last option. |
142142
| enter | Select the current option. |
143143
| home | Move the highlight to the first option. |
144-
| page_down | Move the highlight down a page of options. |
145-
| page_up | Move the highlight up a page of options. |
144+
| pagedown | Move the highlight down a page of options. |
145+
| pageup | Move the highlight up a page of options. |
146146
| up | Move the highlight up. |
147147
"""
148148

tests/option_list/test_option_list_movement.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_cleared_movement_does_nothing() -> None:
3333
option_list = pilot.app.query_one(OptionList)
3434
option_list.clear_options()
3535
assert option_list.highlighted is None
36-
await pilot.press("tab", "down", "up", "page_down", "page_up", "home", "end")
36+
await pilot.press("tab", "down", "up", "pagedown", "pageup", "home", "end")
3737
assert option_list.highlighted is None
3838

3939

@@ -90,7 +90,7 @@ async def test_move_home() -> None:
9090
async def test_page_down_from_start_short_list() -> None:
9191
"""Doing a page down from the start of a short list should move to the end."""
9292
async with OptionListApp().run_test() as pilot:
93-
await pilot.press("tab", "page_down")
93+
await pilot.press("tab", "pagedown")
9494
assert pilot.app.query_one(OptionList).highlighted == 5
9595

9696

@@ -101,7 +101,7 @@ async def test_page_up_from_end_short_list() -> None:
101101
assert option_list.highlighted == 0
102102
option_list.highlighted = 5
103103
assert option_list.highlighted == 5
104-
await pilot.press("tab", "page_up")
104+
await pilot.press("tab", "pageup")
105105
assert option_list.highlighted == 0
106106

107107

@@ -112,14 +112,14 @@ async def test_page_down_from_end_short_list() -> None:
112112
assert option_list.highlighted == 0
113113
option_list.highlighted = 5
114114
assert option_list.highlighted == 5
115-
await pilot.press("tab", "page_down")
115+
await pilot.press("tab", "pagedown")
116116
assert option_list.highlighted == 5
117117

118118

119119
async def test_page_up_from_start_short_list() -> None:
120120
"""Doing a page up from the start of a short list go nowhere."""
121121
async with OptionListApp().run_test() as pilot:
122-
await pilot.press("tab", "page_up")
122+
await pilot.press("tab", "pageup")
123123
assert pilot.app.query_one(OptionList).highlighted == 0
124124

125125

@@ -135,7 +135,7 @@ async def test_empty_list_movement() -> None:
135135
async with EmptyOptionListApp().run_test() as pilot:
136136
option_list = pilot.app.query_one(OptionList)
137137
await pilot.press("tab")
138-
for movement in ("up", "down", "home", "end", "page_up", "page_down"):
138+
for movement in ("up", "down", "home", "end", "pageup", "pagedown"):
139139
await pilot.press(movement)
140140
assert option_list.highlighted is None
141141

@@ -147,8 +147,8 @@ async def test_no_highlight_movement() -> None:
147147
("down", 0),
148148
("home", 0),
149149
("end", 99),
150-
("page_up", 0),
151-
("page_down", 99),
150+
("pageup", 0),
151+
("pagedown", 99),
152152
):
153153
async with EmptyOptionListApp().run_test() as pilot:
154154
option_list = pilot.app.query_one(OptionList)

0 commit comments

Comments
 (0)