fix: emoji picker set wrong selected range after insert text issue
This commit is contained in:
parent
9190b27163
commit
6126c15c66
@ -4778,7 +4778,7 @@
|
|||||||
repositoryURL = "https://github.com/TwidereProject/MetaTextView.git";
|
repositoryURL = "https://github.com/TwidereProject/MetaTextView.git";
|
||||||
requirement = {
|
requirement = {
|
||||||
kind = exactVersion;
|
kind = exactVersion;
|
||||||
version = 1.2.2;
|
version = 1.2.3;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
DB0E2D2C26833FF600865C3C /* XCRemoteSwiftPackageReference "Nuke-FLAnimatedImage-Plugin" */ = {
|
DB0E2D2C26833FF600865C3C /* XCRemoteSwiftPackageReference "Nuke-FLAnimatedImage-Plugin" */ = {
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<key>CoreDataStack.xcscheme_^#shared#^_</key>
|
<key>CoreDataStack.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>20</integer>
|
<integer>21</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Mastodon - ASDK.xcscheme_^#shared#^_</key>
|
<key>Mastodon - ASDK.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
<key>NotificationService.xcscheme_^#shared#^_</key>
|
<key>NotificationService.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>21</integer>
|
<integer>22</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<key>SuppressBuildableAutocreation</key>
|
<key>SuppressBuildableAutocreation</key>
|
||||||
|
@ -114,8 +114,8 @@
|
|||||||
"repositoryURL": "https://github.com/TwidereProject/MetaTextView.git",
|
"repositoryURL": "https://github.com/TwidereProject/MetaTextView.git",
|
||||||
"state": {
|
"state": {
|
||||||
"branch": null,
|
"branch": null,
|
||||||
"revision": "d48cf6a2479ce6fc4f836b6c4d7ba855cdbc71cc",
|
"revision": "5b86b386464be8a6da5383aa714c458c07da6c01",
|
||||||
"version": "1.2.2"
|
"version": "1.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -58,14 +58,8 @@ extension ComposeStatusSection {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol CustomEmojiReplaceableTextInput: AnyObject {
|
protocol CustomEmojiReplaceableTextInput: UITextInput & UIResponder {
|
||||||
var inputView: UIView? { get set }
|
var inputView: UIView? { get set }
|
||||||
func reloadInputViews()
|
|
||||||
|
|
||||||
// UIKeyInput
|
|
||||||
func insertText(_ text: String)
|
|
||||||
// UIResponder
|
|
||||||
var isFirstResponder: Bool { get }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomEmojiReplaceableTextInputReference {
|
class CustomEmojiReplaceableTextInputReference {
|
||||||
|
@ -46,8 +46,23 @@ extension CustomEmojiPickerInputViewModel {
|
|||||||
removeEmptyReferences()
|
removeEmptyReferences()
|
||||||
|
|
||||||
for reference in customEmojiReplaceableTextInputReferences {
|
for reference in customEmojiReplaceableTextInputReferences {
|
||||||
guard reference.value?.isFirstResponder == true else { continue }
|
guard let textInput = reference.value else { continue }
|
||||||
reference.value?.insertText(text)
|
guard textInput.isFirstResponder == true else { continue }
|
||||||
|
|
||||||
|
let selectedTextRange = textInput.selectedTextRange
|
||||||
|
textInput.insertText(text)
|
||||||
|
|
||||||
|
// due to insert text render as attachment
|
||||||
|
// the cursor reset logic not works
|
||||||
|
// hack with hard code +2 offset
|
||||||
|
assert(text.hasSuffix(": "))
|
||||||
|
if text.hasPrefix(":") && text.hasSuffix(": "),
|
||||||
|
let selectedTextRange = selectedTextRange,
|
||||||
|
let newPosition = textInput.position(from: selectedTextRange.start, offset: 2) {
|
||||||
|
let newSelectedTextRange = textInput.textRange(from: newPosition, to: newPosition)
|
||||||
|
textInput.selectedTextRange = newSelectedTextRange
|
||||||
|
}
|
||||||
|
|
||||||
return reference
|
return reference
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user