go to the prev or next char of a scrolling fld automaticaly

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

go to the prev or next char of a scrolling fld automaticaly

Post by jmburnod » Sun Mar 21, 2010 12:41 pm

Hi All,

I need go to the prev or next char of a scrolling fld automaticaly
You can see the script for prev char

I need also go to the prev or next "visible" line of the same scrolling fld (not list)

Someone have a good idea ?

Code: Select all

local DelaiSelPrevChar,depTime,depChar,LeFld
on mouseUp
   put 30 into DelaiSelPrevChar
   put the ticks into depTime
   put the selectedchunk into bufCC
   put word 2 of bufCC into depChar
   put "LeTexte" into LeFld				
   SelPrevCharFE
end mouseUp

on SelPrevCharFE
   if the optionkey is down then
      select before char depChar of fld LeFld
      exit to top
   end if
   if the mouse is down then
      select before char depChar of fld LeFld
      exit to top
   end if
   if the ticks > depTime+DelaiSelPrevChar then
      subtract 1 from depChar
      select  char depChar of fld LeFld
      put the ticks into depTime
   end if
   send SelPrevCharFE to me in 100 milliseconds
end SelPrevCharFE
Best

Jean-Marc
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: go to the prev or next char of a scrolling fld automaticaly

Post by bn » Sun Mar 21, 2010 9:59 pm

Jean-Marc,
jmburnod wrote:I need go to the prev or next char of a scrolling fld automaticaly
what do you mean, do you want to hilite the line, do you want only work on the "visible" lines.
Could you explain a little?
regards
Bernd

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

Re: go to the prev or next char of a scrolling fld automaticaly

Post by jmburnod » Mon Mar 22, 2010 9:58 am

Hi Bernd,
It is OK for the prev or next char

I want to allow the user to go back up in the lines of one field (no scrolling, not really line) as if I type on arrowkeyUp with textArrows = true

Sorry for my fancy english

Jean-Marc
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: go to the prev or next char of a scrolling fld automaticaly

Post by bn » Mon Mar 22, 2010 5:57 pm

Jean-Marc,
as far as I understood you want something you did for the next and prev char, except now you want to select a char in the preceding or following line.
So if you select char 4 of line 10 you would then select char 4 of line 11 or char 4 of line 9. If this is correct then you might try this code. It is a bit rough, but works in my limited testing. Could be adapted to your needs. If you had something completely different in mind, please say so.
This is code for going up and for going down, just block/unblock the pertaining line "SelCharInLineBefore" or "SelCharInLineAfter" in the mouseUp handler.

Code: Select all

local DelaiSelPrevChar,depTime,depChar,LeFld, sLineSelected, sSoManyCharsInLIne, sTotalLines

on mouseUp
   put 30 into DelaiSelPrevChar
   put the ticks into depTime
   put the selectedChunk into bufCC
   
   put word 2 of bufCC into depChar
   put word 2 of the selectedLine into sLineSelected
   if sLIneSelected = ""  then exit to top -- field is not selected
   put "LeTexte" into LeFld
   
   lock screen
   -- to find out how many chars in field up to char 1 of the selectedLine
   select  char 1 of line sLineSelected of fld LeFld --of field LeFld
   put word 2 of the selectedChunk into tCharsToStartOfLIne
   
   -- now we know which char in the line was selected
   put depChar - tCharsToStartOfLIne into sSoManyCharsInLIne
   put word 2 of bufCC into tStartChar
   -- restore selection
   select before char tStartChar  of field LeFld
   unlock screen
   
   put the number of lines of field LeFld into sTotalLines
   
   SelCharInLineBefore -- for char in previous line before
   --SelCharInLineAfter -- for char in next line
end mouseUp

on SelCharInLineBefore
   if the optionKey is down then
      select before char sSoManyCharsInLIne of line sLineSelected of fld LeFld
      exit to top
   end if
   if the mouse is down then
      select before char sSoManyCharsInLIne of line sLineSelected of fld LeFld
      exit to top
   end if
   if the ticks > depTime+DelaiSelPrevChar then
      subtract 1 from sLineSelected
      if sLineSelected >= 1 then
         select  char sSoManyCharsInLIne of line sLineSelected of fld LeFld
         put the ticks into depTime
      else
         select before char sSoManyCharsInLIne of line sLineSelected + 1 of fld LeFld
         exit to top
      end if
   end if
   send SelCharInLineBefore to me in 100 milliseconds
end SelCharInLineBefore

on SelCharInLineAfter
   if the optionKey is down then
      select before char sSoManyCharsInLIne of line sLineSelected of fld LeFld
      exit to top
   end if
   if the mouse is down then
      select before char sSoManyCharsInLIne of line sLineSelected of fld LeFld
      exit to top
   end if
   if the ticks > depTime+DelaiSelPrevChar then
      add 1 to sLineSelected
      if sLineSelected <= sTotalLines then
         select  char sSoManyCharsInLIne of line sLineSelected of fld LeFld
         put the ticks into depTime
      else
         select before char sSoManyCharsInLIne of line sLineSelected - 1 of fld LeFld
         exit to top
      end if
   end if
   send SelCharInLineAfter to me in 100 milliseconds
end SelCharInLineAfter
regards
Bernd

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

Re: go to the prev or next char of a scrolling fld automaticaly

Post by jmburnod » Tue Mar 23, 2010 9:30 am

Bernd,

Thank one more for help
I tested your script.
It work in a scrolling field with dontWrap = true but i need go the the previous "visible" line in a scrolling field with dontWrap = false

Jean-Marc
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: go to the prev or next char of a scrolling fld automaticaly

Post by bn » Tue Mar 23, 2010 4:08 pm

Jean-Marc,

I changed the script. But it is a little more involved now. I wanted to preserve any formatting in the text like color and so on. I did not find an easier way then I put in the attachment. It is very heavily commented, which I hope helps understanding what I am doing there. The two buttons have the same script, one goes up, one goes down.
regards
Bernd
Attachments
leTexteIII.rev.zip
(3.27 KiB) Downloaded 241 times

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

Re: go to the prev or next char of a scrolling fld automaticaly

Post by jmburnod » Tue Mar 23, 2010 11:48 pm

Hi Bernd,
Good work. Many thank (noch einmal one more)
I tested and it work fine with line contains a return char, it will early useful like that
For the next step, i find the same behavior for the visible line (without return char)
I tried by the selectedLoc but it not word realy at this moment.

all the best

Jean-Marc
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: go to the prev or next char of a scrolling fld automaticaly

Post by bn » Wed Mar 24, 2010 12:34 am

Hi Jean-Marc,
glad it works.
For the next step, i find the same behavior for the visible line (without return char)
I tried by the selectedLoc but it not word realy at this moment.
I dont get the selectedLoc part. Could you restate that in french/english, I am afraid I dont get it.
Please tell me if you find anything that works unexpectedly.
Or you could write in french to niggemann at uni - wh . de without spaces and replacing the at.
regards
Bernd

Post Reply