The incredible shrinking selections.

33 views
Skip to first unread message

Christopher Waterman

unread,
Nov 8, 2021, 1:14:24 AM11/8/21
to bbe...@googlegroups.com
If I select every occurrence of "whatsit" through which ever means.

Work file:

def do_something( doohickeis )
doohickeis.each do | whatsit |
whatsit.this!
whatsit.that!
print whatsit
end
end

Then run this AppleScript.

AppleScript:
tell window 1 of application "BBEdit"
set stuff to get selection
end tell

It returns a list like this.

List:
{characters 54 thru 60 of text document 1, characters 66 thru 72 of text document 1, characters 82 thru 88 of text document 1, characters 104 thru 110 of text document 1}

Thats great, but if I use that list to select those items again like this.

AppleScript:
tell window 1 of application "BBEdit"
set stuff to get selection
select stuff
end tell

Each selection will shrink by one character, from the right end of the selection. So characters 54 thru 60 will look like 54 thru 59 as so on through the list. This list as reported by AppleScript will not change the first time, but will if you run the script multiple times. The selections will shrink on every consecutive run until they're gone.

If I do the same thing with a contiguous selection (no lists involved just the range of characters) this doesn't happen.

What's going on here?

Thanks,
— Chris(topher)?



Christopher Stone

unread,
Nov 8, 2021, 4:40:41 AM11/8/21
to BBEdit-Talk
On Nov 08, 2021, at 00:14, Christopher Waterman <ch...@rustydogink.com> wrote:
If I select every occurrence of "whatsit" through which ever means.

...

Then run this AppleScript.

AppleScript:
tell window 1 of application "BBEdit"
set stuff to get selection
end tell

It returns a list like this.


Hey Christopher,

I don't see how you're getting a list of selected items.

If I use find with show matches it doesn't work.

If I use LiveSearch it doesn't work.

So how exactly are you doing your selection?


--
Best Regards,
Chris

jj

unread,
Nov 8, 2021, 8:55:15 AM11/8/21
to BBEdit Talk

Hi Christopher & Christopher,

Seems there is an off by one somewhere.

You should mail the issue to sup...@barebones.com.

Regards,

Jean Jourdain

tell application "BBEdit"

set vDocument to make new document with properties {contents:"def do_something( doohickeis )\ndoohickeis.each do | whatsit |\nwhatsit.this!\nwhatsit.that!\nprint whatsit\nend\nend\n"}

set vNeedle to "whatsit"

set vFoundObjects to {}

select insertion point before text of vDocument

repeat

set vResult to find vNeedle searching in vDocument options {starting at top:false, wrap around:false, search mode:literal, returning results:false} with selecting match

if (vResult's found) then

set end of vFoundObjects to vResult's found object

log {(vResult's found object) as string, vResult's found text, its selection as string}

else

exit repeat

end if

end repeat

select vFoundObjects

selection

end tell

-- Replies

tell application "BBEdit"

make new document with properties {contents:"def do_something( doohickeis )\ndoohickeis.each do | whatsit |\nwhatsit.this!\nwhatsit.that!\nprint whatsit\nend\nend\n"}

--> text document 1

select insertion point before every text of text document 1

find "whatsit" searching in text document 1 options {starting at top:false, wrap around:false, search mode:literal, returning results:false} with selecting match

--> {found:true, found object:characters 53 thru 59 of text document 1, found text:"whatsit"}

get characters 53 thru 59 of text document 1

--> "whatsit"

get selection

--> "whatsit"

(*whatsit, whatsit, whatsit*)

find "whatsit" searching in text document 1 options {starting at top:false, wrap around:false, search mode:literal, returning results:false} with selecting match

--> {found:true, found object:characters 63 thru 69 of text document 1, found text:"whatsit"}

get characters 63 thru 69 of text document 1

--> "whatsit"

get selection

--> "whatsit"

(*whatsit, whatsit, whatsit*)

find "whatsit" searching in text document 1 options {starting at top:false, wrap around:false, search mode:literal, returning results:false} with selecting match

--> {found:true, found object:characters 77 thru 83 of text document 1, found text:"whatsit"}

get characters 77 thru 83 of text document 1

--> "whatsit"

get selection

--> "whatsit"

(*whatsit, whatsit, whatsit*)

find "whatsit" searching in text document 1 options {starting at top:false, wrap around:false, search mode:literal, returning results:false} with selecting match

--> {found:true, found object:characters 97 thru 103 of text document 1, found text:"whatsit"}

get characters 97 thru 103 of text document 1

--> "whatsit"

get selection

--> "whatsit"

(*whatsit, whatsit, whatsit*)

find "whatsit" searching in text document 1 options {starting at top:false, wrap around:false, search mode:literal, returning results:false} with selecting match

--> {found:false}

select {characters 53 thru 59 of text document 1, characters 63 thru 69 of text document 1, characters 77 thru 83 of text document 1, characters 97 thru 103 of text document 1}

get selection

--> {characters 53 thru 58 of text document 1, characters 63 thru 68 of text document 1, characters 77 thru 82 of text document 1, characters 97 thru 102 of text document 1}

end tell

Result:

{characters 53 thru 58 of text document 1 of application "BBEdit", characters 63 thru 68 of text document 1 of application "BBEdit", characters 77 thru 82 of text document 1 of application "BBEdit", characters 97 thru 102 of text document 1 of application "BBEdit"}

Christopher Waterman

unread,
Nov 8, 2021, 3:26:56 PM11/8/21
to bbe...@googlegroups.com
Hey Chris,

> I don't see how you're getting a list of selected items.
>
> If I use find with show matches it doesn't work.
>
> If I use LiveSearch it doesn't work.
>
> So how exactly are you doing your selection?

I’m making the selections with Search > Find & Select or Edit > Select > Highlighted Matches. I use these commands a fair amount and was making a script to transform the selection in a particular way when I ran into this.

— Chris(topher)?

Christopher Waterman

unread,
Nov 8, 2021, 3:44:35 PM11/8/21
to bbe...@googlegroups.com
Jean,

Thanks for breakdown. I will send it on to support.

— Chris(topher)?



On Nov 8, 2021, at 5:55 AM, jj <goo...@mixio.com> wrote:

Hi Christopher & Christopher,

Seems there is an off by one somewhere.

You should mail the issue to sup...@barebones.com.

Regards,

Jean Jourdain

tell application "BBEdit"

...

Result:

{characters 53 thru 58 of text document 1 of application "BBEdit", characters 63 thru 68 of text document 1 of application "BBEdit", characters 77 thru 82 of text document 1 of application "BBEdit", characters 97 thru 102 of text document 1 of application "BBEdit"}


On Monday, November 8, 2021 at 10:40:41 AM UTC+1 listmei...@gmail.com wrote:
On Nov 08, 2021, at 00:14, Christopher Waterman <ch...@rustydogink.com> wrote:
If I select every occurrence of "whatsit" through which ever means.

...

Then run this AppleScript.

AppleScript:
tell window 1 of application "BBEdit"
set stuff to get selection
end tell

It returns a list like this.


Hey Christopher,

I don't see how you're getting a list of selected items.

If I use find with show matches it doesn't work.

If I use LiveSearch it doesn't work.

So how exactly are you doing your selection?


--
Best Regards,
Chris


--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/b5fa857a-0f89-4df9-95b5-b7f9758eae15n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages