try
tell application "BBEdit"
tell first window
set vLine to startLine of selection
tell first document
set vResult to find "^\\h*" searching in its line vLine options {search mode:grep, wrap around:false, starting at top:true}
if vResult's found then
if vResult's found text is "" then
select insertion point before its line vLine
else
select insertion point after last character of vResult's found object
end if
end if
end tell
end tell
end tell
on error aMessage
display alert aMessage
end try