Skip to content

Commit

Permalink
Visual Timeline Editor: Fix various copy/paste issues (#2459)
Browse files Browse the repository at this point in the history
Fixes multiple edge cases of copying and pasting events in the visual editor.
  • Loading branch information
salianifo authored Nov 11, 2024
1 parent b21dce8 commit 69760b1
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,12 @@ func get_events_indexed(events:Array) -> Dictionary:
if event.resource is DialogicEndBranchEvent:
continue

indexed_dict[event.get_index()] = event.resource.to_text()
indexed_dict[event.get_index()] = event.resource._store_as_string()

# store an end branch if it is selected or connected to a selected event
if 'end_node' in event and event.end_node:
event = event.end_node
indexed_dict[event.get_index()] = event.resource.to_text()
indexed_dict[event.get_index()] = event.resource._store_as_string()
elif event.resource is DialogicEndBranchEvent:
if event.parent_node in events: # add local index
indexed_dict[event.get_index()] += str(events.find(event.parent_node))
Expand Down Expand Up @@ -476,7 +476,7 @@ func add_events_indexed(indexed_events:Dictionary) -> void:
event_resource = i.duplicate()
break

event_resource.from_text(indexed_events[event_idx])
event_resource._load_from_string(indexed_events[event_idx])

# now create the visual block.
deselect_all_items()
Expand Down Expand Up @@ -547,7 +547,7 @@ func copy_selected_events() -> void:

var event_copy_array := []
for item in selected_items:
event_copy_array.append(item.resource.to_text())
event_copy_array.append(item.resource._store_as_string())
if item.resource is DialogicEndBranchEvent:
if item.parent_node in selected_items: # add local index
event_copy_array[-1] += str(selected_items.find(item.parent_node))
Expand Down Expand Up @@ -1104,16 +1104,17 @@ func _input(event:InputEvent) -> void:
get_viewport().set_input_as_handled()

"Ctrl+C":
select_events_indexed(get_events_indexed(selected_items))
copy_selected_events()
get_viewport().set_input_as_handled()

"Ctrl+V":
var events_list := get_clipboard_data()
var paste_position := -1
var paste_position := 0
if selected_items:
paste_position = selected_items[-1].get_index()+1
else:
paste_position = %Timeline.get_child_count()-1
paste_position = %Timeline.get_child_count()
if events_list:
TimelineUndoRedo.create_action("[D] Pasting "+str(len(events_list))+" event(s).")
TimelineUndoRedo.add_do_method(add_events_at_index.bind(events_list, paste_position))
Expand Down

0 comments on commit 69760b1

Please sign in to comment.