Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove mention in one stroke while typing backspace #15

Open
kiran4991 opened this issue Jul 11, 2019 · 0 comments
Open

How to remove mention in one stroke while typing backspace #15

kiran4991 opened this issue Jul 11, 2019 · 0 comments

Comments

@kiran4991
Copy link

kiran4991 commented Jul 11, 2019

Hi @szweier , Awesome library you have made. I have integrated it in my code. Working fine. But just one feature I want, that is to remove mention in just one stroke while backspacing. I just tried the following code,

if let mention = mentions |> mentionBeingEdited(at: range) {
mention |> clearMention()
/* let str = mentionsTextView.attributedText.string
let replaceStr = NSAttributedString(string:str.replacingOccurrences(of: mention.object.display, with: ""))
print("NAME ",mention.object.display)
print("RANGE ",range)
let str = mentionsTextView.attributedText.string
let replacedNameString = str.replacingOccurrences(of: mention.object.display, with: "")O
print("NAME AFTER REPLACE ",replacedNameString)
let (text, selectedRange) = mentionsTextView.attributedText
|> replace(charactersIn: NSRange(str.startIndex..., in: str), with: replacedNameString)
print("TEXT ",text.string)
print("selectedRange ",selectedRange)*/
// mentionsTextView.selectedRange = NSRange(mention.object.display.startIndex..., in: mention.object.display)
self.mentionsTextView.text = self.mentionsTextView.text.replacingOccurrences(of: mention.object.display, with: "")
print("self.mentionsTextView.text ",self.mentionsTextView.text)
print("mentionsTextView.attributedText ",mentionsTextView.attributedText)
print("RANGE ",NSRange(self.mentionsTextView.text.startIndex..., in: self.mentionsTextView.text))
print(mentions.count)
let (text, selectedRange) = mentionsTextView.attributedText
|> replace(charactersIn: NSRange(self.mentionsTextView.text.startIndex..., in: self.mentionsTextView.text), with: self.mentionsTextView.text)
/let (text, selectedRange) = mentionsTextView.attributedText
|> replace(charactersIn: range, with: text)
/
mentionsTextView.attributedText = text
mentionsTextView.selectedRange = selectedRange
shouldChangeText = false

above code is working fine, when we tried to remove mention from last. But if we tried to remove it from the middle then app crashed.

Example. Suppose I have a note like this,
test @abc and @pqr
1] Now if I start to remove mention @pqr first, then it will remove in one stroke
2] But when I start to remove mention @abc first, then app crashes. Please help if anyone is having the solution for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant