Unhiliting selected text in a field

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
WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Unhiliting selected text in a field

Post by WaltBrown » Fri May 22, 2009 3:01 pm

Hi again, another noob question.

I have a field of text a user is working on. I have two problems.

1. I can't seem to find a field property that lets the user drag (mouseDown) across a phrase and visibly hilite it (like using a hiliter pen). Instead it sets the foreground color to the background color (making the text invisible) and underlines the selection with whatever color I have set the Hilite property to while they are dragging. I can't seem to find the right combination of properties in the Object Properties window to make this happen. I can set it after the fact using a script of course, but that doesn't help while they are dragging.

My question here is "Is it possible through Object Properties to make a field act like it is being hilited while the action is occuring?"

2. Then when the user is done, I want to reset all the hilites in the field by using:

set the backgroundcolor of field fInField to "white"
set the foregroundcolor of field fInField to "black"

This only sets the backgroundcolor in areas that don't already have text in them. I am using different color hilites to mark different contexts in a document, so the field gets quite messy in the process.

My question here is "Is there a simple way, without going word to word, to reset the various hilites I have in a field?"

3. So I tried using a "repeat for each word" but this returns the word, not it's chunk description. This brings on my third question, which I am sure is in the documents but I just can't find it.

"Is there a way to use repeat for each word and return the chunk description ("char 132 to char 168 of field 4" for example) rather than the chunk contents, so I can test or reset the text properties of that chunk?"

Or even better, go through and return each chunk hilited a certain way, as in:

repeat for each chunk with backcolor "255,255,0"

Thanks again.
Walt Brown
Omnis traductor traditor

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

Post by bn » Fri May 22, 2009 6:38 pm

Walt,

you say
I have a field of text a user is working on
Is the user entering text or is the text locked, and the user edits the highlighting of the text according to some scheme?

If you have the text locked and the user is just editing the hiliting then you could put something like this into the script of the field

Code: Select all

on mouseUp -- user dragged and hilited some text
    put the selectedchunk into tText
    set the foregroundcolor of tText to red
end mouseUp

on mouseDoubleUp -- double clicking on a word
    put the mousechunk into myChunk
    if myChunk is not empty then
        select myChunk
        set the foregroundcolor of myChunk to blue
    end if
end mouseDoubleUp

if the text of the field is editable then you could put something like this into a button

Code: Select all

on mouseUp pMouseBtnNo
    put the selectedchunk of field 1 into tSelected
    set the foregroundcolor of tSelected to green
    set the backgroundcolor of tSelected to yellow
end mouseUp
to reset all text hiliting you could put this into a button:

Code: Select all

on mouseUp
    set the foregroundcolor of char 1 to -1 of field 1 to black
    set the backgroundcolor of char 1 to - 1 of field 1 to white
end mouseUp
Or do you mean something different alltogether?
(never mind the colors I used, I am not really colorblind... :) )
regards
Bernd

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Post by WaltBrown » Sat May 23, 2009 1:31 am

Thanks Bernd. I am looking at before the event occurs - how can I change the highlighting as the user is dragging across the locked text, before they release the mouse.

Thanks,
Walt
Walt Brown
Omnis traductor traditor

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

Post by bn » Sat May 23, 2009 9:25 am

Walt,

I see two options, the easy one:

Code: Select all

on mouseStillDown
    put the selectedchunk into tText
    set the foregroundcolor of tText to red
    -- you could also set the backgroundcolor
    -- set the backgroundcolor of tText to black
end mouseStillDown

on mouseUp
    -- to remove the remnants of the selection 
    select after char (word 4 of the selectedchunk of me) of me
end mouseUp
in the script of the field.

another option in the script of the field is a little more responsive and as an option in Rev a very powerful: send in time. Basically as long as a handler is runnign Rev can not do anything else. A long repeat handler is locking effectively everything up. But with a send in time construct you give Rev the time to do its housekeeping and you allow user input (like clicking a button) Sounds complicated but is actually quite simple as in this handler for the field script:

Code: Select all

on mousedown
    send checkforHilite to me in 2 milliseconds
end mousedown

on checkforHilite
    if the mouse is down then
        put the selectedchunk into tText
        set the foregroundcolor of tText to red
        send checkforHilite to me in 2 milliseconds
    else
          -- to remove visual remnants of the selection
          select after char (word 4 of the selectedchunk of me) of me
   end if
end checkforHilite
the send in time is a little more then is needed here but to try it out is a nice opportunity.
regards
Bernd

Post Reply