Skip to content

Commit 9f862d6

Browse files
authored
UITextInput Conformance (#356)
* Made EditorView conform to UITextInput * Added conformance to UITextInput for EditorView
1 parent 895900e commit 9f862d6

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

Proton/Proton.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
1BDA09422AD4B4D400674CFE /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDA09412AD4B4D400674CFE /* Logger.swift */; };
150150
1BDC794A2B2026EC00B19971 /* GridCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDC79492B2026EC00B19971 /* GridCellTests.swift */; };
151151
1BDC794C2B20271800B19971 /* MockGridCellDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDC794B2B20271800B19971 /* MockGridCellDelegate.swift */; };
152+
1BF053432CE8517D003D1FE5 /* EditorView+UITextInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BF053422CE85176003D1FE5 /* EditorView+UITextInput.swift */; };
152153
1BF90FB4245E503E00A411A3 /* TextBlockAttributeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BF90FB3245E503E00A411A3 /* TextBlockAttributeTests.swift */; };
153154
1BFA75A42897D52300E4A2AD /* GridViewAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BFA75A32897D52300E4A2AD /* GridViewAttachment.swift */; };
154155
1BFBFC892ADE34050057CCB3 /* MockEditorCommandExecutorDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BFBFC882ADE34050057CCB3 /* MockEditorCommandExecutorDelegate.swift */; };
@@ -342,6 +343,7 @@
342343
1BDC794B2B20271800B19971 /* MockGridCellDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockGridCellDelegate.swift; sourceTree = "<group>"; };
343344
1BE8825E250DD7B600E2CC1B /* PRTextStorage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PRTextStorage.m; sourceTree = "<group>"; };
344345
1BE88263250E3ADB00E2CC1B /* PREditorContentName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PREditorContentName.m; sourceTree = "<group>"; };
346+
1BF053422CE85176003D1FE5 /* EditorView+UITextInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EditorView+UITextInput.swift"; sourceTree = "<group>"; };
345347
1BF90FB3245E503E00A411A3 /* TextBlockAttributeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextBlockAttributeTests.swift; sourceTree = "<group>"; };
346348
1BFA75A32897D52300E4A2AD /* GridViewAttachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridViewAttachment.swift; sourceTree = "<group>"; };
347349
1BFBFC882ADE34050057CCB3 /* MockEditorCommandExecutorDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockEditorCommandExecutorDelegate.swift; sourceTree = "<group>"; };
@@ -554,6 +556,7 @@
554556
1B45CDD423C00927001EB196 /* EditorContent.swift */,
555557
1B45CDDE23C053FB001EB196 /* EditorContentIdentifying.swift */,
556558
1B004EC623C1C287007893AA /* EditorView.swift */,
559+
1BF053422CE85176003D1FE5 /* EditorView+UITextInput.swift */,
557560
1BFFEF0B23C30D5200D2BA35 /* EditorContentView.swift */,
558561
1B82570C23C5686F0033A0A9 /* EditorViewContext.swift */,
559562
1B8BE91A23C71CEA00353B17 /* EditorViewDelegate.swift */,
@@ -1104,6 +1107,7 @@
11041107
1B238D6E2456A40200BF49D5 /* NullRichTextEditorContext.swift in Sources */,
11051108
1B21AD072B74614C00EBC0BF /* LineNumberFormatting.swift in Sources */,
11061109
1B45CDBE23BF125D001EB196 /* NSAttributedString+ContentTypes.swift in Sources */,
1110+
1BF053432CE8517D003D1FE5 /* EditorView+UITextInput.swift in Sources */,
11071111
1B7A985723C4828A00C34B14 /* RichTextEditorContext.swift in Sources */,
11081112
1BC0AA64284DF918004B8862 /* GridConfiguration.swift in Sources */,
11091113
1B7A985923C484BC00C34B14 /* RichTextViewDelegate.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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

Comments
 (0)