Skip to content

Commit

Permalink
Fix issue when preparing text for insertion. When editor was set to C…
Browse files Browse the repository at this point in the history
…RLF line endings, and pasted text already contained CRLF endings, this function would not apply line ending changes correctly. Here we first split the text separating by any kind of new line character and then join them with the correct line ending.
  • Loading branch information
PasiSalenius committed Nov 30, 2024
1 parent 1fad339 commit 0b305e7
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Sources/Runestone/TextView/Core/TextInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1320,12 +1320,8 @@ extension TextInputView {

private func prepareTextForInsertion(_ text: String) -> String {
// Ensure all line endings match our preferred line endings.
var preparedText = text
let lineEndingsToReplace: [LineEnding] = [.crlf, .cr, .lf].filter { $0 != lineEndings }
for lineEnding in lineEndingsToReplace {
preparedText = preparedText.replacingOccurrences(of: lineEnding.symbol, with: lineEndings.symbol)
}
return preparedText
let lines = text.split(omittingEmptySubsequences: false, whereSeparator: \.isNewline)
return lines.joined(separator: lineEndings.symbol)
}
}

Expand Down

0 comments on commit 0b305e7

Please sign in to comment.