@@ -152,8 +152,20 @@ def _update_command(self, cmd: UpdateCommand):
152
152
def identifier_resolver (m : Marker ):
153
153
return self .find_identifier (source_info , m )
154
154
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 )
157
169
158
170
marker , search_range = find_marker_or_segment (action , lines , search_range )
159
171
@@ -162,21 +174,33 @@ def identifier_resolver(m: Marker):
162
174
)
163
175
164
176
match content :
177
+ case str () | [str (), * _] | (str (), * _):
178
+ pass
165
179
case (region , relindent ):
166
180
dest_indent = search_range .indent
167
181
content_range = restrict_search_range_for_marker (
168
182
region , action , lines , search_range , identifier_resolver
169
183
)
170
184
content = content_range .read (lines )
171
185
count = dest_indent + (relindent or 0 )
186
+ # TODO IndentationInfo.from_content(content) ?
172
187
content = IndentationInfo .from_content (lines ).shift_indentation (
173
188
content , count
174
189
)
175
- case str () | [str (), * _] | (str (), * _):
176
- pass
177
190
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 } ' )
180
204
181
205
self ._apply_action (action , lines , search_range , content )
182
206
@@ -188,15 +212,8 @@ def _apply_action(self, action: EditingAction, lines: Sequence[str], range_spec:
188
212
match action :
189
213
190
214
case MoveClause (insert_position = insert_position , to_other_file = other_file , relative_indentation = relindent ):
191
- saved_content = range_spec .delete (lines )
192
215
# 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 )
200
217
201
218
case DeleteClause ():
202
219
range_spec .delete (lines )
0 commit comments