Skip to content

Commit

Permalink
Merge branch 'enhancement/fix-swiftlint' into enhancement/remove-unsa…
Browse files Browse the repository at this point in the history
…fe-flags
  • Loading branch information
simonbs committed May 6, 2022
2 parents ee91131 + 6eacd73 commit 2cb46f9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ final class TreeSitterTextPredicatesEvaluator {
#if DEBUG
if !Self.previousUnsupportedPredicateNames.contains(parameters.name) {
Self.previousUnsupportedPredicateNames.append(parameters.name)
print("Unsupported predicate '\(parameters.name)'. This message is only printed once and only when running in the debug configuration.")
print("Unsupported predicate '\(parameters.name)'."
+ " This message is only printed once and only when running in the debug configuration.")
}
#endif
return false
Expand Down
1 change: 1 addition & 0 deletions Sources/Runestone/Library/TextEditHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class TextEditHelper {

func string(byApplying batchReplaceSet: BatchReplaceSet) -> NSString {
let sortedReplacements = batchReplaceSet.replacements.sorted { $0.range.lowerBound < $1.range.lowerBound }
// swiftlint:disable:next force_cast
let mutableSubstring = stringView.string.mutableCopy() as! NSMutableString
var totalChangeInLength = 0
var replacedRanges: [NSRange] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// swiftlint:disable file_length
import CoreGraphics
import CoreText
import UIKit
Expand Down
17 changes: 9 additions & 8 deletions Sources/Runestone/TextView/TextInput/TextInputView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// swiftlint:disable file_length

import UIKit

protocol TextInputViewDelegate: AnyObject {
Expand Down Expand Up @@ -43,16 +42,16 @@ final class TextInputView: UIView, UITextInput {
}
}
private(set) var markedTextRange: UITextRange? {
set {
markedRange = (newValue as? IndexedRange)?.range
}
get {
if let markedRange = markedRange {
return IndexedRange(markedRange)
} else {
return nil
}
}
set {
markedRange = (newValue as? IndexedRange)?.range
}
}
var markedTextStyle: [NSAttributedString.Key: Any]?
var beginningOfDocument: UITextPosition {
Expand Down Expand Up @@ -485,12 +484,12 @@ final class TextInputView: UIView, UITextInput {
private let lineMovementController: LineMovementController
private let pageGuideController = PageGuideController()
private var markedRange: NSRange? {
set {
layoutManager.markedRange = newValue
}
get {
return layoutManager.markedRange
}
set {
layoutManager.markedRange = newValue
}
}
private var floatingCaretView: FloatingCaretView?
private var insertionPointColorBeforeFloatingBegan: UIColor = .black
Expand Down Expand Up @@ -965,9 +964,11 @@ extension TextInputView {
guard newString != string else {
return
}
guard let oldString = stringView.string.copy() as? NSString else {
return
}
timedUndoManager.endUndoGrouping()
let oldSelectedRange = selectedRange
let oldString = stringView.string.copy() as! NSString
string = newString
timedUndoManager.beginUndoGrouping()
timedUndoManager.setActionName(L10n.Undo.ActionName.replaceAll)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ enum TreeSitterPredicateMapper {
default:
let parameters = TreeSitterTextPredicate.UnsupportedParameters(name: predicate.name)
textPredicates.append(.unsupported(parameters))
break
}
}
return MapResult(properties: properties, textPredicates: textPredicates)
Expand Down
5 changes: 4 additions & 1 deletion Sources/Runestone/TreeSitter/TreeSitterTextInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ final class TreeSitterTextInput {
}
}

private func read(payload: UnsafeMutableRawPointer?, byteIndex: UInt32, position: TSPoint, bytesRead: UnsafeMutablePointer<UInt32>?) -> UnsafePointer<Int8>? {
private func read(payload: UnsafeMutableRawPointer?,
byteIndex: UInt32,
position: TSPoint,
bytesRead: UnsafeMutablePointer<UInt32>?) -> UnsafePointer<Int8>? {
let input: TreeSitterTextInput = Unmanaged.fromOpaque(payload!).takeUnretainedValue()
if let result = input.callback(ByteCount(byteIndex), TreeSitterTextPoint(position)) {
bytesRead?.pointee = result.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class MockTreeSitterParserDelegate: TreeSitterParserDelegate {

func parser(_ parser: TreeSitterParser, bytesAt byteIndex: ByteCount) -> TreeSitterTextProviderResult? {
let maxLength = stringView.string.byteCount - byteIndex
let length = min(2048, maxLength)
let length = min(2_048, maxLength)
let byteRange = ByteRange(location: byteIndex, length: length)
if let result = stringView.bytes(in: byteRange) {
return TreeSitterTextProviderResult(bytes: result.bytes, length: UInt32(result.length.value))
Expand Down

0 comments on commit 2cb46f9

Please sign in to comment.