![]() The use of a whose clause is essential see my brief introduction to whose clauses from last week if you’re not familiar with them. It’s a lot of action for one line of AppleScript. The second line is where we determine which the “current” word is and select it. Thus, the characterOffset of selection tells you where the selection starts. ![]() ![]() There’s always a selection - an insertion point counts as a zero-width selection between two characters. A characterOffset is an integer value, corresponding to the position of a character in the document, starting from 1. The first line gets the offset of the current selection. This script implements the Select Word command in just two lines (not counting tell statements). Select (last word whose characterOffset ≤ sel_offset) Set sel_offset to characterOffset of selection Here’s a slightly rewritten version of Stanley’s script: I learned the correct way to do it from a message Shane Stanley posted to the BBEdit-Scripting mailing list in March 2002. You don’t want to see that script it’s junk. I went about it the long way, by first finding the character position offset of the last word between the beginning of the document and the current selection then selecting the first word after that offset. My first crack at it worked, but was somewhat convoluted. No need to file a feature request to Bare Bones, however - this command can be implemented using AppleScript. If you had a partial word selected, Select Word would expand the selection to the entire word. In the same way that Select Line acts like a triple-click, Select Word would act like a double-click: position the insertion point inside or next to a word, invoke the Select Word command, and that word would be selected, just as if you had double-clicked on it. BBEdit has supported both these commands at least as far back as 1993’s version 2.5, which is the oldest version of the user manual I have laying around.Ī while back, it occurred to me that I’d like a third, similar command: Select Word. They’re as deeply ingrained in my muscle memory as the Cmd-A shortcut for Select All. I use both these commands frequently editing in an application that doesn’t support them drives me nuts. A companion command, Select Paragraph (default shortcut: Cmd-Opt-L), takes things one step further: it selects the current line, as well as all adjacent lines that contain anything other than whitespace. The Edit → Select Line command (default shortcut: Cmd-L) selects the current line. But what if your hands are on the keyboard? BBEdit, not surprisingly, has you covered. Triple-clicking is the standard mouse gesture to select an entire line at once. ‘Select Word’ Script for BBEdit Tuesday, 23 September 2003
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |