@@ -152,8 +152,20 @@ def _update_command(self, cmd: UpdateCommand):
152152 def identifier_resolver (m : Marker ):
153153 return self .find_identifier (source_info , m )
154154
155- # Set range_spec to cover the identifier
156- search_range = restrict_search_range (action , target , identifier_resolver )
155+ match action :
156+ case MoveClause ():
157+ # (Check parse_update_command)
158+ # when action=MoveClause example (MOVE roll TO AFTER score):
159+ # action.deleteclause.region=WHOLE
160+ # action.as_marker = action.insertclause.as_marker
161+ # action.insertclause.insert_position=FUNCTION(score)
162+ # target.as_marker = FUNCTION(roll) (the one to delete)
163+ search_range = RangeSpec .EMPTY
164+ move_src_range = restrict_search_range (action , target , identifier_resolver )
165+ case _:
166+ move_src_range = None
167+ # Set range_spec to cover the identifier
168+ search_range = restrict_search_range (action , target , identifier_resolver )
157169
158170 marker , search_range = find_marker_or_segment (action , lines , search_range )
159171
@@ -162,21 +174,33 @@ def identifier_resolver(m: Marker):
162174 )
163175
164176 match content :
177+ case str () | [str (), * _] | (str (), * _):
178+ pass
165179 case (region , relindent ):
166180 dest_indent = search_range .indent
167181 content_range = restrict_search_range_for_marker (
168182 region , action , lines , search_range , identifier_resolver
169183 )
170184 content = content_range .read (lines )
171185 count = dest_indent + (relindent or 0 )
186+ # TODO IndentationInfo.from_content(content) ?
172187 content = IndentationInfo .from_content (lines ).shift_indentation (
173188 content , count
174189 )
175- case str () | [str (), * _] | (str (), * _):
176- pass
177190 case _:
178- raise ValueError (f'Invalid content: { content } ' )
179-
191+ match action :
192+ case MoveClause (insert_position = region , relative_indentation = relindent ):
193+ dest_range = restrict_search_range_for_marker (
194+ region , action , lines , RangeSpec .EMPTY , identifier_resolver
195+ )
196+ dest_indent = dest_range .indent
197+ content = move_src_range .read (lines )
198+ count = dest_indent + (relindent or 0 )
199+ content = IndentationInfo .from_content (content ).shift_indentation (
200+ content , count
201+ )
202+ case _:
203+ raise ValueError (f'Invalid content: { content } ' )
180204
181205 self ._apply_action (action , lines , search_range , content )
182206
@@ -188,15 +212,8 @@ def _apply_action(self, action: EditingAction, lines: Sequence[str], range_spec:
188212 match action :
189213
190214 case MoveClause (insert_position = insert_position , to_other_file = other_file , relative_indentation = relindent ):
191- saved_content = range_spec .delete (lines )
192215 # TODO Move from 'lines' to the same file or to 'other_file'
193- dest_range = self ._get_index_range (InsertClause (insert_position ), lines )
194- count = dest_range .indent + (relindent or 0 )
195- saved_content = (
196- IndentationInfo .from_content (lines ).
197- shift_indentation (saved_content , count )
198- )
199- dest_range .write (saved_content , lines )
216+ range_spec .write (content , lines )
200217
201218 case DeleteClause ():
202219 range_spec .delete (lines )
0 commit comments