If the cursor is at the beginning of a word (and there is a space to the LEFT of the cursor) - then highlight the word on the RIGHT
If the cursor is at the end of a word (and there is a space to the RIGHT of the cursor) - then highlight the word on the LEFT
In theory, a script with such logic should work:
Code: Select all
#a::
SelectWordUnderCaret(){
leftChar := GetLeftChar()
MsgBox, %leftChar% ;nothing here!
if !InStr(leftChar, " ") ;logic: if cursor not at beginning of selected word
{
JumpToWordBeginning()
}
SelectWordToRight()
}
JumpToWordBeginning(){
Send, ^{Left}
return
}
SelectWordToRight(){
Send, ^+{Right}
return
}
GetLeftChar(){
CancelOldSelection()
SelectLeftChar()
leftChar := CopySelectedWordNoClip()
return leftChar
}
CancelOldSelection(){
SendInput, {Right}
SendInput, {Left}
return
}
SelectLeftChar(){
SendInput, +{Left}
return
}
CopySelectedWordNoClip(){ ;use that so my Clipboard keep last clip
oldClip := ClipboardAll
Clipboard :=
SendInput, ^c
ClipWait
result := ClipboardAll
Clipboard := oldClip
return result
}
1) there is a void in the String variable. If I log it in
Code: Select all
MsgBox, %leftChar%
2) if the cursor is between the 1st and 2nd letter, then selects the left word. For some reason, the logic has shifted 1 character to the right.
3) after executing the logic, sometimes it remains either Ctrl or Shift. (In my Sublime IDE, when the mouse is clicked, lines are multi-separated, new cursors are created). As if some of the functions did not have time to "programmatically release" them. Should I instead of
Code: Select all
Send, ^{Left}
Code: Select all
Send {Ctrl down}
Send {Left}
Send {Ctrl up}
[Mod action: Moved topic to v1 section. The main section is for v2.]