@@ -238,55 +238,52 @@ def tearDownClass(cls):
238238 class DummyRMenu :
239239 def tk_popup (x , y ): pass
240240
241- def click (self , x = 0 , y = 0 ):
242- """Simulate a right click at the (x, y) pixel of the text.
243-
244- Return the index of the clicked character, as computed by the
245- widget itself. It cannot be computed here, because the geometry
246- of the text is unknown while its window is not mapped.
241+ def click (self ):
242+ """Simulate a right click at(text pixel 0,0).
247243 """
248- index = self .text .index (f'@{ x } ,{ y } ' )
249244 Event = namedtuple ('Event' , ['x' , 'y' , 'x_root' , 'y_root' ])
250- event = Event (x , y , x_root = 0 , y_root = 0 )
245+ event = Event (0 , 0 , 0 , 0 )
251246 self .assertEqual (self .window .right_menu_event (event ), 'break' )
252- return index
253-
254- def test_rclick_no_selection (self ):
255- text = self .text
256- insert (text , 'one two three' )
257- index = self .click ()
258- self .assertEqual (text .tag_ranges ('sel' ), ())
259- self .assertEqual (text .index ('insert' ), index )
247+ # This assertion should be moved to a new method that also
248+ # text that dummy rmenu.tk_popup is called.
260249
261- def test_rclick_outside_selection (self ):
250+ def test_rclick_not_in_a_selection (self ):
251+ # Like left click, 'insert' moves to click and any selection is deleted.
252+ eq = self .assertEqual
262253 text = self .text
263254 insert (text , 'one two three' )
264- # The selection does not contain the clicked character.
265- text .tag_add ('sel' , '1.5' , '1.8' )
255+ # Selection exists but not clicked.
256+ text .tag_add ('sel' , '1.4' , '1.7' ) # 'two' selected.
257+ text .mark_set ('insert' , '1.7' ) # Outside of selection.
258+ self .click ()
259+ eq (text .tag_ranges ('sel' ), ())
260+ eq (text .index ('insert' ), '1.0' )
261+ # No selection to click, same result.
266262 text .mark_set ('insert' , '1.8' )
267263 index = self .click ()
268- self . assertEqual (text .tag_ranges ('sel' ), ())
269- self . assertEqual (text .index ('insert' ), index )
264+ eq (text .tag_ranges ('sel' ), ())
265+ eq (text .index ('insert' ), '1.0' )
270266
271267 def test_rclick_inside_selection (self ):
268+ # Unlike left click, selection is not deleted.
269+ eq = self .assertEqual
272270 text = self .text
273- insert (text , 'one two three' )
271+ insert (text , 'one two three' ) # 'insert' at 1.13.
274272 # The selection contains the clicked character.
275- index = text .index ('@0,0' )
276- text .tag_add ('sel' , index , f'{ index } +3c' )
277- text .mark_set ('insert' , 'end-1c' )
273+ text .tag_add ('sel' , 1.0 , 1.3 ) # Select 'one'.
274+ text .mark_set ('insert' , '1.3' ) # If select rightward, 'insert' at 1.3.
278275 self .click ()
279- self .assertEqual (text .index ('sel.first' ), index )
280- self .assertEqual (text .index ('sel.last' ), text .index (f'{ index } +3c' ))
281- self .assertEqual (text .index ('insert' ), text .index ('end-1c' ))
276+ eq ((text .index ('sel.first' ), text .index ('sel.last' )), ('1.0' , '1.3' ))
277+ eq (text .index ('insert' ), '1.3' )
282278
283279 def test_rmenu_check_copy (self ):
280+ # copy and cut only valid for click inside selection.
281+ eq = self .assertEqual
284282 text = self .text
285283 insert (text , 'one two three' )
286- eq = self .assertEqual
287284 eq (self .window .rmenu_check_copy (), 'disabled' )
288285 eq (self .window .rmenu_check_cut (), 'disabled' )
289- text .tag_add ('sel' , '1.0' , '1.3' )
286+ text .tag_add ('sel' , '1.0' , '1.3' ) # Includes '1.0' click.
290287 eq (self .window .rmenu_check_copy (), 'normal' )
291288 eq (self .window .rmenu_check_cut (), 'normal' )
292289
0 commit comments