Page 1 of 1

selection color and background color

Posted: Thu Oct 29, 2009 7:42 pm
by Steve
It appears that when the user is selecting text that has a background color, the "selection color" in behind the text's "background color", making it difficult to see what is being selected. I can make it a little more visible by making the line spacing very large.

But, is there any way to make the "selection color" be on top of the text's background color?

Thanks,

Steve

Posted: Thu Oct 29, 2009 8:36 pm
by bn
Steve,
is this for a locked field or an editable field.
I have not found a way to make the selection color go before the backgroundcolor of a text. But you can set the the backgroundcolor of the selection to something else then the backgroundcolor already in place.
It also depends on how many different backgroundcolors you want in your text.
here is some code to select some text and that selection will have a yellow backgroundcolor. If you select again then the selection will be green and then turn the selected text into a yellow backgroundcolor.
This is basically from the thread:
http://forums.runrev.com/phpBB2/viewtop ... ght=#18045
(the code is a little different from the one I posted there so I will post it here again slightly altered/improved)
make a stack with a text field, locked called "text2" which holds the data you want to mark, make a text field "output" for the selected text, and a text field "fRaw" if you want to see the raw data that is worked on.
This was mainly to provide a list of the text of the selections in a field in the order in which it was in the original text, not in the order of the selection. But you can throw all that stuff out easily if you dont need it.

Code: Select all

local hiliteCounter, hilitedList, tGreen

on mouseDown
   put true into tGreen --start the mouseMove handler
end mouseDown

on mouseMove
   if tGreen then
      lock screen
      -- sets the backgroundcolor on the fly
      -- see further down for comments in the handler
      colorBgOfMe
      set the backgroundcolor of the selectedChunk to green
      unlock screen
   end if
end mouseMove

on mouseUp 
   put false into tGreen -- stop the mouseMove handler
   
   if the optionkey is down then -- resets all if Alt-Key or Option-Key is down
      set the backgroundcolor of char 1 to -1 of me to ""
      --set the foregroundcolor of char 1 to -1 of me to ""
      put 0 into hiliteCounter
      put "" into hilitedList
      put "" into field "output"
      lock messages
      click at the topleft of me
      exit mouseUp
   end if
   
   put hiliteCounter+1 into hiliteCounter 
   put word 2 of the selectedChunk into tStartChar 
   put word 4of the selectedChunk into tEndChar 
   put tStartChar && tEndChar
   
   -- if the user clicks before the first word it selects the whole text
   if  tEndChar = 0 then exit mouseUp
   
   put "1234567890.,¿!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'-ä" into tTestString
   
   -- take the text of field "text2" into a variable tTest to speed things up
   put field "text2" into tTest
   
   put false into tFoundStart 
   repeat until tFoundStart = true 
      put char tStartChar of tTest into tChar 
      if tChar is not in tTestString then 
         put true into tFoundStart 
      else 
         subtract 1 from tStartChar 
      end if 
   end repeat 
   
   put false into tFoundEnd 
   repeat until tFoundEnd = true 
      put char tEndChar of tTest into tChar 
      if tChar is not in tTestString then 
         put true into tFoundEnd 
      else 
         add 1 to tEndChar 
      end if 
   end repeat 
   
   put tStartChar && tEndChar
   
   set backgroundcolor of char tStartChar+1 to tEndChar-1 of field "Text2" to yellow 
   
   put char tStartChar+1 to tEndChar-1 of tTest into tReplaceReturns
   
   -- take returns out so it won't break the lines of the hilitedList
   replace return with "|" in tReplaceReturns
   
   put tStartChar+1 & " " & tReplaceReturns into line hiliteCounter of hilitedList
   sort hilitedList numeric
   
   -- we leave the hilitedList alone and work on a copy of it
   put hilitedList into tListToClean
   repeat with i = 1 to the number of lines of tListToClean
      delete word 1 of line i of tListToClean
   end repeat
   -- remove empty lines
   filter tListToClean without empty
   -- put the returns back in
   replace "|" with return in tListToClean
   
   -----
   -- look into the comments of this command further down
   colorBgOfMe
   ------
   put hilitedList into field "fRaw"
   put tListToClean into field "output"
   select after char tEndChar of me -- to avoid stray selectioncolor remnants
end mouseUp 

private command colorBgOfMe
   -- here we recolor the selected text to yellow backgroundcolor
   -- because if user selects forward and backwards in one move
   -- there would be green selection remnants
   lock screen
   set the backgroundcolor of char 1 to -1 of field "text2" to ""
   repeat for each line aLine in hilitedList
      put the length of word 1 of aLIne into tIndexLength
      put the length of aLine into tLineLength
      if tIndexLength + 1 = tLineLength then next repeat
      set backgroundcolor of char (word 1 of aLine) to (word 1 of aLine + tLineLength - tIndexLength -2) of field "text2" to "yellow"
   end repeat
   unlock screen
   -- end of recolorisation
end colorBgOfMe
put this code into text field "text2", the one with the text you mark.


regards
Bernd

Posted: Fri Oct 30, 2009 1:08 am
by Steve
Thanks, that seems to work well. Yes, this is for a locked field.

Doesn't it seem strange, though, that the system would put the change in color for "selecting text" underneath the text's background color?

Thanks again for the help.

Sincerely,

Steve