Merge lp:~samh/leo-editor/delete-word into lp:leo-editor/old-trunk

Proposed by Sam Hartsfield
Status: Merged
Merged at revision: 3295
Proposed branch: lp:~samh/leo-editor/delete-word
Merge into: lp:leo-editor/old-trunk
Diff against target: 243 lines (+144/-11) (has conflicts)
4 files modified
leo/core/leoEditCommands.py (+7/-3)
leo/core/leoKeys.py (+5/-1)
leo/plugins/qtGui.py (+1/-1)
leo/test/unitTest.leo (+131/-6)
Text conflict in leo/test/unitTest.leo
To merge this branch: bzr merge lp:~samh/leo-editor/delete-word
Reviewer Review Type Date Requested Status
Edward K. Ream Pending
Review via email: mp+34001@code.launchpad.net

Description of the change

The first revision fixes delete-word / backward-delete-word in headlines, the second fixes backward-delete-word in Tk.

The third is to help with unit tests, and the 4th adds some header unit tests for [backward-]delete-word.

It's fine if you just take the first two commits. If you want me to change the way I did the unit tests in the 4th commit to make it acceptable, let me know (or fix it yourself, or just drop it, whatever you'd prefer).

To post a comment you must log in.
Revision history for this message
Edward K. Ream (edreamleo) wrote :

On Sat, Aug 28, 2010 at 2:07 PM, Sam Hartsfield <email address hidden> wrote:
> Sam Hartsfield has proposed merging lp:~samh/leo-editor/delete-word into lp:leo-editor.

> The first revision fixes delete-word / backward-delete-word in headlines, the second fixes backward-delete-word in Tk.
>
> The third is to help with unit tests, and the 4th adds some header unit tests for [backward-]delete-word.

Thanks for this. I'll be testing your branch today and merging it if
all seems good.

Edward

Revision history for this message
Edward K. Ream (edreamleo) wrote :

Good work. This branch was merged into the trunk at rev 3295 of the trunk.
All expected unit tests pass.

I had to merge the two new unit tests for delete-word by hand, including the new @common node.

Revision history for this message
Edward K. Ream (edreamleo) wrote :

On Mon, Aug 30, 2010 at 11:11 AM, Edward K. Ream <email address hidden> wrote:

> Thanks for this.  I'll be testing your branch today and merging it if
> all seems good.

Merged at rev 3295 of the trunk. Thanks for this work.

