Seems like no one's published a simple way to drag-reorder lines in a list field (at least not that I could easily find with a cursory search), so I thought I'd publish my version here. Here's how it can be done with only 14 lines of code:
Code: Select all
local lineText, lastPosition on mousedown put the value of the mouseline into lineText put the mouseline into lastPosition end mousedown on mousemove if the mouse is down and the mouseline is not lastPosition and the mouseline is not empty and word 2 of the mouseLine <= the number of lines of me then delete lastPosition if word 2 of the mouseline is the number of lines of me and the last char of me is not cr then put cr after me put lineText & cr before the mouseline put the mouseline into lastPosition select the mouseline end if end mousemove
About that, can anyone improve on this and make the code even shorter than mine? Here's what I suggest as criteria for submissions:
(1) Must show either the line of text being moved, or a marker between the lines where the dropped line will go when the mouse is released.
(2) Must not use repeat while the mouse is down, which is a no-no as it ties up the CPU.
(3) Must not ever mangle the text.
(4) Must not malfunction if the user moves the mouse pointer out of the list field (and possibly then back into the field) while the mouse is still down.
(5) Acceptable to drag a line to an unpopulated blank area (as in my example).
(6) Handler on and end count as lines, blank lines don't.