|
| 1 | +// |
| 2 | +// EditorView+UITextInput.swift |
| 3 | +// Proton |
| 4 | +// |
| 5 | +// Created by Rajdeep Kwatra on 16/11/2024. |
| 6 | +// Copyright © 2024 Rajdeep Kwatra. All rights reserved. |
| 7 | +// |
| 8 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | +// you may not use this file except in compliance with the License. |
| 10 | +// You may obtain a copy of the License at |
| 11 | +// |
| 12 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +// |
| 14 | +// Unless required by applicable law or agreed to in writing, software |
| 15 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +// See the License for the specific language governing permissions and |
| 18 | +// limitations under the License. |
| 19 | +// |
| 20 | + |
| 21 | +import Foundation |
| 22 | +import UIKit |
| 23 | + |
| 24 | +extension EditorView: UITextInput { |
| 25 | + public func text(in range: UITextRange) -> String? { |
| 26 | + richTextView.text(in: range) |
| 27 | + } |
| 28 | + |
| 29 | + public func replace(_ range: UITextRange, withText text: String) { |
| 30 | + richTextView.replace(range, withText: text) |
| 31 | + } |
| 32 | + |
| 33 | + public var markedTextRange: UITextRange? { |
| 34 | + richTextView.markedTextRange |
| 35 | + } |
| 36 | + |
| 37 | + public var markedTextStyle: [NSAttributedString.Key : Any]? { |
| 38 | + get { |
| 39 | + richTextView.markedTextStyle |
| 40 | + } |
| 41 | + set(markedTextStyle) { |
| 42 | + richTextView.markedTextStyle = markedTextStyle |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public func setMarkedText(_ markedText: String?, selectedRange: NSRange) { |
| 47 | + richTextView.setMarkedText(markedText, selectedRange: selectedRange) |
| 48 | + } |
| 49 | + |
| 50 | + public func unmarkText() { |
| 51 | + richTextView.unmarkText() |
| 52 | + } |
| 53 | + |
| 54 | + public var beginningOfDocument: UITextPosition { |
| 55 | + richTextView.beginningOfDocument |
| 56 | + } |
| 57 | + |
| 58 | + public var endOfDocument: UITextPosition { |
| 59 | + richTextView.endOfDocument |
| 60 | + } |
| 61 | + |
| 62 | + public func textRange(from fromPosition: UITextPosition, to toPosition: UITextPosition) -> UITextRange? { |
| 63 | + richTextView.textRange(from: fromPosition, to: toPosition) |
| 64 | + } |
| 65 | + |
| 66 | + public func position(from position: UITextPosition, offset: Int) -> UITextPosition? { |
| 67 | + richTextView.position(from: position, offset: offset) |
| 68 | + } |
| 69 | + |
| 70 | + public func position(from position: UITextPosition, in direction: UITextLayoutDirection, offset: Int) -> UITextPosition? { |
| 71 | + richTextView.position(from: position, in: direction, offset: offset) |
| 72 | + } |
| 73 | + |
| 74 | + public func compare(_ position: UITextPosition, to other: UITextPosition) -> ComparisonResult { |
| 75 | + richTextView.compare(position, to: other) |
| 76 | + } |
| 77 | + |
| 78 | + public func offset(from: UITextPosition, to toPosition: UITextPosition) -> Int { |
| 79 | + richTextView.offset(from: from, to: toPosition) |
| 80 | + } |
| 81 | + |
| 82 | + public var inputDelegate: (any UITextInputDelegate)? { |
| 83 | + get { |
| 84 | + richTextView.inputDelegate |
| 85 | + } |
| 86 | + set(inputDelegate) { |
| 87 | + richTextView.inputDelegate = inputDelegate |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + public var tokenizer: any UITextInputTokenizer { |
| 92 | + richTextView.tokenizer |
| 93 | + } |
| 94 | + |
| 95 | + public func position(within range: UITextRange, farthestIn direction: UITextLayoutDirection) -> UITextPosition? { |
| 96 | + richTextView.position(within: range, farthestIn: direction) |
| 97 | + } |
| 98 | + |
| 99 | + public func characterRange(byExtending position: UITextPosition, in direction: UITextLayoutDirection) -> UITextRange? { |
| 100 | + richTextView.characterRange(byExtending: position, in: direction) |
| 101 | + } |
| 102 | + |
| 103 | + public func baseWritingDirection(for position: UITextPosition, in direction: UITextStorageDirection) -> NSWritingDirection { |
| 104 | + richTextView.baseWritingDirection(for: position, in: direction) |
| 105 | + } |
| 106 | + |
| 107 | + public func setBaseWritingDirection(_ writingDirection: NSWritingDirection, for range: UITextRange) { |
| 108 | + richTextView.setBaseWritingDirection(writingDirection, for: range) |
| 109 | + } |
| 110 | + |
| 111 | + public func firstRect(for range: UITextRange) -> CGRect { |
| 112 | + richTextView.firstRect(for: range) |
| 113 | + } |
| 114 | + |
| 115 | + public func caretRect(for position: UITextPosition) -> CGRect { |
| 116 | + richTextView.caretRect(for: position) |
| 117 | + } |
| 118 | + |
| 119 | + public func selectionRects(for range: UITextRange) -> [UITextSelectionRect] { |
| 120 | + richTextView.selectionRects(for: range) |
| 121 | + } |
| 122 | + |
| 123 | + public func closestPosition(to point: CGPoint) -> UITextPosition? { |
| 124 | + richTextView.closestPosition(to: point) |
| 125 | + } |
| 126 | + |
| 127 | + public func closestPosition(to point: CGPoint, within range: UITextRange) -> UITextPosition? { |
| 128 | + richTextView.closestPosition(to: point, within: range) |
| 129 | + } |
| 130 | + |
| 131 | + public func characterRange(at point: CGPoint) -> UITextRange? { |
| 132 | + richTextView.characterRange(at: point) |
| 133 | + } |
| 134 | + |
| 135 | + public var hasText: Bool { |
| 136 | + richTextView.hasText |
| 137 | + } |
| 138 | + |
| 139 | + public func insertText(_ text: String) { |
| 140 | + richTextView.insertText(text) |
| 141 | + } |
| 142 | +} |
0 commit comments