[TIP] How to ensure plain pasted text

Hugh Senior h at FlexibleLearning.com
Fri Oct 24 13:06:43 EDT 2008


  on commandKeyDown pKey
    if pKey = "V" then
      set the htmlText of the templateField to the clipboardData["HTML"]
      if the autoTab of the selectedField then
        get the text of the templateField
        replace RETURN with SPACE in it
        set the text of the templateField to it
      end if
      set the clipboardData["TEXT"] to the text of the templateField
      reset the templatefield
    paste
    else pass commandKeyDown
  end commandKeyDown

> I'm sure your handler will come in useful, but out of interest,
> would the Edit menu item "Paste Unformatted" not take care of
> many of the cases?

Not if you have a standAlone and/or are rolling your own, Colin.


> on commandKeyDown theKey
>    if theKey is "V" and the selectedField is not empty then
>      lock screen
>      paste
>      put the text of the selectedField into the selectedField
>      unlock screen
>    else
>      pass commandKeyDown
>    end if
> end commandKeyDown

Elegant, Mark, but you would also need to track the insertion point (easily
done), and it would not handle any pre-existing user-formatted styles (which
I grant you was not part of the exercise but pasting text that defaults to
hard-wired Helvetica 14pt is a royal pita).


> I'm not sure this holds true for win or linux (or older rev versions
> then 2.8.1), but on mac os x, when there's styled text in the
> clipboard, both the html and the text values of the clipboarddata
> array hold their respective value.
>
> Therefore this proved sufficient in one of my projects:
>
> on commandKeyDown Vkey
>    if Vkey = "v" then
>      put the clipboardData["text"] into the selection
>    end if
> end commandKeyDown

I believe independent arrays on OSX, as with other platforms, are not
supported and changing one will change the others to suit, BvG. You would
also lose any paragraph returns, I think.

/H




More information about the use-livecode mailing list