Update LCManager.swift

Fix for some potential issues that could be caused by initializing LCManager off the main queue, and improved the console text view's ability to stick to the bottom if it is scrolled to the bottom.
This commit is contained in:
Duraid Abdul committed 2021-08-16 11:40:35 -07:00
1 parent 0ae97b8162
commit ab79c1200f
1 file changed
+8 -10
+8 -10
View File
@@ -86,11 +86,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
var consoleWindow: ConsoleWindow?
// The console needs a parent view controller in order to display context menus.
let viewController = UIViewController()
lazy var viewController = UIViewController()
lazy var consoleView = viewController.view!
/// Text view that displays printed items.
let consoleTextView = InvertedTextView()
lazy var consoleTextView = InvertedTextView()
/// Button that reveals menu.
lazy var menuButton = UIButton()
@@ -99,7 +99,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
var scrollLocked = true
/// Feedback generator for the long press action.
let feedbackGenerator = UISelectionFeedbackGenerator()
lazy var feedbackGenerator = UISelectionFeedbackGenerator()
lazy var panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(consolePiPPanner(recognizer:)))
lazy var longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(recognizer:)))
@@ -303,8 +303,6 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
}
}
private var _hasRelayedOffsetChange = false
/// Print items to the console view.
public func print(_ items: Any) {
if currentText == "" {
@@ -462,15 +460,15 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
func commitTextChanges(requestMenuUpdate menuUpdateRequested: Bool) {
if consoleTextView.contentOffset.y > consoleTextView.contentSize.height - consoleTextView.bounds.size.height - 20
|| _hasRelayedOffsetChange == false {
if consoleTextView.contentOffset.y > consoleTextView.contentSize.height - consoleTextView.bounds.size.height - 20 {
// Weird, weird fix that makes the scroll view bottom pinning system work.
consoleTextView.isScrollEnabled.toggle()
consoleTextView.isScrollEnabled.toggle()
consoleTextView.pendingOffsetChange = true
_hasRelayedOffsetChange = true
}
consoleTextView.text = currentText
setAttributedText(currentText)
if menuUpdateRequested {