The default settings of a text field allow content of a different font and font size to be pasted into the field. How do I make sure that pasted content is converted to use a specific font and font size, i.e. the one I choose as default for the field?
Asked
Active
Viewed 116 times
1 Answers
2
You need to trap the paste from happening, then replicate it yourself. For example in a field (untested):
on pasteKey
put the clipBoardData["text"] into char (word 2 of the selectedchunk of me) to (word 4 of the selectedchunk of me) of me
end pasteKey
You also need to care about drag & drop:
on dragDrop
put the dragData["text"] into char (word 2 of the dropChunk) to (word 4 of the dropChunk) of me
end dragDrop
If you use the "paste" command, it will not trigger the pasteKey message, so if you have such code in your app, so you need to make sure to handle special cases there.
Note: Testing this in the IDE can be tricky, because it interrupts some messages, including pasteKey (use "suspend development tools" from the "development" menu).

BvG
- 425
- 3
- 3
-
What does the char `(word 2 of the selectedchunk of me) to (word 4 of the selectedchunk of me) of me` mean? I just want to insert the clipboard text as the insertion point of the field. – z-- Apr 19 '13 at 10:37
-
Isn't there a simpler solution by setting properties of the field? – z-- Apr 19 '13 at 10:41
-
The suggested solution does not work. Neither with the on pasteKey handler on the field level nor on the card level. – z-- Apr 19 '13 at 20:14
-
1@BvG did say that it won't work in the IDE because it traps and doesn't pass pasteKey. If you already formatted text that has been pasted in then you can `set the text of fld X to the text of fld X` – Monte Goulding Apr 19 '13 at 20:37
-
1I have added `set the text of me to the text of me` to the pasteKey handler and put the handler on the field level. Now it works when selecting "suspend development tools" from the "development" menu. – z-- Apr 20 '13 at 04:24
-
@Hannes Just to make it clear, using `the selectedChunk` like that is one way to put stuff into the current selection. I agree that is a bit wordy, but I've had mixed results with other approaches, like setting `the selection`. Using `set the htmltext of me to the text of me` is smart, because it also replaces rich text that sneaked trough somehow. – BvG Apr 22 '13 at 17:34