Drag and Drop Text into a field

Peter M. Brigham, MD pmbrig at gmail.com
Mon Sep 26 17:09:58 EDT 2011


On Sep 26, 2011, at 4:51 PM, Pete wrote:

> Thanks Peter, that sounds like it should work, I guess I'd assumed that LC
> would remember the selected text.
> 
> The dictionary says that if no text is selected, the end char part of the
> selectedChunk is less than the startchar so I guess I'll need to check for
> that so that a normal insert works.

No need. If you have an insertion point after char 5 of a field, the selectedchunk is <char 6 to 5 of fld "targetField">, and putting a text string into char 6 to 5 of fld "targetField" will insert the text after char 5 of the field, Ie, where the insertion point was.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


> On Mon, Sep 26, 2011 at 1:01 PM, Peter M. Brigham, MD <pmbrig at gmail.com>wrote:
> 
>> You could set a customprop of the field control on mouseleave:
>> 
>> on mouseleave
>>  set the uSelChunk of me to the selectedchunk
>> end mouseleave
>> 
>> then in your dragdrop handler:
>> 
>> put the uSelChunk of fld "targetField" into selCh
>> put word 2 of selCh into startChar
>> put word 4 of selCh into endChar
>> put the clipboardData["text"] into char startChar to endChar of fld
>> "targetField"
>> 
>> -- Peter
>> 
>> Peter M. Brigham
>> pmbrig at gmail.com
>> http://home.comcast.net/~pmbrig
>> 
>> 
>> On Sep 26, 2011, at 2:37 PM, Pete wrote:
>> 
>>> I'm trying to find a way to drag and drop text from a datagrid into a
>> field
>>> control.  If no text is selected in the field control, the text should be
>>> inserted at the insertion point; if text is selected, the dragged text
>>> should replace the selected text.
>>> 
>>> The way I'm doing this is:
>>> 
>>> - The dragStart handler for the datagrid places the text I want to insert
>>> into the clipboardData["text"]
>>> - The dragEnter handler for the field control sets the focus on the field
>>> control
>>> - The dragDrop handler for the field control issues a paste command
>>> 
>>> That all works fine when no text is selected in the field control, LC
>>> appears to remember where the insertion is in the field control.
>> However,
>>> let's say I select some text in the field control.  As soon as I click on
>> a
>>> line in the datagrid to start the drag/drop operation, the text is no
>> longer
>>> selected in the field control and when I drop the text into the field
>>> control it is inserted at what was the end point of the text I had
>>> originally selected.
>>> 
>>> To illustrate, if the field control contains "This is my Text" and I
>> select
>>> the word "my", then drag the text "your" to the field Control, it will be
>>> inserted right after "my" instead of replacing it.
>>> 
>>> Am I setting about this the wrong way or can this approach be made to
>> work
>>> somehow?
>>> 
>>> Thanks,
>>> 
>>> Pete
>>> Molly's Revenge <http://www.mollysrevenge.com>
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the Use-livecode mailing list