@@ -37,6 +37,8 @@ def __init__(self, suggestion_source):
3737 self .Bind (wx .EVT_MOVE , self .OnFocusLost )
3838 self ._showing_content_assist = False
3939 self ._row = None
40+ self .gherkin_prefix = '' # Store gherkin prefix from input to add \
41+ # later after search is performed
4042
4143 def set_row (self , row ):
4244 self ._row = row
@@ -48,7 +50,7 @@ def OnChar(self, event):
4850 if keycode == wx .WXK_SPACE and event .ControlDown ():
4951 self .show_content_assist ()
5052 return
51- if keycode in [wx .WXK_UP , wx .WXK_DOWN , wx .WXK_PAGEUP , wx .WXK_PAGEDOWN ] \
53+ if keycode in [wx .WXK_UP , wx .WXK_DOWN , wx .WXK_PAGEUP , wx .WXK_PAGEDOWN ]\
5254 and self ._popup .is_shown ():
5355 self ._popup .select_and_scroll (keycode )
5456 return
@@ -62,14 +64,16 @@ def OnChar(self, event):
6264 return
6365 elif self ._popup .is_shown () and keycode < 256 :
6466 self ._populate_content_assist (event )
65- elif keycode in (ord ('1' ), ord ('2' )) and event .ControlDown () and not event .AltDown ():
66- self .execute_variable_creator (list_variable = (keycode == ord ('2' )))
67+ elif keycode in (ord ('1' ), ord ('2' )) and event .ControlDown () and not \
68+ event .AltDown ():
69+ self .execute_variable_creator (list_variable = (keycode == ord ('2' )))
6770 event .Skip ()
6871
6972 def execute_variable_creator (self , list_variable = False ):
7073 from_ , to_ = self .GetSelection ()
7174 symbol = '@' if list_variable else '$'
72- self .SetValue (self ._variable_creator_value (self .Value , symbol , from_ , to_ ))
75+ self .SetValue (self ._variable_creator_value (
76+ self .Value , symbol , from_ , to_ ))
7377 if from_ == to_ :
7478 self .SetInsertionPoint (from_ + 2 )
7579 else :
@@ -81,7 +85,7 @@ def _variable_creator_value(self, value, symbol, from_, to_):
8185 def OnFocusLost (self , event , set_value = True ):
8286 if not self ._popup .is_shown ():
8387 return
84- value = self ._popup .get_value ()
88+ value = self .gherkin_prefix + self . _popup .get_value ()
8589 if set_value and value :
8690 self .SetValue (value )
8791 self .SetInsertionPoint (len (self .Value ))
@@ -113,26 +117,41 @@ def _populate_content_assist(self, event=None):
113117 return False
114118 else :
115119 value += unichr (event .GetRawKeyCode ())
120+ (self .gherkin_prefix , value ) = self ._remove_bdd_prefix (value )
116121 return self ._popup .content_assist_for (value , row = self ._row )
117122
123+ def _remove_bdd_prefix (self , name ):
124+ for match in ['given ' , 'when ' , 'then ' , 'and ' , 'but ' ]:
125+ if name .lower ().startswith (match ):
126+ return (name [:len (match )], name [len (match ):])
127+ return ('' , name )
128+
118129 def _show_content_assist (self ):
119130 height = self .GetSizeTuple ()[1 ]
120131 x , y = self .ClientToScreenXY (0 , 0 )
121132 self ._popup .show (x , y , height )
122133
123134 def content_assist_value (self ):
124- return self ._popup .content_assist_value (self .Value )
135+ suggestion = self ._popup .content_assist_value (self .Value )
136+ if suggestion is None :
137+ return suggestion
138+ else :
139+ return self .gherkin_prefix + suggestion
125140
126141 def hide (self ):
127142 self ._popup .hide ()
128143 self ._showing_content_assist = False
129144
130145
131- class ExpandingContentAssistTextCtrl (_ContentAssistTextCtrlBase , ExpandoTextCtrl ):
146+ class ExpandingContentAssistTextCtrl (_ContentAssistTextCtrlBase ,
147+ ExpandoTextCtrl ):
132148
133149 def __init__ (self , parent , plugin , controller ):
134- ExpandoTextCtrl .__init__ (self , parent , size = wx .DefaultSize , style = wx .WANTS_CHARS )
135- _ContentAssistTextCtrlBase .__init__ (self , SuggestionSource (plugin , controller ))
150+ ExpandoTextCtrl .__init__ (self , parent , size = wx .DefaultSize ,
151+ style = wx .WANTS_CHARS )
152+ _ContentAssistTextCtrlBase .__init__ (self ,
153+ SuggestionSource (plugin ,
154+ controller ))
136155
137156
138157class ContentAssistTextCtrl (_ContentAssistTextCtrlBase , wx .TextCtrl ):
@@ -144,10 +163,11 @@ def __init__(self, parent, suggestion_source, size=wx.DefaultSize):
144163
145164class ContentAssistFileButton (_ContentAssistTextCtrlBase , FileBrowseButton ):
146165
147- def __init__ (self , parent , suggestion_source , label , controller , size = wx .DefaultSize ):
166+ def __init__ (self , parent , suggestion_source , label , controller ,
167+ size = wx .DefaultSize ):
148168 FileBrowseButton .__init__ (self , parent , labelText = label ,
149- size = size , fileMask = "*" ,
150- changeCallback = self .OnFileChanged )
169+ size = size , fileMask = "*" ,
170+ changeCallback = self .OnFileChanged )
151171 self ._parent = parent
152172 self ._controller = controller
153173 self ._browsed = False
@@ -183,10 +203,11 @@ def SelectAll(self):
183203 def _relative_path (self , value ):
184204 src = self ._controller .datafile .source
185205 if utils .is_same_drive (src , value ):
186- path = relpath (value , src if isdir (src ) else dirname (src ))
206+ path = relpath (value , src if isdir (src ) else dirname (src ))
187207 else :
188208 path = value
189- return path .replace ('\\ ' , '/' ) if context .IS_WINDOWS else path .replace ('\\ ' , '\\ \\ ' )
209+ return path .replace ('\\ ' , '/' ) if context .IS_WINDOWS else \
210+ path .replace ('\\ ' , '\\ \\ ' )
190211
191212
192213class Suggestions (object ):
@@ -199,7 +220,7 @@ def __init__(self, suggestion_source):
199220 def get_for (self , value , row = None ):
200221 self ._previous_choices = self ._get_choices (value , row )
201222 self ._previous_value = value
202- return [k for k ,_ in self ._previous_choices ]
223+ return [k for k , _ in self ._previous_choices ]
203224
204225 def get_item (self , name ):
205226 for k , v in self ._previous_choices :
@@ -210,7 +231,7 @@ def get_item(self, name):
210231 def _get_choices (self , value , row ):
211232 if self ._previous_value and value .startswith (self ._previous_value ):
212233 return [(key , val ) for key , val in self ._previous_choices
213- if utils .normalize (key ).startswith (utils .normalize (value ))]
234+ if utils .normalize (key ).startswith (utils .normalize (value ))]
214235 choices = self ._suggestion_source .get_suggestions (value , row )
215236 duplicate_names = self ._get_duplicate_names (choices )
216237 return self ._format_choices (choices , value , duplicate_names )
@@ -225,15 +246,18 @@ def _get_duplicate_names(self, choices):
225246 return results
226247
227248 def _format_choices (self , choices , prefix , duplicate_names ):
228- return [(self ._format (val , prefix , duplicate_names ), val ) for val in choices ]
249+ return [(self ._format (val , prefix , duplicate_names ), val ) for val in
250+ choices ]
229251
230252 def _format (self , choice , prefix , duplicate_names ):
231- return choice .name if self ._matches_unique_shortname (choice , prefix , duplicate_names ) else choice .longname
253+ return choice .name if self ._matches_unique_shortname (
254+ choice , prefix , duplicate_names ) else choice .longname
232255
233256 def _matches_unique_shortname (self , choice , prefix , duplicate_names ):
234257 if isinstance (choice , VariableInfo ):
235258 return True
236- if not utils .normalize (choice .name ).startswith (utils .normalize (prefix )):
259+ if not utils .normalize (choice .name ).startswith (
260+ utils .normalize (prefix )):
237261 return False
238262 if utils .normalize (choice .name ) in duplicate_names :
239263 return False
@@ -247,15 +271,17 @@ def __init__(self, parent, suggestion_source):
247271 self ._main_popup = RidePopupWindow (parent , _PREFERRED_POPUP_SIZE )
248272 self ._details_popup = HtmlPopupWindow (parent , _PREFERRED_POPUP_SIZE )
249273 self ._selection = - 1
250- self ._list = ContentAssistList (self ._main_popup , self .OnListItemSelected ,
274+ self ._list = ContentAssistList (self ._main_popup ,
275+ self .OnListItemSelected ,
251276 self .OnListItemActivated )
252277 self ._suggestions = Suggestions (suggestion_source )
253278
254279 def reset (self ):
255280 self ._selection = - 1
256281
257282 def get_value (self ):
258- return self ._selection != - 1 and self ._list .get_text (self ._selection ) or None
283+ return self ._selection != - 1 and self ._list .get_text (
284+ self ._selection ) or None
259285
260286 def content_assist_for (self , value , row = None ):
261287 self ._choices = self ._suggestions .get_for (value , row = row )
@@ -275,9 +301,12 @@ def content_assist_value(self, value):
275301 return None
276302
277303 def show (self , xcoord , ycoord , cell_height ):
278- self ._main_popup .SetPosition ((xcoord , self ._move_y_where_room (ycoord , cell_height )))
304+ self ._main_popup .SetPosition ((xcoord ,
305+ self ._move_y_where_room (ycoord ,
306+ cell_height )))
279307 self ._details_popup .SetPosition ((self ._move_x_where_room (xcoord ),
280- self ._move_y_where_room (ycoord , cell_height )))
308+ self ._move_y_where_room (ycoord ,
309+ cell_height )))
281310 self ._main_popup .Show ()
282311 self ._list .SetFocus ()
283312
@@ -303,13 +332,13 @@ def is_shown(self):
303332
304333 def select_and_scroll (self , keycode ):
305334 sel = self ._list .GetFirstSelected ()
306- if keycode == wx .WXK_DOWN :
335+ if keycode == wx .WXK_DOWN :
307336 if sel < (self ._list .GetItemCount () - 1 ):
308337 self ._select_and_scroll (sel + 1 )
309338 else :
310339 self ._select_and_scroll (0 )
311340 elif keycode == wx .WXK_UP :
312- if sel > 0 :
341+ if sel > 0 :
313342 self ._select_and_scroll (sel - 1 )
314343 else :
315344 self ._select_and_scroll (self ._list .GetItemCount () - 1 )
0 commit comments