caretPosition removes <br> tags

Workarounds and usability notes.

Re: caretPosition removes <br> tags

Postby John Robin Dove » Tue Jan 21, 2025 10:45 am

Hi Clifton,
Thanks for your reply. Are you sure you still have a problem creating colored words at the end of the sentence? I have been trying to reproduce this error but so far I have not been able to. The period at the end of the sentence is always removed, if that was the problem perhaps? I have put the latest test version here https://www.mediacours.com/tb_examples/parasLatest/ It is different because you have to press the Enter key now and all the colored words will be red because they're easier to see like that.

You didn't reply about this:
txt = tbfunction_pgReplace("&lt;", "<", txt, true);
txt = tbfunction_pgReplace("&gt;", ">", txt, true);

It works but seems a bit clunky to me.
John Robin Dove
 
Posts: 538
Joined: Thu Jan 23, 2014 4:35 am

Re: caretPosition removes <br> tags

Postby Clifton » Tue Jan 21, 2025 12:07 pm

When I put try and make a link from the #. at the end of a sentence, I get the alert, but nothing else happens and the item does not become red. In some ways, you may want to see what I was able to put together even if it is far from complete. I was testing a number of other things using your example to ensure the integrity of caretPosition().

Regarding your use of pgReplace for &lt; and &gt;, what you are doing is fine, but conversions like this are automatic if you grab the textContent property of the object.
   var txt = gTBo( "myText2", "objRef").textContent;   //[txt] will yield raw text with extended HTML characters converted for you

The only issue is that you may lose your line breaks. 

UPDATE: When I ran your link again, it does indeed make the hotlink for the number at the end of the sentence. Maybe a browser cache issue was causing the previous anomaly.
Clifton
Site Admin
 
Posts: 781
Joined: Tue Jan 14, 2014 1:04 am

Re: caretPosition removes <br> tags

Postby John Robin Dove » Thu Jan 23, 2025 10:40 am

Epilogue At least I hope that's what it is! Unfortunately you were right the first time. In certain circumstances, it was not possible to make a hotword for the last word. There were also other bugs, some of which were catastrophic. However, I'm pretty sure that I have a system that works 100% now. I've tried to produce bugs for about about an hour now but haven't seen any. I have put a zip here: https://www.mediacours.com/tb_examples/parasNew.zip should you have time to have a look. It was very much a case of trial and error; the code is pretty messy and I don't even understand how some of it works! But I think it does. I have changed the instructions once again, you have to click on the 'Create link' button twice now. I've put a demo here: https://www.mediacours.com/tb_examples/parasNew
John Robin Dove
 
Posts: 538
Joined: Thu Jan 23, 2014 4:35 am

Re: caretPosition removes <br> tags

Postby Clifton » Fri Jan 24, 2025 12:06 am

I was sure there must be an easier way, so I put together this example. It may or may not do what you want, but it seems very similar to what you are trying to achieve. Plus, this uses a fraction of the code. In addition, I am not sure making the contentEditable is necessary, but this example preserves this property. It has the side effect of allowing the hotlink text to be changed by the user either before or after the link is created. I used your original selection.css so the hotlinks are randomly colored.

This may have a few bugs, but this initial example seems to work pretty good.

Here you go!
Attachments
source.zip
TBK v9.0 source and dependencies
(26.38 KiB) Downloaded 191 times
Clifton
Site Admin
 
Posts: 781
Joined: Tue Jan 14, 2014 1:04 am

Re: caretPosition removes <br> tags

Postby John Robin Dove » Fri Jan 24, 2025 3:46 am

Thanks very much. I'll let you know how I get on.
UPDATE It's looking good so far but where's the rest of the code? No, just kidding! :) The reduction in code is impressive to say the least. I'll try and implement it in my program now. Shouldn't be too difficult. Thanks again.
John Robin Dove
 
Posts: 538
Joined: Thu Jan 23, 2014 4:35 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron