Fix contents of selection in scripting (fix #1392)

This commit is contained in:
1024jp 2022-10-30 20:00:37 +09:00
parent 1a08589bc4
commit a4c80f5ce2
2 changed files with 3 additions and 1 deletions

View File

@ -13,6 +13,7 @@ Change Log
### Fixes
- Fix an issue on macOS 13 that the Find All button in the find panel was not localized.
- Fix an issue on CotEditor 4.4.0 that `contents of selection` of a document object returned its entire contents.

View File

@ -101,7 +101,8 @@ final class TextSelection: NSObject {
get {
guard let textView = self.textView else { return nil }
let textStorage = NSTextStorage(string: textView.string)
let string = (textView.string as NSString).substring(with: textView.selectedRange)
let textStorage = NSTextStorage(string: string)
textStorage.observeDirectEditing { (editedString) in
textView.insert(string: editedString, at: .replaceSelection)