Skip to content

Instantly share code, notes, and snippets.

@toomasv
Created February 13, 2019 09:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toomasv/6a65fadaf09ddf91810ee8e878160b8f to your computer and use it in GitHub Desktop.
Save toomasv/6a65fadaf09ddf91810ee8e878160b8f to your computer and use it in GitHub Desktop.
Drag words from area to text-list experiment
Red [
Author: "Toomas Vooglaid"
Date: 13-Feb-2019
Purpose: {Example of dragging words from area to text-list}
]
count-nl: func [face /local text n x][
n: 0 x: face/selected/x
text: copy face/text
while [all [
text: find/tail text #"^/"
x >= index? text
]][
n: n + 1
] n
]
view [
tl: text-list data []
on-drop [props event]
ar: area {This is example of
dropping words from
area to a text-list.
Area text can be changed
only initially.
Later changes may drive
it crazy :(} focus
on-change [system/view/platform/redraw face]
on-select [
if face/selected [
s: face/selected
nls: either system/platform = 'Windows [
count-nl face
][0]
t0/text: tx/text: copy/part at face/text s/1 - nls s/2 - s/1 + 1
tx/offset: face/offset + (caret-to-offset face s/1 - nls) + (as-pair 6 3 - nls)
tx/size: (size-text t0) - 4x3
unless tx/visible? [tx/visible?: yes]
]
]
at 0x0 t0: text hidden
at 0x0 tx: text hidden loose 0.120.215 white ;hex-to-rgb #0078d7
on-drop [
if within? face/offset tl/offset tl/size [
append tl/data tx/text
]
tx/visible?: no
ar/selected: none
set-focus ar
]
do [t0/size: ar/size]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment