Ensure new text items are on the canvas.

This commit is contained in:
Matthew Chen 2019-03-26 16:09:34 -04:00 committed by Michael Kirk
parent 675c60bf4e
commit 5973c326de
2 changed files with 8 additions and 3 deletions

View File

@ -75,8 +75,8 @@ private class VAlignTextView: UITextView {
override var keyCommands: [UIKeyCommand]? {
return [
UIKeyCommand(input: "\r", modifierFlags: .command, action: #selector(self.modifiedReturnPressed(sender:)), discoverabilityTitle: "Send Message"),
UIKeyCommand(input: "\r", modifierFlags: .alternate, action: #selector(self.modifiedReturnPressed(sender:)), discoverabilityTitle: "Send Message")
UIKeyCommand(input: "\r", modifierFlags: .command, action: #selector(self.modifiedReturnPressed(sender:)), discoverabilityTitle: "Add Text"),
UIKeyCommand(input: "\r", modifierFlags: .alternate, action: #selector(self.modifiedReturnPressed(sender:)), discoverabilityTitle: "Add Text")
]
}
@ -295,7 +295,7 @@ public class ImageEditorTextViewController: OWSViewController, VAlignTextViewDel
// Ensure continuity of the new text item's location
// with its apparent location in this text editor.
let locationInView = view.convert(textView.bounds.center, from: textView)
let locationInView = view.convert(textView.bounds.center, from: textView).clamp(view.bounds)
let textCenterImageUnit = ImageEditorCanvasView.locationImageUnit(forLocationInView: locationInView,
viewBounds: viewBounds,
model: model,

View File

@ -270,6 +270,11 @@ public extension CGPoint {
return CGPoint(x: sin(angle),
y: cos(angle))
}
public func clamp(_ rect: CGRect) -> CGPoint {
return CGPoint(x: x.clamp(rect.minX, rect.maxX),
y: y.clamp(rect.minY, rect.maxY))
}
}
// MARK: -