-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Made EditorView conform to UITextInput * Added conformance to UITextInput for EditorView
- Loading branch information
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
Proton/Sources/Swift/Editor/EditorView+UITextInput.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |