ecSyntMemo.pas

procedure TCustomSyntaxMemo.SelectWord;
  //make new version of IsSpaceChar to handle only space/tab
  //(but not EOL chars, like Notepad++)
  function IsSpaceChar(ch: ecChar): boolean;
  begin
    Result:= (ch=' ') or (ch=#9);
  end;
var
  wEnd, wStart: integer;
begin
  //handle case when caret is on space
  //(like Notepad++ does)
  wStart:= CaretStrPos;
  if (wStart>=0) and (wStart<Length(Lines.FText)) then
    if IsSpaceChar(Lines.FText[wStart+1]) then
    begin
      wEnd:= wStart;
      while (wStart>0) and IsSpaceChar(Lines.FText[wStart]) do Dec(wStart);
      while (wEnd<Length(Lines.FText)) and IsSpaceChar(Lines.FText[wEnd+1]) do Inc(wEnd);
      SetSelection(wStart, wEnd-wStart);
      Exit;
    end;

  WordRangeAtPos(CaretPos, wStart, wEnd);
  if wEnd = wStart then
   begin
    CaretStrPos := wEnd + 1;
    SelLength := 0;
   end else
//   begin
//    CaretStrPos := wEnd;
    SetSelection(wStart, wEnd - wStart);
//   end;
end;

