Git Product home page Git Product logo

Comments (12)

michaelbina avatar michaelbina commented on June 7, 2024

I'm looking to do the same. I want to remove the "@" in mentions. If you have any insight, please share.

from activelabel.swift.

polqf avatar polqf commented on June 7, 2024

I have planned to implement smth like this for URLs. I'll try to think in this use case when I implement it

from activelabel.swift.

longbowww avatar longbowww commented on June 7, 2024

@poolqf so that means it is basically impossible atm because you are just using the original text as read only property?

while playing around inside createMentionElements() I could at least modify the range that gets highlighted

from activelabel.swift.

polqf avatar polqf commented on June 7, 2024

Hi @longbowww , I was trying to add this feature last weekend, but it was not as easy as I thought. Requires replacements in the text, and doing it in an specific order. If you have any better idea, feel free to share it 😄 !

from activelabel.swift.

juanjold avatar juanjold commented on June 7, 2024

Hi @longbowww, @poolqf I'm actually trying to implement the same thing as you. Have you come with a solution? How were you thinking about going at it? I'm just about to get started with it so any ideas would be great. Thanks!

from activelabel.swift.

polqf avatar polqf commented on June 7, 2024

Hi @juanjold , my approach was:

  • ActiveType has 2 parameters, one for the trimmed word, and another one for the original
  • While in the parsing, remove the extra characters from each word
  • Replace the words in the label's text with the trimmed ones

All this things have to be done taking a lot of care of the ranges. Otherwise it is really easy to make it crash. The correct way to do it would be doing it backwards, that way the previous word's ranges are still the same even if you replace a word, due that it is in a higher range location.

That's all the ideas I came up, I'll try to work on in whenever I find time. Would be really happy to help you if you have time to start working on it.

from activelabel.swift.

longbowww avatar longbowww commented on June 7, 2024

@juanjold @poolqf The way you put it was also my approach to tinker with Active Type.

In my case it is quite easy to find mentions as it follows a specific regex pattern, unfortunately I am not that familiar with TextStorage but could it be possible to set a 3rd parameter much like word that keeps track of what should be removed?

So basically I was trying to also find my way around with my original string and then decide on base of the mention range what to cut off (in my case i know that it is either 29/30 characters)

All that worked, but as soon as i start cutting off stuff I get all messed up inside the UITableViewCell rendering cycle and the library trying to detect mentions.

That was why I was asking when it would be best to step in.

Lets say we got:
String -> TableViewCell Label -> TextStorage? -> ActiveLabel parsing -> TextStorage?

I get caught up inside the last 2 parts when I try to modify word/range as it will then no longer detect the regex as valid and therefore drop the mention.


As a bottom line my idea also would be:

  1. get initial string
  2. detect mentions inside this string
  3. delete mention ranges from string and keep track ? in a dict? where we deleted what
  4. create ActiveType mentions, insert them again with either original string or modified string
  5. decide on what/where to update TextStorage depending on ActiveType returns and original mention dict from string

I hope this is remotely understandable :D

from activelabel.swift.

michaelbina avatar michaelbina commented on June 7, 2024

Anyone ever get this figured out? I made a kinda hacky version that removes the "@" symbol on mentions and bolds the name but leaves a space where the @ was. I found it extremely difficult to remove that space properly and have all the formatting move along with it. Looks like @longbowww outlined a possible solution but I wanted to see if anyone else has taken a crack at it before I try again.

from activelabel.swift.

polqf avatar polqf commented on June 7, 2024

This is done

from activelabel.swift.

michaelbina avatar michaelbina commented on June 7, 2024

@poolqf - How would removing the @ in mentions happen then? I don't see a config for something like that.

from activelabel.swift.

polqf avatar polqf commented on June 7, 2024

@michaelbina , my fault. I read it too quickly. This is not done.

BTW, it is not on our roadmap to be honest

from activelabel.swift.

Xabchinsk avatar Xabchinsk commented on June 7, 2024

In my case i just used invisible unicode character (u2063) with custom pattern, like this
static let purePattern = "(?:^|\s|$)\u{2063}[\p{L}0-9_]*"

from activelabel.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.