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
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 from_pos,to_pos = w.getSelectionRange()
6 else:
7 from_pos = w.getInsertPoint()
8- self.moveWordHelper(event=None,extend=False,forward=forward)
9+ self.moveWordHelper(event,extend=False,forward=forward)
10 to_pos = w.getInsertPoint()
11
12- w.delete(from_pos, to_pos)
13+ # For Tk GUI, make sure to_pos > from_pos
14+ if from_pos > to_pos:
15+ from_pos,to_pos = to_pos,from_pos
16+
17+ w.delete(from_pos,to_pos)
18 c.frame.body.forceFullRecolor()
19- self.endCommand(changed=True, setLabel=True)
20+ self.endCommand(changed=True,setLabel=True)
21 #@+node:ekr.20050920084036.87: *4* deleteNextChar
22 def deleteNextChar (self,event):
23
24
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 g.app.gui.set_focus(c,w)
30 g.app.gui.event_generate(w,stroke)
31 else:
32- g.trace('no shortcut for %s' % (commandName),color='red')
33+ message = 'no shortcut for %s' % (commandName)
34+ if g.app.unitTesting:
35+ raise AttributeError(message)
36+ else:
37+ g.trace(message,color='red')
38 #@+node:ekr.20061031131434.127: *4* simulateCommand
39 def simulateCommand (self,commandName):
40
41
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 def hasSelection(self):
47
48 if self.check():
49- return self.widget.hasSelection()
50+ return self.widget.hasSelectedText()
51 else:
52 return False
53 #@+node:ekr.20090603073641.3856: *5* see & seeInsertPoint
54
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 <v t="ekr.20100131171342.5593"><vh>@test ctors for all dialogs</vh></v>
60 </v>
61 <v t="ekr.20071113192611"><vh>leoEditCommands</vh>
62+<v t="samh.20100821003042.5877"><vh>@common leoEditCommands test code</vh>
63+<v t="samh.20100821015835.5881"><vh>runEditCommandTest</vh></v>
64+</v>
65 <v t="ekr.20100204165850.5371"><vh>Toggle commands</vh>
66 <v t="ekr.20100119102849.5108"><vh>@test toggle-extend-mode</vh>
67 <v t="ekr.20100119102849.5109"><vh>&lt;&lt; define table &gt;&gt;</vh></v>
68@@ -1636,11 +1639,21 @@
69 <v t="ekr.20100817131738.5888"><vh>before sel=1.10,1.10</vh></v>
70 <v t="ekr.20100817131738.5889"><vh>after sel=1.5,1.5</vh></v>
71 </v>
72+<v t="samh.20100821002818.5879"><vh>@test backward-delete-word (headline, no selection)</vh>
73+<v t="samh.20100821002818.5880"><vh>work</vh></v>
74+<v t="ekr.20100817131738.5888"></v>
75+<v t="ekr.20100817131738.5889"></v>
76+</v>
77 <v t="ekr.20100817131738.5894"><vh>@test backward-delete-word (selection)</vh>
78 <v t="ekr.20100817131738.5895"><vh>work</vh></v>
79 <v t="ekr.20100817131738.5896"><vh>before sel=1.7,1.12</vh></v>
80 <v t="ekr.20100817131738.5897"><vh>after sel=1.7,1.7</vh></v>
81 </v>
82+<v t="samh.20100821030600.5887"><vh>@test backward-delete-word (headline, selection)</vh>
83+<v t="samh.20100821030600.5888"><vh>work</vh></v>
84+<v t="ekr.20100817131738.5896"></v>
85+<v t="ekr.20100817131738.5897"></v>
86+</v>
87 <v t="ekr.20061101121602.126"><vh>@test backward-kill-paragraph</vh>
88 <v t="ekr.20061101121602.127"><vh>work</vh></v>
89 <v t="ekr.20061101121602.128"><vh>before sel=9.0,9.0</vh></v>
90@@ -2468,11 +2481,11 @@
91 <v t="ekr.20090529141856.4764"><vh>@test two functions (for comparison with unindent does not end function)</vh></v>
92 <v t="ekr.20090529141856.4765"><vh>@test unindent in triple string does not end function</vh></v>
93 </v>
94-<v t="ekr.20090529141856.4780" a="E"><vh>xml tests</vh>
95+<v t="ekr.20090529141856.4780"><vh>xml tests</vh>
96 <v t="ekr.20090529141856.4781"><vh>@test xml 1</vh></v>
97 </v>
98 </v>
99-<v t="ekr.20090529141856.4784" a="E"><vh> Tests of @auto-rst</vh>
100+<v t="ekr.20090529141856.4784"><vh> Tests of @auto-rst</vh>
101 <v t="ekr.20090529141856.4785"><vh>@test rST import test</vh></v>
102 <v t="ekr.20090529141856.4786"><vh>@test rST import test (no double-underlines)</vh></v>
103 <v t="ekr.20090529141856.4787"><vh>@test rST import test: long underlines</vh></v>
104@@ -25098,16 +25111,21 @@
105 <t tx="ekr.20100817131738.5895">aaaa bbcc dddd</t>
106 <t tx="ekr.20100817131738.5896">aaaa bbbb cccc dddd</t>
107 <t tx="ekr.20100817131738.5897">aaaa bbcc dddd</t>
108-<t tx="ekr.20100817131738.5902">import leo.core.leoTest as leoTest
109-leoTest.runEditCommandTest(c,p)</t>
110+<t tx="ekr.20100817131738.5902">exec(g.findTestScript(c,'@common leoEditCommands test code'))
111+runEditCommandTest(c,p,inHeadline=False)
112+runEditCommandTest(c,p,inHeadline=True)
113+</t>
114 <t tx="ekr.20100817131738.5903">aaaa bbbb dddd</t>
115 <t tx="ekr.20100817131738.5904">aaaa bbbb cccc dddd</t>
116 <t tx="ekr.20100817131738.5905">aaaa bbbb dddd</t>
117-<t tx="ekr.20100818073344.5910">import leo.core.leoTest as leoTest
118-leoTest.runEditCommandTest(c,p)</t>
119+<t tx="ekr.20100818073344.5910">exec(g.findTestScript(c,'@common leoEditCommands test code'))
120+runEditCommandTest(c,p,inHeadline=False)
121+runEditCommandTest(c,p,inHeadline=True)
122+</t>
123 <t tx="ekr.20100818073344.5911">aaaa bbcc dddd</t>
124 <t tx="ekr.20100818073344.5912">aaaa bbbb cccc dddd</t>
125 <t tx="ekr.20100818073344.5913">aaaa bbcc dddd</t>
126+<<<<<<< TREE
127 <t tx="ekr.20100827140832.5913">exec(g.findTestScript(c,'@common leoRst test code'))
128 rst3Test(c,p)
129 </t>
130@@ -26883,6 +26901,113 @@
131 print ('%3d %s' % (i,repr(expected_lines[i])))
132 print ('%3d %s' % (i,repr(got_lines[i])))
133 if expected_lines[i] != got_lines[i]: break</t>
134+=======
135+<t tx="samh.20100821002818.5879">exec(g.findTestScript(c,'@common leoEditCommands test code'))
136+runEditCommandTest(c,p,inHeadline=True)
137+</t>
138+<t tx="samh.20100821002818.5880"></t>
139+<t tx="samh.20100821003042.5877">@others</t>
140+<t tx="samh.20100821015835.5881">import leo.core.leoTest as leoTest
141+
142+@
143+This is an updated version of leo.core.leoTest.runEditCommandTest,
144+moved here to take advantage of EKR's new common-test-code-sharing
145+mechanism. It should be okay to delete the old code and replace
146+all uses with:
147+
148+ exec(g.findTestScript(c,'@common leoEditCommands test code'))
149+ runEditCommandTest(c,p)
150+@c
151+
152+def runEditCommandTest (c,p,inHeadline=False):
153+ '''
154+ This is a helper for testing edit commands. It takes the name of the
155+ command from the title of the test and the before and after conditions
156+ from child nodes.
157+
158+ :param inHeadline: if True, tests the command in the headline; if False,
159+ tests the command in the body.
160+ '''
161+
162+ u = leoTest.testUtils(c) ; atTest = p.copy()
163+
164+ h = atTest.h
165+ assert h.startswith('@test '),'expected head: %s, got: %s' % ('@test',h)
166+ commandName = h[6:].strip()
167+ # Ignore everything after the actual command name.
168+ i = g.skip_id(commandName, 0, chars='-')
169+ commandName = commandName[:i]
170+ assert commandName, 'empty command name'
171+ command = c.commandsDict.get(commandName)
172+ assert command, 'no command: %s' % (commandName)
173+
174+ work,before,after = u.findChildrenOf(atTest)
175+ before_h = 'before sel='
176+ after_h = 'after sel='
177+ for node,h in ((work,'work'),(before,before_h),(after,after_h)):
178+ h2 = node.h
179+ assert h2.startswith(h),'expected head: %s, got: %s' % (h,h2)
180+
181+ sels = []
182+ for node,h in ((before,before_h),(after,after_h)):
183+ sel = node.h[len(h):].strip()
184+ aList = [str(z) for z in sel.split(',')]
185+ sels.append(tuple(aList))
186+ sel1,sel2 = sels
187+ #g.trace(repr(sels))
188+
189+ c.selectPosition(work)
190+
191+ if inHeadline:
192+ c.setHeadString(work,before.b)
193+ # To make the node visible, and edit the label
194+ c.redrawAndEdit(work)
195+ w = c.edit_widget(work)
196+ g.app.gui.set_focus(c,w)
197+ else:
198+ w = c.frame.body.bodyCtrl
199+ c.setBodyString(work,before.b)
200+
201+ try:
202+ #g.trace(repr(sel1[0]),repr(sel1[1]))
203+ w.setSelectionRange(sel1[0],sel1[1],insert=sel1[1])
204+ if inHeadline:
205+ # simulateCommand doesn't seem to work when editing a headline
206+ c.k.manufactureKeyPressForCommandName(w,commandName)
207+ else:
208+ c.k.simulateCommand(commandName)
209+
210+ # Exit headline-editing mode
211+ if inHeadline: w.event_generate('&lt;Return&gt;')
212+
213+ location = 'headline' if inHeadline else 'body'
214+ s1 = work.h if inHeadline else work.b
215+ s2 = after.b
216+
217+ assert s1 == s2, 'mismatch in %s\nexpected: %s\n got: %s' % (location,repr(s2),repr(s1))
218+ sel3 = w.getSelectionRange()
219+ ins = w.toGuiIndex(w.getInsertPoint())
220+ #g.trace('ins',ins,'s1[j:...]',repr(s1[j:j+10]))
221+ # Convert both selection ranges to gui indices.
222+ sel2_orig = sel2
223+ # g.trace(w)
224+ assert len(sel2) == 2,'Bad headline index. Expected index,index. got: %s' % sel2
225+ i,j = sel2 ; sel2 = w.toGuiIndex(i),w.toGuiIndex(j)
226+ assert len(sel3) == 2,'Bad headline index. Expected index,index. got: %s' % sel3
227+ i,j = sel3 ; sel3 = w.toGuiIndex(i),w.toGuiIndex(j)
228+ assert sel2 == sel3, 'mismatch in sel\nexpected: %s = %s, got: %s' % (sel2_orig,sel2,sel3)
229+ c.selectPosition(atTest)
230+ atTest.contract()
231+ # Don't redraw.
232+ finally:
233+ # Make sure to restore the headline so it can be used for future tests
234+ if inHeadline:
235+ c.setHeadString(work,'work')
236+</t>
237+<t tx="samh.20100821030600.5887">exec(g.findTestScript(c,'@common leoEditCommands test code'))
238+runEditCommandTest(c,p,inHeadline=True)</t>
239+<t tx="samh.20100821030600.5888"></t>
240+>>>>>>> MERGE-SOURCE
241 <t tx="sps.20100531034136.20110">p2 = p.firstChild().firstChild().firstChild()
242
243 aList = g.get_directives_dict_list(p2)

Subscribers

People subscribed via source and target branches

to status/vote changes: