Skip to content

Commit bb2746b

Browse files
committed
tabs: add TabStops.clear_all()
1 parent 0e479dc commit bb2746b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docx/text/tabstops.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def add_tab_stop(self, position, alignment=WD_TAB_ALIGNMENT.LEFT,
7575
tab = tabs.insert_tab_in_order(position, alignment, leader)
7676
return TabStop(tab)
7777

78+
def clear_all(self):
79+
"""
80+
Remove all tab stops.
81+
"""
82+
tabs = self._pPr.get_or_add_tabs()
83+
while len(tabs) > 0:
84+
del tabs[0]
85+
7886

7987
class TabStop(ElementProxy):
8088
"""

tests/text/test_tabstops.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,24 @@ def it_can_delete_a_tab_stop(self, delete_tab_fixture):
153153
del tab_stops[index]
154154
assert tab_stops._element.xml == expected_xml
155155

156+
def it_can_clear_all_tab_stops(self, clear_all_tab_stops_fixture):
157+
tab_stops = clear_all_tab_stops_fixture
158+
tab_stops.clear_all()
159+
assert len(tab_stops) == 0
160+
156161
# fixture --------------------------------------------------------
157162

163+
@pytest.fixture(params=[
164+
'w:pPr',
165+
'w:pPr/w:tabs/w:tab{w:pos=2880}',
166+
'w:pPr/w:tabs/(w:tab{w:pos=24,w:val=center},'
167+
'w:tab{w:pos=42,w:val=left})',
168+
])
169+
def clear_all_tab_stops_fixture(self, request):
170+
pPr_cxml = request.param
171+
tab_stops = TabStops(element(pPr_cxml))
172+
return tab_stops
173+
158174
@pytest.fixture(params=[
159175
('w:pPr/w:tabs/w:tab{w:pos=42,w:val=left}', 0, 'w:pPr'),
160176
('w:pPr/w:tabs/(w:tab{w:pos=24,w:val=center},'

0 commit comments

Comments
 (0)