Insert hyperlink at current cursor position

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Jochen
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 01, 2013 7:30 am

Insert hyperlink at current cursor position

Post by Jochen » Thu Apr 18, 2013 3:18 pm

Hello,
I'm really stuck trying to insert a hyperlink into a field at the current cursor position.

I use the following code to insert the text in the field:

Code: Select all

put "Link Title" after the selectedChunk
This works, as long as I'm not debugging. In that case it inserts the text into the script editor.

My questions are:
1. Is there a simple way to set the textStyle of the previously inserted text?
2. Is there a "debugger safe" way to get the selectedChunk? (put "Link Title" after the selectedChunk of field "xyz" doesn't work)

Any help is really appreciated.

Jochen

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Insert hyperlink at current cursor position

Post by jmburnod » Thu Apr 18, 2013 4:11 pm

1. Is there a simple way to set the textStyle of the previously inserted text?

Code: Select all

 set the textstyle of char tStart to tEnd of fld tFld to Plain
2. Is there a "debugger safe" way to get the selectedChunk? (put "Link Title" after the selectedChunk of field "xyz" doesn't work)
Take of "of field "xyz" and it should work

Code: Select all

put "Link Title" after the selectedChunk
I put a script playing with selectedchunk

Code: Select all

put "Link Title" into tNameLink
   put the selectedchunk into tSelC
    put the selectedtext into tSelT
   if tSelT = empty then exit DoMe -- No selection
   put the value of word 2 of tSelC into tStart
   put the value of word 4 of tSelC into tEnd
   put the value of word 7 of tSelC into tNumFld
   
   put tNameLink after char tEnd of fld tNumFld
   set the textstyle of char tStart to tEnd of fld tNumFld to Plain
   put the num of chars of tNameLink into tnbC
   set the textstyle of char (tEnd+1) to (tEnd + 1 + tNbc) of fld tNumFld to "link"
Best regards
Jean-Marc
https://alternatic.ch

Jochen
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 01, 2013 7:30 am

Re: Insert hyperlink at current cursor position

Post by Jochen » Fri Apr 19, 2013 8:08 am

Hello Jean-Marc,
thanks for your example. I still have to get used to the power of chunk expressions :)

Regarding my selectedChunk debugger problem. When I'm stepping through the code the selectedChunk always points to the current line inside the script editor, not the field I'm debugging.

My workaround for this is to copy the chunk into a variable and set the breakpoint after that line. This works but is not very intuitive.

Best regards,
Jochen

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Insert hyperlink at current cursor position

Post by jmburnod » Fri Apr 19, 2013 10:34 am

I Jochen,
I'm not sure I understand (someone can help us ?)
Regarding my selectedChunk debugger problem. When I'm stepping through the code the selectedChunk always points to the current line inside the script editor, not the field I'm debugging.
i believe you can't upload a stack before you have sent 10 post
If you have a little stack about this mistake you can send me it
"jmburnod" & "@" & "vtxnet" & dot & "ch"
Best regards
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Insert hyperlink at current cursor position

Post by dunbarx » Fri Apr 19, 2013 1:29 pm

Yipes. Confirmed here. I never saw this before. I wonder if it happens in Hypercard.

Given a field with some text in it and a button with:

Code: Select all

on mouseUp
   select after char 3 of fld 1
   put "xx" after the selectedChunk
end mouseUp
If you put a breakpoint in, say, the "select..." line, you will get "put "xx" after the selectedChunkxx" after you step through.

Running the script works as advertised.

EDIT:

In HyperCard, stepping through puts the text in the field, not in the script editor line.

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Insert hyperlink at current cursor position

Post by dunbarx » Fri Apr 19, 2013 2:11 pm

Well, this may not be a trivial thing.

Again, make a field with some text in it, and a button with:

Code: Select all

on mouseUp
   select after char 3 of fld 1
   get the selectedchunk
   
   put "XX" after it
   do "put XX after" &&  it
end mouseUp
Run, (do not step) through,with the following:

1- Comment out the "do" line, and nothing happens.
2- Comment out the "put" line, and the "xx" is inserted correctly in the field.
3- Comment nothing, and an error is thrown, because the variable "it" now contains the chunk reference, but with "XX" appended:

char 4 to 3 of field 1XX

Now you will debug, the offending line being the "do" line. The code in the script editor has been modified when this sequence runs. The variable "it" has had the "XX" appended to it, just as it did when the earlier code was stepped through (though not when it was run), and the "do" line therefore breaks.

How has this not popped up before?

Craig Newman

eaks

Jochen
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 01, 2013 7:30 am

Re: Insert hyperlink at current cursor position

Post by Jochen » Fri Apr 19, 2013 4:12 pm

Hello alltogether,
it seems that I'm good at finding bugs :D

I will send a bug report. At least it's not limited to my installation. I've also tested it with the evaluation version of LC 5.5.4. It also happens there.

Edit: The sample stack / bug report can be found here: http://quality.runrev.com/show_bug.cgi?id=10862

Best regards,
Jochen

Post Reply