Skip to content

Commit a8a0e9c

Browse files
Correctly Group Drag-and-drop for Undo (#104)
### Description Moves the `endUndoGrouping` call to the end of the actual editing operation when dropping text. Makes it so only one undo command is needed to undo a drag-and-drop operation. ### Related Issues * closes #99 ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots https://github.com/user-attachments/assets/35952874-6d4d-4702-b149-f06b9ffb5226
1 parent c127b47 commit a8a0e9c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/CodeEditTextView/TextView/TextView+Drag.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ extension TextView: NSDraggingSource {
255255
insertText("") // Replace the selected ranges with nothing
256256
}
257257

258-
undoManager?.endUndoGrouping()
259-
260258
replaceCharacters(in: [NSRange(location: insertionOffset, length: 0)], with: insertionString)
261259

260+
undoManager?.endUndoGrouping()
261+
262262
selectionManager.setSelectedRange(
263263
NSRange(location: insertionOffset, length: NSString(string: insertionString).length)
264264
)

0 commit comments

Comments
 (0)