Merge lp:~samh/leo-editor/delete-word into lp:leo-editor/old-trunk
- delete-word
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Edward K. Ream | Pending | ||
Review via email: mp+34001@code.launchpad.net |
Commit message
Description of the change
The first revision fixes delete-word / backward-
The third is to help with unit tests, and the 4th adds some header unit tests for [backward-
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).
Edward K. Ream (edreamleo) wrote : | # |
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.
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
1 | === modified file 'leo/core/leoEditCommands.py' | |||
2 | --- leo/core/leoEditCommands.py 2010-08-28 01:11:11 +0000 | |||
3 | +++ leo/core/leoEditCommands.py 2010-08-28 19:07:41 +0000 | |||
4 | @@ -2690,12 +2690,16 @@ | |||
5 | 2690 | from_pos,to_pos = w.getSelectionRange() | 2690 | from_pos,to_pos = w.getSelectionRange() |
6 | 2691 | else: | 2691 | else: |
7 | 2692 | from_pos = w.getInsertPoint() | 2692 | from_pos = w.getInsertPoint() |
9 | 2693 | self.moveWordHelper(event=None,extend=False,forward=forward) | 2693 | self.moveWordHelper(event,extend=False,forward=forward) |
10 | 2694 | to_pos = w.getInsertPoint() | 2694 | to_pos = w.getInsertPoint() |
11 | 2695 | 2695 | ||
13 | 2696 | w.delete(from_pos, to_pos) | 2696 | # For Tk GUI, make sure to_pos > from_pos |
14 | 2697 | if from_pos > to_pos: | ||
15 | 2698 | from_pos,to_pos = to_pos,from_pos | ||
16 | 2699 | |||
17 | 2700 | w.delete(from_pos,to_pos) | ||
18 | 2697 | c.frame.body.forceFullRecolor() | 2701 | c.frame.body.forceFullRecolor() |
20 | 2698 | self.endCommand(changed=True, setLabel=True) | 2702 | self.endCommand(changed=True,setLabel=True) |
21 | 2699 | #@+node:ekr.20050920084036.87: *4* deleteNextChar | 2703 | #@+node:ekr.20050920084036.87: *4* deleteNextChar |
22 | 2700 | def deleteNextChar (self,event): | 2704 | def deleteNextChar (self,event): |
23 | 2701 | 2705 | ||
24 | 2702 | 2706 | ||
25 | === modified file 'leo/core/leoKeys.py' | |||
26 | --- leo/core/leoKeys.py 2010-07-07 13:44:43 +0000 | |||
27 | +++ leo/core/leoKeys.py 2010-08-28 19:07:41 +0000 | |||
28 | @@ -2966,7 +2966,11 @@ | |||
29 | 2966 | g.app.gui.set_focus(c,w) | 2966 | g.app.gui.set_focus(c,w) |
30 | 2967 | g.app.gui.event_generate(w,stroke) | 2967 | g.app.gui.event_generate(w,stroke) |
31 | 2968 | else: | 2968 | else: |
33 | 2969 | g.trace('no shortcut for %s' % (commandName),color='red') | 2969 | message = 'no shortcut for %s' % (commandName) |
34 | 2970 | if g.app.unitTesting: | ||
35 | 2971 | raise AttributeError(message) | ||
36 | 2972 | else: | ||
37 | 2973 | g.trace(message,color='red') | ||
38 | 2970 | #@+node:ekr.20061031131434.127: *4* simulateCommand | 2974 | #@+node:ekr.20061031131434.127: *4* simulateCommand |
39 | 2971 | def simulateCommand (self,commandName): | 2975 | def simulateCommand (self,commandName): |
40 | 2972 | 2976 | ||
41 | 2973 | 2977 | ||
42 | === modified file 'leo/plugins/qtGui.py' | |||
43 | --- leo/plugins/qtGui.py 2010-08-23 20:11:50 +0000 | |||
44 | +++ leo/plugins/qtGui.py 2010-08-28 19:07:41 +0000 | |||
45 | @@ -1488,7 +1488,7 @@ | |||
46 | 1488 | def hasSelection(self): | 1488 | def hasSelection(self): |
47 | 1489 | 1489 | ||
48 | 1490 | if self.check(): | 1490 | if self.check(): |
50 | 1491 | return self.widget.hasSelection() | 1491 | return self.widget.hasSelectedText() |
51 | 1492 | else: | 1492 | else: |
52 | 1493 | return False | 1493 | return False |
53 | 1494 | #@+node:ekr.20090603073641.3856: *5* see & seeInsertPoint | 1494 | #@+node:ekr.20090603073641.3856: *5* see & seeInsertPoint |
54 | 1495 | 1495 | ||
55 | === modified file 'leo/test/unitTest.leo' | |||
56 | --- leo/test/unitTest.leo 2010-08-28 01:11:11 +0000 | |||
57 | +++ leo/test/unitTest.leo 2010-08-28 19:07:41 +0000 | |||
58 | @@ -1535,6 +1535,9 @@ | |||
59 | 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> |
60 | 1536 | </v> | 1536 | </v> |
61 | 1537 | <v t="ekr.20071113192611"><vh>leoEditCommands</vh> | 1537 | <v t="ekr.20071113192611"><vh>leoEditCommands</vh> |
62 | 1538 | <v t="samh.20100821003042.5877"><vh>@common leoEditCommands test code</vh> | ||
63 | 1539 | <v t="samh.20100821015835.5881"><vh>runEditCommandTest</vh></v> | ||
64 | 1540 | </v> | ||
65 | 1538 | <v t="ekr.20100204165850.5371"><vh>Toggle commands</vh> | 1541 | <v t="ekr.20100204165850.5371"><vh>Toggle commands</vh> |
66 | 1539 | <v t="ekr.20100119102849.5108"><vh>@test toggle-extend-mode</vh> | 1542 | <v t="ekr.20100119102849.5108"><vh>@test toggle-extend-mode</vh> |
67 | 1540 | <v t="ekr.20100119102849.5109"><vh><< define table >></vh></v> | 1543 | <v t="ekr.20100119102849.5109"><vh><< define table >></vh></v> |
68 | @@ -1636,11 +1639,21 @@ | |||
69 | 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> |
70 | 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> |
71 | 1638 | </v> | 1641 | </v> |
72 | 1642 | <v t="samh.20100821002818.5879"><vh>@test backward-delete-word (headline, no selection)</vh> | ||
73 | 1643 | <v t="samh.20100821002818.5880"><vh>work</vh></v> | ||
74 | 1644 | <v t="ekr.20100817131738.5888"></v> | ||
75 | 1645 | <v t="ekr.20100817131738.5889"></v> | ||
76 | 1646 | </v> | ||
77 | 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> |
78 | 1640 | <v t="ekr.20100817131738.5895"><vh>work</vh></v> | 1648 | <v t="ekr.20100817131738.5895"><vh>work</vh></v> |
79 | 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> |
80 | 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> |
81 | 1643 | </v> | 1651 | </v> |
82 | 1652 | <v t="samh.20100821030600.5887"><vh>@test backward-delete-word (headline, selection)</vh> | ||
83 | 1653 | <v t="samh.20100821030600.5888"><vh>work</vh></v> | ||
84 | 1654 | <v t="ekr.20100817131738.5896"></v> | ||
85 | 1655 | <v t="ekr.20100817131738.5897"></v> | ||
86 | 1656 | </v> | ||
87 | 1644 | <v t="ekr.20061101121602.126"><vh>@test backward-kill-paragraph</vh> | 1657 | <v t="ekr.20061101121602.126"><vh>@test backward-kill-paragraph</vh> |
88 | 1645 | <v t="ekr.20061101121602.127"><vh>work</vh></v> | 1658 | <v t="ekr.20061101121602.127"><vh>work</vh></v> |
89 | 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> |
90 | @@ -2468,11 +2481,11 @@ | |||
91 | 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> |
92 | 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> |
93 | 2470 | </v> | 2483 | </v> |
95 | 2471 | <v t="ekr.20090529141856.4780" a="E"><vh>xml tests</vh> | 2484 | <v t="ekr.20090529141856.4780"><vh>xml tests</vh> |
96 | 2472 | <v t="ekr.20090529141856.4781"><vh>@test xml 1</vh></v> | 2485 | <v t="ekr.20090529141856.4781"><vh>@test xml 1</vh></v> |
97 | 2473 | </v> | 2486 | </v> |
98 | 2474 | </v> | 2487 | </v> |
100 | 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> |
101 | 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> |
102 | 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> |
103 | 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> |
104 | @@ -25098,16 +25111,21 @@ | |||
105 | 25098 | <t tx="ekr.20100817131738.5895">aaaa bbcc dddd</t> | 25111 | <t tx="ekr.20100817131738.5895">aaaa bbcc dddd</t> |
106 | 25099 | <t tx="ekr.20100817131738.5896">aaaa bbbb cccc dddd</t> | 25112 | <t tx="ekr.20100817131738.5896">aaaa bbbb cccc dddd</t> |
107 | 25100 | <t tx="ekr.20100817131738.5897">aaaa bbcc dddd</t> | 25113 | <t tx="ekr.20100817131738.5897">aaaa bbcc dddd</t> |
110 | 25101 | <t tx="ekr.20100817131738.5902">import leo.core.leoTest as leoTest | 25114 | <t tx="ekr.20100817131738.5902">exec(g.findTestScript(c,'@common leoEditCommands test code')) |
111 | 25102 | leoTest.runEditCommandTest(c,p)</t> | 25115 | runEditCommandTest(c,p,inHeadline=False) |
112 | 25116 | runEditCommandTest(c,p,inHeadline=True) | ||
113 | 25117 | </t> | ||
114 | 25103 | <t tx="ekr.20100817131738.5903">aaaa bbbb dddd</t> | 25118 | <t tx="ekr.20100817131738.5903">aaaa bbbb dddd</t> |
115 | 25104 | <t tx="ekr.20100817131738.5904">aaaa bbbb cccc dddd</t> | 25119 | <t tx="ekr.20100817131738.5904">aaaa bbbb cccc dddd</t> |
116 | 25105 | <t tx="ekr.20100817131738.5905">aaaa bbbb dddd</t> | 25120 | <t tx="ekr.20100817131738.5905">aaaa bbbb dddd</t> |
119 | 25106 | <t tx="ekr.20100818073344.5910">import leo.core.leoTest as leoTest | 25121 | <t tx="ekr.20100818073344.5910">exec(g.findTestScript(c,'@common leoEditCommands test code')) |
120 | 25107 | leoTest.runEditCommandTest(c,p)</t> | 25122 | runEditCommandTest(c,p,inHeadline=False) |
121 | 25123 | runEditCommandTest(c,p,inHeadline=True) | ||
122 | 25124 | </t> | ||
123 | 25108 | <t tx="ekr.20100818073344.5911">aaaa bbcc dddd</t> | 25125 | <t tx="ekr.20100818073344.5911">aaaa bbcc dddd</t> |
124 | 25109 | <t tx="ekr.20100818073344.5912">aaaa bbbb cccc dddd</t> | 25126 | <t tx="ekr.20100818073344.5912">aaaa bbbb cccc dddd</t> |
125 | 25110 | <t tx="ekr.20100818073344.5913">aaaa bbcc dddd</t> | 25127 | <t tx="ekr.20100818073344.5913">aaaa bbcc dddd</t> |
126 | 25128 | <<<<<<< TREE | ||
127 | 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')) |
128 | 25112 | rst3Test(c,p) | 25130 | rst3Test(c,p) |
129 | 25113 | </t> | 25131 | </t> |
130 | @@ -26883,6 +26901,113 @@ | |||
131 | 26883 | print ('%3d %s' % (i,repr(expected_lines[i]))) | 26901 | print ('%3d %s' % (i,repr(expected_lines[i]))) |
132 | 26884 | print ('%3d %s' % (i,repr(got_lines[i]))) | 26902 | print ('%3d %s' % (i,repr(got_lines[i]))) |
133 | 26885 | if expected_lines[i] != got_lines[i]: break</t> | 26903 | if expected_lines[i] != got_lines[i]: break</t> |
134 | 26904 | ======= | ||
135 | 26905 | <t tx="samh.20100821002818.5879">exec(g.findTestScript(c,'@common leoEditCommands test code')) | ||
136 | 26906 | runEditCommandTest(c,p,inHeadline=True) | ||
137 | 26907 | </t> | ||
138 | 26908 | <t tx="samh.20100821002818.5880"></t> | ||
139 | 26909 | <t tx="samh.20100821003042.5877">@others</t> | ||
140 | 26910 | <t tx="samh.20100821015835.5881">import leo.core.leoTest as leoTest | ||
141 | 26911 | |||
142 | 26912 | @ | ||
143 | 26913 | This is an updated version of leo.core.leoTest.runEditCommandTest, | ||
144 | 26914 | moved here to take advantage of EKR's new common-test-code-sharing | ||
145 | 26915 | mechanism. It should be okay to delete the old code and replace | ||
146 | 26916 | all uses with: | ||
147 | 26917 | |||
148 | 26918 | exec(g.findTestScript(c,'@common leoEditCommands test code')) | ||
149 | 26919 | runEditCommandTest(c,p) | ||
150 | 26920 | @c | ||
151 | 26921 | |||
152 | 26922 | def runEditCommandTest (c,p,inHeadline=False): | ||
153 | 26923 | ''' | ||
154 | 26924 | This is a helper for testing edit commands. It takes the name of the | ||
155 | 26925 | command from the title of the test and the before and after conditions | ||
156 | 26926 | from child nodes. | ||
157 | 26927 | |||
158 | 26928 | :param inHeadline: if True, tests the command in the headline; if False, | ||
159 | 26929 | tests the command in the body. | ||
160 | 26930 | ''' | ||
161 | 26931 | |||
162 | 26932 | u = leoTest.testUtils(c) ; atTest = p.copy() | ||
163 | 26933 | |||
164 | 26934 | h = atTest.h | ||
165 | 26935 | assert h.startswith('@test '),'expected head: %s, got: %s' % ('@test',h) | ||
166 | 26936 | commandName = h[6:].strip() | ||
167 | 26937 | # Ignore everything after the actual command name. | ||
168 | 26938 | i = g.skip_id(commandName, 0, chars='-') | ||
169 | 26939 | commandName = commandName[:i] | ||
170 | 26940 | assert commandName, 'empty command name' | ||
171 | 26941 | command = c.commandsDict.get(commandName) | ||
172 | 26942 | assert command, 'no command: %s' % (commandName) | ||
173 | 26943 | |||
174 | 26944 | work,before,after = u.findChildrenOf(atTest) | ||
175 | 26945 | before_h = 'before sel=' | ||
176 | 26946 | after_h = 'after sel=' | ||
177 | 26947 | for node,h in ((work,'work'),(before,before_h),(after,after_h)): | ||
178 | 26948 | h2 = node.h | ||
179 | 26949 | assert h2.startswith(h),'expected head: %s, got: %s' % (h,h2) | ||
180 | 26950 | |||
181 | 26951 | sels = [] | ||
182 | 26952 | for node,h in ((before,before_h),(after,after_h)): | ||
183 | 26953 | sel = node.h[len(h):].strip() | ||
184 | 26954 | aList = [str(z) for z in sel.split(',')] | ||
185 | 26955 | sels.append(tuple(aList)) | ||
186 | 26956 | sel1,sel2 = sels | ||
187 | 26957 | #g.trace(repr(sels)) | ||
188 | 26958 | |||
189 | 26959 | c.selectPosition(work) | ||
190 | 26960 | |||
191 | 26961 | if inHeadline: | ||
192 | 26962 | c.setHeadString(work,before.b) | ||
193 | 26963 | # To make the node visible, and edit the label | ||
194 | 26964 | c.redrawAndEdit(work) | ||
195 | 26965 | w = c.edit_widget(work) | ||
196 | 26966 | g.app.gui.set_focus(c,w) | ||
197 | 26967 | else: | ||
198 | 26968 | w = c.frame.body.bodyCtrl | ||
199 | 26969 | c.setBodyString(work,before.b) | ||
200 | 26970 | |||
201 | 26971 | try: | ||
202 | 26972 | #g.trace(repr(sel1[0]),repr(sel1[1])) | ||
203 | 26973 | w.setSelectionRange(sel1[0],sel1[1],insert=sel1[1]) | ||
204 | 26974 | if inHeadline: | ||
205 | 26975 | # simulateCommand doesn't seem to work when editing a headline | ||
206 | 26976 | c.k.manufactureKeyPressForCommandName(w,commandName) | ||
207 | 26977 | else: | ||
208 | 26978 | c.k.simulateCommand(commandName) | ||
209 | 26979 | |||
210 | 26980 | # Exit headline-editing mode | ||
211 | 26981 | if inHeadline: w.event_generate('<Return>') | ||
212 | 26982 | |||
213 | 26983 | location = 'headline' if inHeadline else 'body' | ||
214 | 26984 | s1 = work.h if inHeadline else work.b | ||
215 | 26985 | s2 = after.b | ||
216 | 26986 | |||
217 | 26987 | assert s1 == s2, 'mismatch in %s\nexpected: %s\n got: %s' % (location,repr(s2),repr(s1)) | ||
218 | 26988 | sel3 = w.getSelectionRange() | ||
219 | 26989 | ins = w.toGuiIndex(w.getInsertPoint()) | ||
220 | 26990 | #g.trace('ins',ins,'s1[j:...]',repr(s1[j:j+10])) | ||
221 | 26991 | # Convert both selection ranges to gui indices. | ||
222 | 26992 | sel2_orig = sel2 | ||
223 | 26993 | # g.trace(w) | ||
224 | 26994 | assert len(sel2) == 2,'Bad headline index. Expected index,index. got: %s' % sel2 | ||
225 | 26995 | i,j = sel2 ; sel2 = w.toGuiIndex(i),w.toGuiIndex(j) | ||
226 | 26996 | assert len(sel3) == 2,'Bad headline index. Expected index,index. got: %s' % sel3 | ||
227 | 26997 | i,j = sel3 ; sel3 = w.toGuiIndex(i),w.toGuiIndex(j) | ||
228 | 26998 | assert sel2 == sel3, 'mismatch in sel\nexpected: %s = %s, got: %s' % (sel2_orig,sel2,sel3) | ||
229 | 26999 | c.selectPosition(atTest) | ||
230 | 27000 | atTest.contract() | ||
231 | 27001 | # Don't redraw. | ||
232 | 27002 | finally: | ||
233 | 27003 | # Make sure to restore the headline so it can be used for future tests | ||
234 | 27004 | if inHeadline: | ||
235 | 27005 | c.setHeadString(work,'work') | ||
236 | 27006 | </t> | ||
237 | 27007 | <t tx="samh.20100821030600.5887">exec(g.findTestScript(c,'@common leoEditCommands test code')) | ||
238 | 27008 | runEditCommandTest(c,p,inHeadline=True)</t> | ||
239 | 27009 | <t tx="samh.20100821030600.5888"></t> | ||
240 | 27010 | >>>>>>> MERGE-SOURCE | ||
241 | 26886 | <t tx="sps.20100531034136.20110">p2 = p.firstChild().firstChild().firstChild() | 27011 | <t tx="sps.20100531034136.20110">p2 = p.firstChild().firstChild().firstChild() |
242 | 26887 | 27012 | ||
243 | 26888 | aList = g.get_directives_dict_list(p2) | 27013 | aList = g.get_directives_dict_list(p2) |
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. ]delete- word.
>
> The third is to help with unit tests, and the 4th adds some header unit tests for [backward-
Thanks for this. I'll be testing your branch today and merging it if
all seems good.
Edward