mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-26 21:04:09 +02:00
implemented VK_LEFT/VK_RIGHT for word/identifier completion
git-svn-id: trunk@7529 -
This commit is contained in:
parent
7c6b448dd9
commit
60145ca7f2
@ -1127,16 +1127,16 @@ begin
|
||||
ActivateGlobalWriteLock;
|
||||
try
|
||||
// build code tree
|
||||
{ $IFDEF CTDEBUG}
|
||||
{$IFDEF CTDEBUG}
|
||||
DebugLn('TFindDeclarationTool.FindDeclaration A CursorPos=X',dbgs(CursorPos.X),',Y',dbgs(CursorPos.Y));
|
||||
{ $ENDIF}
|
||||
{$ENDIF}
|
||||
if DirtySrc<>nil then DirtySrc.Clear;
|
||||
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
|
||||
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos,{$ENDIF}
|
||||
btLoadDirtySource,btCursorPosOutAllowed]);
|
||||
{ $IFDEF CTDEBUG}
|
||||
{$IFDEF CTDEBUG}
|
||||
DebugLn('TFindDeclarationTool.FindDeclaration C CleanCursorPos=',dbgs(CleanCursorPos));
|
||||
{ $ENDIF}
|
||||
{$ENDIF}
|
||||
// find CodeTreeNode at cursor
|
||||
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,CleanCursorPos,
|
||||
|
@ -83,6 +83,8 @@ type
|
||||
FBackgroundColor: TColor;
|
||||
FOnSearchPosition: TSynBaseCompletionSearchPosition;
|
||||
FOnKeyCompletePrefix: TNotifyEvent;
|
||||
FOnKeyNextChar: TNotifyEvent;
|
||||
FOnKeyPrevChar: TNotifyEvent;
|
||||
FTextColor: TColor;
|
||||
FTextSelectedColor: TColor;
|
||||
procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override;
|
||||
@ -131,6 +133,8 @@ type
|
||||
property OnSearchPosition:TSynBaseCompletionSearchPosition
|
||||
read FOnSearchPosition write FOnSearchPosition;
|
||||
property OnKeyCompletePrefix: TNotifyEvent read FOnKeyCompletePrefix write FOnKeyCompletePrefix;
|
||||
property OnKeyNextChar: TNotifyEvent read FOnKeyNextChar write FOnKeyNextChar;
|
||||
property OnKeyPrevChar: TNotifyEvent read FOnKeyPrevChar write FOnKeyPrevChar;
|
||||
property BackgroundColor: TColor read FBackgroundColor write FBackgroundColor;
|
||||
property TextColor: TColor read FTextColor write FTextColor;
|
||||
property TextSelectedColor: TColor
|
||||
@ -178,6 +182,10 @@ type
|
||||
procedure SetOnSearchPosition(NewValue :TSynBaseCompletionSearchPosition);
|
||||
function GetOnKeyCompletePrefix: TNotifyEvent;
|
||||
procedure SetOnKeyCompletePrefix(const AValue: TNotifyEvent);
|
||||
function GetOnKeyNextChar: TNotifyEvent;
|
||||
procedure SetOnKeyNextChar(const AValue: TNotifyEvent);
|
||||
function GetOnKeyPrevChar: TNotifyEvent;
|
||||
procedure SetOnKeyPrevChar(const AValue: TNotifyEvent);
|
||||
{$ENDIF}
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
@ -209,6 +217,10 @@ type
|
||||
read GetOnSearchPosition write SetOnSearchPosition;
|
||||
property OnKeyCompletePrefix: TNotifyEvent read GetOnKeyCompletePrefix
|
||||
write SetOnKeyCompletePrefix;
|
||||
property OnKeyNextChar: TNotifyEvent read GetOnKeyNextChar
|
||||
write SetOnKeyNextChar;
|
||||
property OnKeyPrevChar: TNotifyEvent read GetOnKeyPrevChar
|
||||
write SetOnKeyPrevChar;
|
||||
{$ENDIF}
|
||||
property ClSelect: TColor read GetClSelect write SetClSelect;
|
||||
property AnsiStrings: boolean read SFAnsi write RFAnsi;
|
||||
@ -408,6 +420,18 @@ begin
|
||||
if Assigned(OnKeyCompletePrefix) then OnKeyCompletePrefix(Self);
|
||||
Key:=VK_UNKNOWN;
|
||||
end;
|
||||
VK_LEFT:
|
||||
begin
|
||||
if (Shift = []) and (Length(CurrentString) > 0) then begin
|
||||
if Assigned(OnKeyPrevChar) then OnKeyPrevChar(Self);
|
||||
Key:=VK_UNKNOWN;
|
||||
end;
|
||||
end;
|
||||
VK_Right:
|
||||
begin
|
||||
if Assigned(OnKeyNextChar) then OnKeyNextChar(Self);
|
||||
Key:=VK_UNKNOWN;
|
||||
end;
|
||||
{$ENDIF}
|
||||
end;
|
||||
{$ifdef SYN_LAZARUS}
|
||||
@ -731,6 +755,26 @@ procedure TSynBaseCompletion.SetOnKeyCompletePrefix(const AValue: TNotifyEvent);
|
||||
begin
|
||||
Form.OnKeyCompletePrefix:=AValue;
|
||||
end;
|
||||
|
||||
function TSynBaseCompletion.GetOnKeyNextChar: TNotifyEvent;
|
||||
begin
|
||||
Result:=Form.OnKeyNextChar;
|
||||
end;
|
||||
|
||||
procedure TSynBaseCompletion.SetOnKeyNextChar(const AValue: TNotifyEvent);
|
||||
begin
|
||||
Form.OnKeyNextChar:=AValue;
|
||||
end;
|
||||
|
||||
function TSynBaseCompletion.GetOnKeyPrevChar: TNotifyEvent;
|
||||
begin
|
||||
Result:=Form.OnKeyPrevChar;
|
||||
end;
|
||||
|
||||
procedure TSynBaseCompletion.SetOnKeyPrevChar(const AValue: TNotifyEvent);
|
||||
begin
|
||||
Form.OnKeyPrevChar:=AValue;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TSynBaseCompletion.Execute(s: string; x, y: integer);
|
||||
|
@ -471,6 +471,8 @@ type
|
||||
X, Y: integer; ItemSelected: boolean; Index: integer): boolean;
|
||||
procedure OnSynCompletionSearchPosition(var APosition: integer);
|
||||
procedure OnSynCompletionCompletePrefix(Sender: TObject);
|
||||
procedure OnSynCompletionNextChar(Sender: TObject);
|
||||
procedure OnSynCompletionPrevChar(Sender: TObject);
|
||||
procedure OnSynCompletionKeyPress(Sender: TObject; var Key: Char);
|
||||
procedure DeactivateCompletionForm;
|
||||
procedure InitIdentCompletion(S: TStrings);
|
||||
@ -2388,6 +2390,8 @@ begin
|
||||
OnPaintItem:=@OnSynCompletionPaintItem;
|
||||
OnSearchPosition:=@OnSynCompletionSearchPosition;
|
||||
OnKeyCompletePrefix:=@OnSynCompletionCompletePrefix;
|
||||
OnKeyNextChar:=@OnSynCompletionNextChar;
|
||||
OnKeyPrevChar:=@OnSynCompletionPrevChar;
|
||||
OnKeyPress:=@OnSynCompletionKeyPress;
|
||||
ShortCut:=Menus.ShortCut(VK_UNKNOWN,[]);
|
||||
end;
|
||||
@ -2639,17 +2643,66 @@ begin
|
||||
CurCompletionControl.Editor.SelText:=AddPrefix;
|
||||
CurCompletionControl.Editor.LogicalCaretXY:=
|
||||
CurCompletionControl.Editor.BlockBegin;
|
||||
SL:=TStringList.Create;
|
||||
try
|
||||
aWordCompletion.GetWordList(SL, NewPrefix, false, 100);
|
||||
CurCompletionControl.ItemList:=SL;
|
||||
finally
|
||||
SL.Free;
|
||||
if CurrentCompletionType=ctWordCompletion then begin
|
||||
SL:=TStringList.Create;
|
||||
try
|
||||
aWordCompletion.GetWordList(SL, NewPrefix, false, 100);
|
||||
CurCompletionControl.ItemList:=SL;
|
||||
finally
|
||||
SL.Free;
|
||||
end;
|
||||
end;
|
||||
CurCompletionControl.CurrentString:=NewPrefix;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.OnSynCompletionNextChar(Sender: TObject);
|
||||
var
|
||||
NewPrefix: String;
|
||||
SrcEdit: TSourceEditor;
|
||||
Line: String;
|
||||
Editor: TSynEdit;
|
||||
LogCaret: TPoint;
|
||||
CharLen: LongInt;
|
||||
AddPrefix: String;
|
||||
begin
|
||||
if CurCompletionControl=nil then exit;
|
||||
SrcEdit:=GetActiveSE;
|
||||
if SrcEdit=nil then exit;
|
||||
Editor:=SrcEdit.EditorComponent;
|
||||
LogCaret:=Editor.LogicalCaretXY;
|
||||
if LogCaret.Y>=Editor.Lines.Count then exit;
|
||||
Line:=SrcEdit.EditorComponent.Lines[LogCaret.Y-1];
|
||||
if LogCaret.X>length(Line) then exit;
|
||||
CharLen:=UTF8CharacterLength(@Line[LogCaret.X]);
|
||||
AddPrefix:=copy(Line,LogCaret.X,CharLen);
|
||||
NewPrefix:=CurCompletionControl.CurrentString+AddPrefix;
|
||||
//debugln('TSourceNotebook.OnSynCompletionNextChar NewPrefix="',NewPrefix,'" LogCaret.X=',dbgs(LogCaret.X));
|
||||
inc(LogCaret.X);
|
||||
CurCompletionControl.Editor.LogicalCaretXY:=LogCaret;
|
||||
CurCompletionControl.CurrentString:=NewPrefix;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.OnSynCompletionPrevChar(Sender: TObject);
|
||||
var
|
||||
NewPrefix: String;
|
||||
SrcEdit: TSourceEditor;
|
||||
Editor: TSynEdit;
|
||||
NewLen: LongInt;
|
||||
begin
|
||||
if CurCompletionControl=nil then exit;
|
||||
NewPrefix:=CurCompletionControl.CurrentString;
|
||||
if NewPrefix='' then exit;
|
||||
SrcEdit:=GetActiveSE;
|
||||
if SrcEdit=nil then exit;
|
||||
Editor:=SrcEdit.EditorComponent;
|
||||
Editor.CaretX:=Editor.CaretX-1;
|
||||
NewLen:=UTF8FindNearestCharStart(PChar(NewPrefix),length(NewPrefix),
|
||||
length(NewPrefix))-1;
|
||||
NewPrefix:=copy(NewPrefix,1,NewLen);
|
||||
CurCompletionControl.CurrentString:=NewPrefix;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.OnSynCompletionKeyPress(Sender: TObject;
|
||||
var Key: Char);
|
||||
begin
|
||||
|
@ -238,7 +238,7 @@ function NtoLE(const AValue: QWord): QWord;
|
||||
implementation
|
||||
|
||||
var
|
||||
InterfaceFinalizationHandlers: TList;
|
||||
InterfaceFinalizationHandlers: TFPList;
|
||||
DebugTextAlloced: boolean;
|
||||
DebugText: ^Text;
|
||||
|
||||
@ -1926,7 +1926,7 @@ end;
|
||||
|
||||
initialization
|
||||
InitializeDebugOutput;
|
||||
InterfaceFinalizationHandlers:=TList.Create;
|
||||
InterfaceFinalizationHandlers:=TFPList.Create;
|
||||
finalization
|
||||
InterfaceFinalizationHandlers.Free;
|
||||
InterfaceFinalizationHandlers:=nil;
|
||||
|
Loading…
Reference in New Issue
Block a user