Skip to content

Commit

Permalink
UITextInput Conformance (#356)
Browse files Browse the repository at this point in the history
* Made EditorView conform to UITextInput

* Added conformance to UITextInput for EditorView
  • Loading branch information
rajdeep authored Jan 5, 2025
1 parent 895900e commit 9f862d6
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Proton/Proton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
1BDA09422AD4B4D400674CFE /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDA09412AD4B4D400674CFE /* Logger.swift */; };
1BDC794A2B2026EC00B19971 /* GridCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDC79492B2026EC00B19971 /* GridCellTests.swift */; };
1BDC794C2B20271800B19971 /* MockGridCellDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDC794B2B20271800B19971 /* MockGridCellDelegate.swift */; };
1BF053432CE8517D003D1FE5 /* EditorView+UITextInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BF053422CE85176003D1FE5 /* EditorView+UITextInput.swift */; };
1BF90FB4245E503E00A411A3 /* TextBlockAttributeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BF90FB3245E503E00A411A3 /* TextBlockAttributeTests.swift */; };
1BFA75A42897D52300E4A2AD /* GridViewAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BFA75A32897D52300E4A2AD /* GridViewAttachment.swift */; };
1BFBFC892ADE34050057CCB3 /* MockEditorCommandExecutorDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BFBFC882ADE34050057CCB3 /* MockEditorCommandExecutorDelegate.swift */; };
Expand Down Expand Up @@ -342,6 +343,7 @@
1BDC794B2B20271800B19971 /* MockGridCellDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockGridCellDelegate.swift; sourceTree = "<group>"; };
1BE8825E250DD7B600E2CC1B /* PRTextStorage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PRTextStorage.m; sourceTree = "<group>"; };
1BE88263250E3ADB00E2CC1B /* PREditorContentName.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PREditorContentName.m; sourceTree = "<group>"; };
1BF053422CE85176003D1FE5 /* EditorView+UITextInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EditorView+UITextInput.swift"; sourceTree = "<group>"; };
1BF90FB3245E503E00A411A3 /* TextBlockAttributeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextBlockAttributeTests.swift; sourceTree = "<group>"; };
1BFA75A32897D52300E4A2AD /* GridViewAttachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridViewAttachment.swift; sourceTree = "<group>"; };
1BFBFC882ADE34050057CCB3 /* MockEditorCommandExecutorDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockEditorCommandExecutorDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -554,6 +556,7 @@
1B45CDD423C00927001EB196 /* EditorContent.swift */,
1B45CDDE23C053FB001EB196 /* EditorContentIdentifying.swift */,
1B004EC623C1C287007893AA /* EditorView.swift */,
1BF053422CE85176003D1FE5 /* EditorView+UITextInput.swift */,
1BFFEF0B23C30D5200D2BA35 /* EditorContentView.swift */,
1B82570C23C5686F0033A0A9 /* EditorViewContext.swift */,
1B8BE91A23C71CEA00353B17 /* EditorViewDelegate.swift */,
Expand Down Expand Up @@ -1104,6 +1107,7 @@
1B238D6E2456A40200BF49D5 /* NullRichTextEditorContext.swift in Sources */,
1B21AD072B74614C00EBC0BF /* LineNumberFormatting.swift in Sources */,
1B45CDBE23BF125D001EB196 /* NSAttributedString+ContentTypes.swift in Sources */,
1BF053432CE8517D003D1FE5 /* EditorView+UITextInput.swift in Sources */,
1B7A985723C4828A00C34B14 /* RichTextEditorContext.swift in Sources */,
1BC0AA64284DF918004B8862 /* GridConfiguration.swift in Sources */,
1B7A985923C484BC00C34B14 /* RichTextViewDelegate.swift in Sources */,
Expand Down
142 changes: 142 additions & 0 deletions Proton/Sources/Swift/Editor/EditorView+UITextInput.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// EditorView+UITextInput.swift
// Proton
//
// Created by Rajdeep Kwatra on 16/11/2024.
// Copyright © 2024 Rajdeep Kwatra. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import UIKit

extension EditorView: UITextInput {
public func text(in range: UITextRange) -> String? {
richTextView.text(in: range)
}

public func replace(_ range: UITextRange, withText text: String) {
richTextView.replace(range, withText: text)
}

public var markedTextRange: UITextRange? {
richTextView.markedTextRange
}

public var markedTextStyle: [NSAttributedString.Key : Any]? {
get {
richTextView.markedTextStyle
}
set(markedTextStyle) {
richTextView.markedTextStyle = markedTextStyle
}
}

public func setMarkedText(_ markedText: String?, selectedRange: NSRange) {
richTextView.setMarkedText(markedText, selectedRange: selectedRange)
}

public func unmarkText() {
richTextView.unmarkText()
}

public var beginningOfDocument: UITextPosition {
richTextView.beginningOfDocument
}

public var endOfDocument: UITextPosition {
richTextView.endOfDocument
}

public func textRange(from fromPosition: UITextPosition, to toPosition: UITextPosition) -> UITextRange? {
richTextView.textRange(from: fromPosition, to: toPosition)
}

public func position(from position: UITextPosition, offset: Int) -> UITextPosition? {
richTextView.position(from: position, offset: offset)
}

public func position(from position: UITextPosition, in direction: UITextLayoutDirection, offset: Int) -> UITextPosition? {
richTextView.position(from: position, in: direction, offset: offset)
}

public func compare(_ position: UITextPosition, to other: UITextPosition) -> ComparisonResult {
richTextView.compare(position, to: other)
}

public func offset(from: UITextPosition, to toPosition: UITextPosition) -> Int {
richTextView.offset(from: from, to: toPosition)
}

public var inputDelegate: (any UITextInputDelegate)? {
get {
richTextView.inputDelegate
}
set(inputDelegate) {
richTextView.inputDelegate = inputDelegate
}
}

public var tokenizer: any UITextInputTokenizer {
richTextView.tokenizer
}

public func position(within range: UITextRange, farthestIn direction: UITextLayoutDirection) -> UITextPosition? {
richTextView.position(within: range, farthestIn: direction)
}

public func characterRange(byExtending position: UITextPosition, in direction: UITextLayoutDirection) -> UITextRange? {
richTextView.characterRange(byExtending: position, in: direction)
}

public func baseWritingDirection(for position: UITextPosition, in direction: UITextStorageDirection) -> NSWritingDirection {
richTextView.baseWritingDirection(for: position, in: direction)
}

public func setBaseWritingDirection(_ writingDirection: NSWritingDirection, for range: UITextRange) {
richTextView.setBaseWritingDirection(writingDirection, for: range)
}

public func firstRect(for range: UITextRange) -> CGRect {
richTextView.firstRect(for: range)
}

public func caretRect(for position: UITextPosition) -> CGRect {
richTextView.caretRect(for: position)
}

public func selectionRects(for range: UITextRange) -> [UITextSelectionRect] {
richTextView.selectionRects(for: range)
}

public func closestPosition(to point: CGPoint) -> UITextPosition? {
richTextView.closestPosition(to: point)
}

public func closestPosition(to point: CGPoint, within range: UITextRange) -> UITextPosition? {
richTextView.closestPosition(to: point, within: range)
}

public func characterRange(at point: CGPoint) -> UITextRange? {
richTextView.characterRange(at: point)
}

public var hasText: Bool {
richTextView.hasText
}

public func insertText(_ text: String) {
richTextView.insertText(text)
}
}

0 comments on commit 9f862d6

Please sign in to comment.