mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-10-26 10:58:05 +03:00
Fix line ending of string via script
This commit is contained in:
parent
cd50d6550f
commit
b621442068
@ -49,6 +49,11 @@ develop
|
||||
- Enable activate “Show Invisibles” action even if all of invisible characters were set as not shown when the document was opened.
|
||||
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fix an issue where some of script APIs returned always string with LF line endings.
|
||||
|
||||
|
||||
|
||||
2.5.7-alpha
|
||||
--------------------------
|
||||
|
@ -38,19 +38,24 @@ protocol Editable: class {
|
||||
|
||||
extension Editable {
|
||||
|
||||
/// return string in text view (LF fix)
|
||||
/// line ending applied document string
|
||||
var string: String {
|
||||
|
||||
guard let string = self.textView?.string else { return "" }
|
||||
|
||||
return self.textView?.string ?? ""
|
||||
return string.replacingLineEndings(with: self.lineEnding)
|
||||
}
|
||||
|
||||
|
||||
/// return current selection
|
||||
var substringWithSelection: String? {
|
||||
/// line ending applied current selection
|
||||
var selectedString: String {
|
||||
|
||||
guard let selectedRange = self.textView?.selectedRange else { return nil }
|
||||
guard let textView = self.textView,
|
||||
let string = textView.string else { return "" }
|
||||
|
||||
return (self.string as NSString).substring(with: selectedRange)
|
||||
let substring = (string as NSString).substring(with: textView.selectedRange)
|
||||
|
||||
return substring.replacingLineEndings(with: self.lineEnding)
|
||||
}
|
||||
|
||||
|
||||
|
@ -225,7 +225,7 @@ final class ScriptManager: NSObject {
|
||||
|
||||
switch type {
|
||||
case .selection:
|
||||
return editor.substringWithSelection ?? ""
|
||||
return editor.selectedString
|
||||
|
||||
case .allText:
|
||||
return editor.string
|
||||
|
@ -102,12 +102,7 @@ final class TextSelection: NSObject {
|
||||
/// string of the selection (Unicode text)
|
||||
var contents: Any? {
|
||||
get {
|
||||
guard
|
||||
let document = self.document,
|
||||
var string = document.editor?.substringWithSelection else { return nil }
|
||||
|
||||
// apply line endings
|
||||
string = string.replacingLineEndings(with: document.lineEnding)
|
||||
guard let string = self.document?.editor?.selectedString else { return nil }
|
||||
|
||||
return NSTextStorage(string: string)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user