Unexpected results when deleting a blank line from a list field
Posted: Sun Jul 30, 2023 9:21 am
My application has a list field and I want the user to be able to edit its contents. I found this post "Click, Pause, Click Again to Edit a Line in a Field?" and used the simple code by dunbarx in my list field.
It works but is exhibiting an odd feature: when in edit mode the list field reverts to being a normal field but becomes a list field once the mouse leaves the field. When editing its possible to in effect delete whole lines by using the delete key, this is desirable but the user may fail to delete the New Line character meaning that the line appears as a blank row in the list. Once back in list mode these rows may be selected but deleting them has thrown up an oddity. I use the following code, in a button, to delete a single selected row from the list :
While this works on lines that contain text it fails on lines that are just the newline character. The reason appears to be that hilitedline fails to return a line number.
I know this because in order to discover that no line number is returned I added a line of code to answer the value :
This prints a blank line but then the selected line does get deleted from the list.
I also note that if I try to add blank lines above text lines using the inspector in the IDE the IDE pauses then removes them.
So what obvious thing am I missing ?
I have created a stack that shows the issue.
best wishes
Simon
Code: Select all
on selectionChanged
--answer the selectedtext of field "ServerList"
--answer the hilitedLine of field "ServerList"
set itemdel to "/"
put the last item of the folder into tFolderName
put the selectedtext of me into tText
set itemdel to cr
put item 1 of tText into tText
put tText into field "AddMe"
put tText & "/" & tFolderName into field "SelectedServer"
end selectionChanged
on mouseup
wait 15 milliseconds
// mouseclick goes true if user makes second click
if the mouseClick then
set the locktext of me to "false"
set the listbehavior of me to "false"
Beep
end if
end mouseup
on mouseLeave
set the locktext of me to "true"
set the listbehavior of me to "true"
end mouseLeave
Code: Select all
on mouseUp
delete Line (the hilitedLine of field "ServerList") of field "ServerList"
end mouseUp
I know this because in order to discover that no line number is returned I added a line of code to answer the value :
Code: Select all
on mouseUp
-- Delete the selected line
answer the hilitedLine of field "ServerList"
delete Line (the hilitedLine of field "ServerList") of field "ServerList"
end mouseUp
I also note that if I try to add blank lines above text lines using the inspector in the IDE the IDE pauses then removes them.
So what obvious thing am I missing ?
I have created a stack that shows the issue.
best wishes
Simon