Register insertionLocations to undoManager more properly

This commit is contained in:
1024jp 2019-01-09 12:52:30 +09:00
parent 3020d349db
commit c8c10e2142
2 changed files with 17 additions and 7 deletions

View File

@ -7,15 +7,16 @@ Change Log
### Improvements
- [beta] Support `^T` and `fn+delete` (`^D`) shortcut multi-cursor editing.
- [beta] Support `^T` and `fn+delete` (`^D`) shortcut in multi-cursor editing.
### Fixes
- [beta] Fix an issue where multiple cursors disappeared after (auto-)saving with “trim tailing whitespace on save” option.
- [beta] Fix an issue where multiple cursors disappeared after (auto-)saving with “trim trailing whitespace on save” option.
- [beta] Fix an issue where the first cursor could disappear after some specific text editing.
- [beta] Fix an issue where auto-inserted tab did not expand to spaces on auto indent level adjustment.
- [beta] Fix multi-cursor behavior of deleting to the beginning of visual line by `⌘⌫`.
- [beta] Fix multi-cusor movement when encounter a surrogate pair.
- [beta] Fix multi-cursor behavior of deleting to the beginning of the visual line by `⌘⌫`.
- [beta] Fix multi-cursor movement when encountering a surrogate pair.
- [beta] Fix an issue where a selected range and an insertion point could overlap.

View File

@ -66,7 +66,7 @@ extension NSTextView {
textStorage.beginEditing()
// use backwards enumeration to skip adjustment of applying location
// use a backward enumeration to skip adjustment of applying location
for (string, range) in zip(strings, ranges).reversed() {
let attrString = NSAttributedString(string: string, attributes: self.typingAttributes)
@ -87,7 +87,16 @@ extension NSTextView {
/// set undoable selection change
func setSelectedRangesWithUndo(_ ranges: [NSValue]) {
self.selectedRanges = ranges
if let self = self as? NSTextView & MultiCursorEditing,
let ranges = ranges as? [NSRange],
let set = self.prepareForSelectionUpdate(ranges)
{
self.selectedRanges = set.selectedRanges
self.insertionLocations = set.insertionLocations
} else {
self.selectedRanges = ranges
}
self.undoManager?.registerUndo(withTarget: self) { target in
target.setSelectedRangesWithUndo(ranges)
@ -102,7 +111,7 @@ extension NSTextView {
}
/// trim all trailing whitespace with/without keeeping editing point
/// trim all trailing whitespace with/without keeping editing point
func trimTrailingWhitespace(ignoresEmptyLines: Bool, keepingEditingPoint: Bool = false) {
assert(Thread.isMainThread)