Page 1 of 1
How to delete the selected text
Posted: Mon Dec 28, 2009 8:24 am
by alemrantareq
Hi everybody, I need a help. I have some contents in a scrolling field and I want to delete the selected from that list. I've tried a lot through delete, clear, put empty commands and also selectedtext, selection, selectedline and selectedchunk functions to do that but failed.
Code: Select all
on mouseUp
put the selectedtext of fld "asd" into myvar
delete myvar
end mouseUp
and also -
Code: Select all
on mouseUp
put the selectedtext of fld "asd" into myvar
put empty into myvar
end mouseUp
But all have failed. How to do that? Please help...
Re: How to delete the selected text
Posted: Mon Dec 28, 2009 9:56 am
by Peter Wood
I tried this with a scrolling field called Field, putting the script in a Button, it worked for me:
Code: Select all
on mouseUp
delete the selectedText of field "Field"
end mouseUp
Re: How to delete the selected text
Posted: Mon Dec 28, 2009 12:45 pm
by sturgis
try
put empty into the selectedText of field "Field"
Re: How to delete the selected text
Posted: Mon Dec 28, 2009 2:07 pm
by alemrantareq
Before my posting, I've tried all of these codes. And after your replies, I've tried both of them again renaming my field "asd" to "Field". But failed again. I tried this -
on mouseUp
delete the selectedText of field "Field"
end mouseUp
And got this error -
button "Button": execution error at line 2 (Handler: can't find handler) near "the", char 4
Then I tried this one -
on mouseUp
put empty into the selectedText of field "Field"
end mouseUp
And got this error -
button "Button": execution error at line 2 (Chunk: no target found), char 14
I'm using rev ent. 4. As far as I know, the aboves should work; but I'm afraid why they don't?
Re: How to delete the selected text
Posted: Mon Dec 28, 2009 3:04 pm
by bn
Alemantareq,
if you are on windows I think the field looses focus if you click a button. This is not the case on the mac.
To catch this put this into the field
Code: Select all
on focusOut -- for locked text fields
set the cLastSelection of me to the selectedChunk
end focusOut
on exitfield -- for editable fields
set the cLastSelection of me to the selectedChunk
end exitfield
this way you make a custom property of the field that gets filled with the last selection. This custom property you can access from your button.
Something like
Code: Select all
on mouseUp
put the cLastSelection of field 1 into mySelection
if word 4 of mySelection < word 2 of mySelection then exit mouseUp -- no text selected, just the insertion mark is in the field
put the number of lines of char 1 to (word 2 of mySelection) of field 1 into tNumOfLines -- find out how many lines up to the begin of the selection
delete line tNumOfLines of field 1
end mouseUp
If this is the problem then I can not really test it because I dont have access to a windows computer. You might want to experiment with this a bit.
Regards
Bernd
Re: How to delete the selected text
Posted: Mon Dec 28, 2009 4:35 pm
by alemrantareq
Yes, I'm using windows xp and its the text locked field. Thanks Bernd for your reply but it doesn't work for me. Oh ! its really making me disappointed.
Re: How to delete the selected text
Posted: Mon Dec 28, 2009 5:35 pm
by sturgis
Here just do it like this
and it should work. I always forget that selectedText is its own container.
edit: at least this works on my win2k, don't have other test beds available.
Re: How to delete the selected text
Posted: Mon Dec 28, 2009 5:53 pm
by alemrantareq
Thanks a lot sturgis; your correction really works

Re: How to delete the selected text
Posted: Tue Dec 29, 2009 12:29 pm
by alemrantareq
Putting empty into the selectedText deletes the text but that line turns to an empty line and still exists. Is there any way to delete that empty line?
Re: How to delete the selected text
Posted: Tue Dec 29, 2009 6:38 pm
by sturgis
My apologies, I thought you were trying to delete part of a line that had been selected IE removing a portion of the text. If you just want to remove all hilited lines in a list field you can do this.
Code: Select all
on mouseUp
repeat for each item tLine in the hilitedLines of field "Field"
delete line tLine of field "Field"
end repeat
end mouseUp
Re: How to delete the selected text
Posted: Wed Dec 30, 2009 4:36 am
by alemrantareq
Using repeat loop was in my mind but I didn't try it thinking that it'd not work as the selectedLine, selectedText of fld "Field" had failed.
However, Thanks a lot (u r great

)
Re: How to delete the selected text
Posted: Tue Jan 05, 2010 1:16 am
by SparkOut
A slight variation may be required if you are deleting multiple lines, as when you delete the first line in the list, then every other line below it will be shuffled up one line, and the next delete will be offset by a line, and that can compound over the repeat loop too. If you sort the hilitedLines list first, so that you delete the highest line number then the next highest, etc, each line number in the list will still match the original selection:
Code: Select all
on mouseUp
put the hilitedLines of field "Field" into tLines
sort tLines descending
repeat for each item tLine in tLines
delete line tLine of field "Field"
end repeat
end mouseUp
HTH
SparkOut
Re: How to delete the selected text
Posted: Tue Jul 24, 2018 8:33 am
by Simon Knight
When applying this excellent tip in LC 9 I had to specify that the items were the subject of the sort e.g.
Code: Select all
put the hilitedLines of field "FullList" into tLines
sort items of tLines descending
repeat for each item tLine in tLines
delete line tLine of field "FullList"
end repeat
Re: How to delete the selected text
Posted: Tue Jul 24, 2018 8:59 am
by jmburnod
Hi,
Is there any way to delete that empty line?
Code: Select all
filter fld "myField" without empty
works (LC 9, OS X 10.13)
Best regards
Jean-Marc