2
0
Эх сурвалжийг харах

UPD: the last part of the text in the TEdit is automatically selected, when selecting from AutoComplete ListBox in KASPathEdit (#600)

rich2014 3 жил өмнө
parent
commit
4b9cc4ac45

+ 19 - 8
components/KASToolBar/kaspathedit.pas

@@ -55,6 +55,7 @@ type
     keyDownText: String;
     keyDownText: String;
 {$ENDIF}
 {$ENDIF}
   private
   private
+    procedure setTextAndSelect( newText:String );
     procedure handleSpecialKeys( var Key: Word );
     procedure handleSpecialKeys( var Key: Word );
     procedure handleUpKey;
     procedure handleUpKey;
     procedure handleDownKey;
     procedure handleDownKey;
@@ -300,8 +301,7 @@ procedure TKASPathEdit.ListBoxClick(Sender: TObject);
 begin
 begin
   if FListBox.ItemIndex >= 0 then
   if FListBox.ItemIndex >= 0 then
   begin
   begin
-    Text:= FListBox.Items[FListBox.ItemIndex];
-    SelStart:= UTF8Length(Text);
+    setTextAndSelect( FListBox.Items[FListBox.ItemIndex] );
     HideListBox;
     HideListBox;
     SetFocus;
     SetFocus;
   end;
   end;
@@ -369,6 +369,19 @@ end;
 
 
 {$ENDIF}
 {$ENDIF}
 
 
+procedure TKASPathEdit.setTextAndSelect( newText:String );
+var
+  start: Integer;
+begin
+  if Pos(Text,newText) > 0 then
+    start:= UTF8Length(Text)
+  else
+    start:= UTF8Length(ExtractFilePath(Text));
+  Text:= newText;
+  SelStart:= start;
+  SelLength:= UTF8Length(Text)-SelStart;
+end;
+
 procedure TKASPathEdit.DoExit;
 procedure TKASPathEdit.DoExit;
 begin
 begin
   HideListBox;
   HideListBox;
@@ -450,10 +463,9 @@ begin
       FListBox.ItemIndex:= FListBox.ItemIndex - 1;
       FListBox.ItemIndex:= FListBox.ItemIndex - 1;
 
 
     if FListBox.ItemIndex >= 0 then
     if FListBox.ItemIndex >= 0 then
-      Text:= FListBox.Items[FListBox.ItemIndex]
+      setTextAndSelect( FListBox.Items[FListBox.ItemIndex] )
     else
     else
-      Text:= ExtractFilePath(Text);
-    SelStart:= UTF8Length(Text);
+      setTextAndSelect( ExtractFilePath(Text) );
 end;
 end;
 
 
 procedure TKASPathEdit.handleDownKey;
 procedure TKASPathEdit.handleDownKey;
@@ -466,10 +478,9 @@ begin
       FListBox.ItemIndex:= FListBox.ItemIndex + 1;
       FListBox.ItemIndex:= FListBox.ItemIndex + 1;
 
 
     if FListBox.ItemIndex >= 0 then
     if FListBox.ItemIndex >= 0 then
-      Text:= FListBox.Items[FListBox.ItemIndex]
+      setTextAndSelect( FListBox.Items[FListBox.ItemIndex] )
     else
     else
-      Text:= ExtractFilePath(Text);
-    SelStart:= UTF8Length(Text);
+      setTextAndSelect( ExtractFilePath(Text) );
 end;
 end;
 
 
 {$IF DEFINED(LCLCOCOA)}
 {$IF DEFINED(LCLCOCOA)}