Edward

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'leo/core/leoEditCommands.py'
--- leo/core/leoEditCommands.py 2010-08-28 01:11:11 +0000
+++ leo/core/leoEditCommands.py 2010-08-28 19:07:41 +0000
@@ -2690,12 +2690,16 @@
2690 from_pos,to_pos = w.getSelectionRange()2690 from_pos,to_pos = w.getSelectionRange()
2691 else:2691 else:
2692 from_pos = w.getInsertPoint()2692 from_pos = w.getInsertPoint()
2693 self.moveWordHelper(event=None,extend=False,forward=forward)2693 self.moveWordHelper(event,extend=False,forward=forward)
2694 to_pos = w.getInsertPoint()2694 to_pos = w.getInsertPoint()
26952695
2696 w.delete(from_pos, to_pos)2696 # For Tk GUI, make sure to_pos > from_pos
2697 if from_pos > to_pos:
2698 from_pos,to_pos = to_pos,from_pos
2699
2700 w.delete(from_pos,to_pos)
2697 c.frame.body.forceFullRecolor()2701 c.frame.body.forceFullRecolor()
2698 self.endCommand(changed=True, setLabel=True)2702 self.endCommand(changed=True,setLabel=True)
2699 #@+node:ekr.20050920084036.87: *4* deleteNextChar2703 #@+node:ekr.20050920084036.87: *4* deleteNextChar
2700 def deleteNextChar (self,event):2704 def deleteNextChar (self,event):
27012705
27022706
=== modified file 'leo/core/leoKeys.py'
--- leo/core/leoKeys.py 2010-07-07 13:44:43 +0000
+++ leo/core/leoKeys.py 2010-08-28 19:07:41 +0000
@@ -2966,7 +2966,11 @@
2966 g.app.gui.set_focus(c,w)2966 g.app.gui.set_focus(c,w)
2967 g.app.gui.event_generate(w,stroke)2967 g.app.gui.event_generate(w,stroke)
2968 else:2968 else:
2969 g.trace('no shortcut for %s' % (commandName),color='red')2969 message = 'no shortcut for %s' % (commandName)
2970 if g.app.unitTesting:
2971 raise AttributeError(message)
2972 else:
2973 g.trace(message,color='red')
2970 #@+node:ekr.20061031131434.127: *4* simulateCommand2974 #@+node:ekr.20061031131434.127: *4* simulateCommand
2971 def simulateCommand (self,commandName):2975 def simulateCommand (self,commandName):
29722976
29732977
=== modified file 'leo/plugins/qtGui.py'
--- leo/plugins/qtGui.py 2010-08-23 20:11:50 +0000
+++ leo/plugins/qtGui.py 2010-08-28 19:07:41 +0000
@@ -1488,7 +1488,7 @@
1488 def hasSelection(self):1488 def hasSelection(self):
14891489
1490 if self.check():1490 if self.check():
1491 return self.widget.hasSelection()1491 return self.widget.hasSelectedText()
1492 else:1492 else:
1493 return False1493 return False
1494 #@+node:ekr.20090603073641.3856: *5* see & seeInsertPoint1494 #@+node:ekr.20090603073641.3856: *5* see & seeInsertPoint
14951495
=== modified file 'leo/test/unitTest.leo'
--- leo/test/unitTest.leo 2010-08-28 01:11:11 +0000
+++ leo/test/unitTest.leo 2010-08-28 19:07:41 +0000
@@ -1535,6 +1535,9 @@
1535<v t="ekr.20100131171342.5593"><vh>@test ctors for all dialogs</vh></v>1535<v t="ekr.20100131171342.5593"><vh>@test ctors for all dialogs</vh></v>
1536</v>1536</v>
1537<v t="ekr.20071113192611"><vh>leoEditCommands</vh>1537<v t="ekr.20071113192611"><vh>leoEditCommands</vh>
1538<v t="samh.20100821003042.5877"><vh>@common leoEditCommands test code</vh>
1539<v t="samh.20100821015835.5881"><vh>runEditCommandTest</vh></v>
1540</v>
1538<v t="ekr.20100204165850.5371"><vh>Toggle commands</vh>1541<v t="ekr.20100204165850.5371"><vh>Toggle commands</vh>
1539<v t="ekr.20100119102849.5108"><vh>@test toggle-extend-mode</vh>1542<v t="ekr.20100119102849.5108"><vh>@test toggle-extend-mode</vh>
1540<v t="ekr.20100119102849.5109"><vh>&lt;&lt; define table &gt;&gt;</vh></v>1543<v t="ekr.20100119102849.5109"><vh>&lt;&lt; define table &gt;&gt;</vh></v>
@@ -1636,11 +1639,21 @@
1636<v t="ekr.20100817131738.5888"><vh>before sel=1.10,1.10</vh></v>1639<v t="ekr.20100817131738.5888"><vh>before sel=1.10,1.10</vh></v>
1637<v t="ekr.20100817131738.5889"><vh>after sel=1.5,1.5</vh></v>1640<v t="ekr.20100817131738.5889"><vh>after sel=1.5,1.5</vh></v>
1638</v>1641</v>
1642<v t="samh.20100821002818.5879"><vh>@test backward-delete-word (headline, no selection)</vh>
1643<v t="samh.20100821002818.5880"><vh>work</vh></v>
1644<v t="ekr.20100817131738.5888"></v>
1645<v t="ekr.20100817131738.5889"></v>
1646</v>
1639<v t="ekr.20100817131738.5894"><vh>@test backward-delete-word (selection)</vh>1647<v t="ekr.20100817131738.5894"><vh>@test backward-delete-word (selection)</vh>
1640<v t="ekr.20100817131738.5895"><vh>work</vh></v>1648<v t="ekr.20100817131738.5895"><vh>work</vh></v>
1641<v t="ekr.20100817131738.5896"><vh>before sel=1.7,1.12</vh></v>1649<v t="ekr.20100817131738.5896"><vh>before sel=1.7,1.12</vh></v>
1642<v t="ekr.20100817131738.5897"><vh>after sel=1.7,1.7</vh></v>1650<v t="ekr.20100817131738.5897"><vh>after sel=1.7,1.7</vh></v>
1643</v>1651</v>
1652<v t="samh.20100821030600.5887"><vh>@test backward-delete-word (headline, selection)</vh>
1653<v t="samh.20100821030600.5888"><vh>work</vh></v>
1654<v t="ekr.20100817131738.5896"></v>
1655<v t="ekr.20100817131738.5897"></v>
1656</v>
1644<v t="ekr.20061101121602.126"><vh>@test backward-kill-paragraph</vh>1657<v t="ekr.20061101121602.126"><vh>@test backward-kill-paragraph</vh>
1645<v t="ekr.20061101121602.127"><vh>work</vh></v>1658<v t="ekr.20061101121602.127"><vh>work</vh></v>
1646<v t="ekr.20061101121602.128"><vh>before sel=9.0,9.0</vh></v>1659<v t="ekr.20061101121602.128"><vh>before sel=9.0,9.0</vh></v>
@@ -2468,11 +2481,11 @@
2468<v t="ekr.20090529141856.4764"><vh>@test two functions (for comparison with unindent does not end function)</vh></v>2481<v t="ekr.20090529141856.4764"><vh>@test two functions (for comparison with unindent does not end function)</vh></v>
2469<v t="ekr.20090529141856.4765"><vh>@test unindent in triple string does not end function</vh></v>2482<v t="ekr.20090529141856.4765"><vh>@test unindent in triple string does not end function</vh></v>
2470</v>2483</v>
2471<v t="ekr.20090529141856.4780" a="E"><vh>xml tests</vh>2484<v t="ekr.20090529141856.4780"><vh>xml tests</vh>
2472<v t="ekr.20090529141856.4781"><vh>@test xml 1</vh></v>2485<v t="ekr.20090529141856.4781"><vh>@test xml 1</vh></v>
2473</v>2486</v>
2474</v>2487</v>
2475<v t="ekr.20090529141856.4784" a="E"><vh> Tests of @auto-rst</vh>2488<v t="ekr.20090529141856.4784"><vh> Tests of @auto-rst</vh>
2476<v t="ekr.20090529141856.4785"><vh>@test rST import test</vh></v>2489<v t="ekr.20090529141856.4785"><vh>@test rST import test</vh></v>
2477<v t="ekr.20090529141856.4786"><vh>@test rST import test (no double-underlines)</vh></v>2490<v t="ekr.20090529141856.4786"><vh>@test rST import test (no double-underlines)</vh></v>
2478<v t="ekr.20090529141856.4787"><vh>@test rST import test: long underlines</vh></v>2491<v t="ekr.20090529141856.4787"><vh>@test rST import test: long underlines</vh></v>
@@ -25098,16 +25111,21 @@
25098<t tx="ekr.20100817131738.5895">aaaa bbcc dddd</t>25111<t tx="ekr.20100817131738.5895">aaaa bbcc dddd</t>
25099<t tx="ekr.20100817131738.5896">aaaa bbbb cccc dddd</t>25112<t tx="ekr.20100817131738.5896">aaaa bbbb cccc dddd</t>
25100<t tx="ekr.20100817131738.5897">aaaa bbcc dddd</t>25113<t tx="ekr.20100817131738.5897">aaaa bbcc dddd</t>
25101<t tx="ekr.20100817131738.5902">import leo.core.leoTest as leoTest25114<t tx="ekr.20100817131738.5902">exec(g.findTestScript(c,'@common leoEditCommands test code'))
25102leoTest.runEditCommandTest(c,p)</t>25115runEditCommandTest(c,p,inHeadline=False)
25116runEditCommandTest(c,p,inHeadline=True)
25117</t>
25103<t tx="ekr.20100817131738.5903">aaaa bbbb dddd</t>25118<t tx="ekr.20100817131738.5903">aaaa bbbb dddd</t>
25104<t tx="ekr.20100817131738.5904">aaaa bbbb cccc dddd</t>25119<t tx="ekr.20100817131738.5904">aaaa bbbb cccc dddd</t>
25105<t tx="ekr.20100817131738.5905">aaaa bbbb dddd</t>25120<t tx="ekr.20100817131738.5905">aaaa bbbb dddd</t>
25106<t tx="ekr.20100818073344.5910">import leo.core.leoTest as leoTest25121<t tx="ekr.20100818073344.5910">exec(g.findTestScript(c,'@common leoEditCommands test code'))
25107leoTest.runEditCommandTest(c,p)</t>25122runEditCommandTest(c,p,inHeadline=False)
25123runEditCommandTest(c,p,inHeadline=True)
25124</t>
25108<t tx="ekr.20100818073344.5911">aaaa bbcc dddd</t>25125<t tx="ekr.20100818073344.5911">aaaa bbcc dddd</t>
25109<t tx="ekr.20100818073344.5912">aaaa bbbb cccc dddd</t>25126<t tx="ekr.20100818073344.5912">aaaa bbbb cccc dddd</t>
25110<t tx="ekr.20100818073344.5913">aaaa bbcc dddd</t>25127<t tx="ekr.20100818073344.5913">aaaa bbcc dddd</t>
25128<<<<<<< TREE
25111<t tx="ekr.20100827140832.5913">exec(g.findTestScript(c,'@common leoRst test code'))25129<t tx="ekr.20100827140832.5913">exec(g.findTestScript(c,'@common leoRst test code'))
25112rst3Test(c,p)25130rst3Test(c,p)
25113</t>25131</t>
@@ -26883,6 +26901,113 @@
26883 print ('%3d %s' % (i,repr(expected_lines[i])))26901 print ('%3d %s' % (i,repr(expected_lines[i])))
26884 print ('%3d %s' % (i,repr(got_lines[i])))26902 print ('%3d %s' % (i,repr(got_lines[i])))
26885 if expected_lines[i] != got_lines[i]: break</t>26903 if expected_lines[i] != got_lines[i]: break</t>
26904=======
26905<t tx="samh.20100821002818.5879">exec(g.findTestScript(c,'@common leoEditCommands test code'))
26906runEditCommandTest(c,p,inHeadline=True)
26907</t>
26908<t tx="samh.20100821002818.5880"></t>
26909<t tx="samh.20100821003042.5877">@others</t>
26910<t tx="samh.20100821015835.5881">import leo.core.leoTest as leoTest
26911
26912@
26913This is an updated version of leo.core.leoTest.runEditCommandTest,
26914moved here to take advantage of EKR's new common-test-code-sharing
26915mechanism. It should be okay to delete the old code and replace
26916all uses with:
26917
26918 exec(g.findTestScript(c,'@common leoEditCommands test code'))
26919 runEditCommandTest(c,p)
26920@c
26921
26922def runEditCommandTest (c,p,inHeadline=False):
26923 '''
26924 This is a helper for testing edit commands. It takes the name of the
26925 command from the title of the test and the before and after conditions
26926 from child nodes.
26927
26928 :param inHeadline: if True, tests the command in the headline; if False,
26929 tests the command in the body.
26930 '''
26931
26932 u = leoTest.testUtils(c) ; atTest = p.copy()
26933
26934 h = atTest.h
26935 assert h.startswith('@test '),'expected head: %s, got: %s' % ('@test',h)
26936 commandName = h[6:].strip()
26937 # Ignore everything after the actual command name.
26938 i = g.skip_id(commandName, 0, chars='-')
26939 commandName = commandName[:i]
26940 assert commandName, 'empty command name'
26941 command = c.commandsDict.get(commandName)
26942 assert command, 'no command: %s' % (commandName)
26943
26944 work,before,after = u.findChildrenOf(atTest)
26945 before_h = 'before sel='
26946 after_h = 'after sel='
26947 for node,h in ((work,'work'),(before,before_h),(after,after_h)):
26948 h2 = node.h
26949 assert h2.startswith(h),'expected head: %s, got: %s' % (h,h2)
26950
26951 sels = []
26952 for node,h in ((before,before_h),(after,after_h)):
26953 sel = node.h[len(h):].strip()
26954 aList = [str(z) for z in sel.split(',')]
26955 sels.append(tuple(aList))
26956 sel1,sel2 = sels
26957 #g.trace(repr(sels))
26958
26959 c.selectPosition(work)
26960
26961 if inHeadline:
26962 c.setHeadString(work,before.b)
26963 # To make the node visible, and edit the label
26964 c.redrawAndEdit(work)
26965 w = c.edit_widget(work)
26966 g.app.gui.set_focus(c,w)
26967 else:
26968 w = c.frame.body.bodyCtrl
26969 c.setBodyString(work,before.b)
26970
26971 try:
26972 #g.trace(repr(sel1[0]),repr(sel1[1]))
26973 w.setSelectionRange(sel1[0],sel1[1],insert=sel1[1])
26974 if inHeadline:
26975 # simulateCommand doesn't seem to work when editing a headline
26976 c.k.manufactureKeyPressForCommandName(w,commandName)
26977 else:
26978 c.k.simulateCommand(commandName)
26979
26980 # Exit headline-editing mode
26981 if inHeadline: w.event_generate('&lt;Return&gt;')
26982
26983 location = 'headline' if inHeadline else 'body'
26984 s1 = work.h if inHeadline else work.b
26985 s2 = after.b
26986
26987 assert s1 == s2, 'mismatch in %s\nexpected: %s\n got: %s' % (location,repr(s2),repr(s1))
26988 sel3 = w.getSelectionRange()
26989 ins = w.toGuiIndex(w.getInsertPoint())
26990 #g.trace('ins',ins,'s1[j:...]',repr(s1[j:j+10]))
26991 # Convert both selection ranges to gui indices.
26992 sel2_orig = sel2
26993 # g.trace(w)
26994 assert len(sel2) == 2,'Bad headline index. Expected index,index. got: %s' % sel2
26995 i,j = sel2 ; sel2 = w.toGuiIndex(i),w.toGuiIndex(j)
26996 assert len(sel3) == 2,'Bad headline index. Expected index,index. got: %s' % sel3
26997 i,j = sel3 ; sel3 = w.toGuiIndex(i),w.toGuiIndex(j)
26998 assert sel2 == sel3, 'mismatch in sel\nexpected: %s = %s, got: %s' % (sel2_orig,sel2,sel3)
26999 c.selectPosition(atTest)
27000 atTest.contract()
27001 # Don't redraw.
27002 finally:
27003 # Make sure to restore the headline so it can be used for future tests
27004 if inHeadline:
27005 c.setHeadString(work,'work')
27006</t>
27007<t tx="samh.20100821030600.5887">exec(g.findTestScript(c,'@common leoEditCommands test code'))
27008runEditCommandTest(c,p,inHeadline=True)</t>
27009<t tx="samh.20100821030600.5888"></t>
27010>>>>>>> MERGE-SOURCE
26886<t tx="sps.20100531034136.20110">p2 = p.firstChild().firstChild().firstChild()27011<t tx="sps.20100531034136.20110">p2 = p.firstChild().firstChild().firstChild()
2688727012
26888aList = g.get_directives_dict_list(p2)27013aList = g.get_directives_dict_list(p2)

Subscribers

People subscribed via source and target branches

to status/vote changes: