mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 07:22:20 +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;
|
ActivateGlobalWriteLock;
|
||||||
try
|
try
|
||||||
// build code tree
|
// build code tree
|
||||||
{ $IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('TFindDeclarationTool.FindDeclaration A CursorPos=X',dbgs(CursorPos.X),',Y',dbgs(CursorPos.Y));
|
DebugLn('TFindDeclarationTool.FindDeclaration A CursorPos=X',dbgs(CursorPos.X),',Y',dbgs(CursorPos.Y));
|
||||||
{ $ENDIF}
|
{$ENDIF}
|
||||||
if DirtySrc<>nil then DirtySrc.Clear;
|
if DirtySrc<>nil then DirtySrc.Clear;
|
||||||
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
|
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
|
||||||
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos,{$ENDIF}
|
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos,{$ENDIF}
|
||||||
btLoadDirtySource,btCursorPosOutAllowed]);
|
btLoadDirtySource,btCursorPosOutAllowed]);
|
||||||
{ $IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('TFindDeclarationTool.FindDeclaration C CleanCursorPos=',dbgs(CleanCursorPos));
|
DebugLn('TFindDeclarationTool.FindDeclaration C CleanCursorPos=',dbgs(CleanCursorPos));
|
||||||
{ $ENDIF}
|
{$ENDIF}
|
||||||
// find CodeTreeNode at cursor
|
// find CodeTreeNode at cursor
|
||||||
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
||||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,CleanCursorPos,
|
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,CleanCursorPos,
|
||||||
|
@ -83,6 +83,8 @@ type
|
|||||||
FBackgroundColor: TColor;
|
FBackgroundColor: TColor;
|
||||||
FOnSearchPosition: TSynBaseCompletionSearchPosition;
|
FOnSearchPosition: TSynBaseCompletionSearchPosition;
|
||||||
FOnKeyCompletePrefix: TNotifyEvent;
|
FOnKeyCompletePrefix: TNotifyEvent;
|
||||||
|
FOnKeyNextChar: TNotifyEvent;
|
||||||
|
FOnKeyPrevChar: TNotifyEvent;
|
||||||
FTextColor: TColor;
|
FTextColor: TColor;
|
||||||
FTextSelectedColor: TColor;
|
FTextSelectedColor: TColor;
|
||||||
procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override;
|
procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override;
|
||||||
@ -131,6 +133,8 @@ type
|
|||||||
property OnSearchPosition:TSynBaseCompletionSearchPosition
|
property OnSearchPosition:TSynBaseCompletionSearchPosition
|
||||||
read FOnSearchPosition write FOnSearchPosition;
|
read FOnSearchPosition write FOnSearchPosition;
|
||||||
property OnKeyCompletePrefix: TNotifyEvent read FOnKeyCompletePrefix write FOnKeyCompletePrefix;
|
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 BackgroundColor: TColor read FBackgroundColor write FBackgroundColor;
|
||||||
property TextColor: TColor read FTextColor write FTextColor;
|
property TextColor: TColor read FTextColor write FTextColor;
|
||||||
property TextSelectedColor: TColor
|
property TextSelectedColor: TColor
|
||||||
@ -178,6 +182,10 @@ type
|
|||||||
procedure SetOnSearchPosition(NewValue :TSynBaseCompletionSearchPosition);
|
procedure SetOnSearchPosition(NewValue :TSynBaseCompletionSearchPosition);
|
||||||
function GetOnKeyCompletePrefix: TNotifyEvent;
|
function GetOnKeyCompletePrefix: TNotifyEvent;
|
||||||
procedure SetOnKeyCompletePrefix(const AValue: TNotifyEvent);
|
procedure SetOnKeyCompletePrefix(const AValue: TNotifyEvent);
|
||||||
|
function GetOnKeyNextChar: TNotifyEvent;
|
||||||
|
procedure SetOnKeyNextChar(const AValue: TNotifyEvent);
|
||||||
|
function GetOnKeyPrevChar: TNotifyEvent;
|
||||||
|
procedure SetOnKeyPrevChar(const AValue: TNotifyEvent);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
@ -209,6 +217,10 @@ type
|
|||||||
read GetOnSearchPosition write SetOnSearchPosition;
|
read GetOnSearchPosition write SetOnSearchPosition;
|
||||||
property OnKeyCompletePrefix: TNotifyEvent read GetOnKeyCompletePrefix
|
property OnKeyCompletePrefix: TNotifyEvent read GetOnKeyCompletePrefix
|
||||||
write SetOnKeyCompletePrefix;
|
write SetOnKeyCompletePrefix;
|
||||||
|
property OnKeyNextChar: TNotifyEvent read GetOnKeyNextChar
|
||||||
|
write SetOnKeyNextChar;
|
||||||
|
property OnKeyPrevChar: TNotifyEvent read GetOnKeyPrevChar
|
||||||
|
write SetOnKeyPrevChar;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
property ClSelect: TColor read GetClSelect write SetClSelect;
|
property ClSelect: TColor read GetClSelect write SetClSelect;
|
||||||
property AnsiStrings: boolean read SFAnsi write RFAnsi;
|
property AnsiStrings: boolean read SFAnsi write RFAnsi;
|
||||||
@ -408,6 +420,18 @@ begin
|
|||||||
if Assigned(OnKeyCompletePrefix) then OnKeyCompletePrefix(Self);
|
if Assigned(OnKeyCompletePrefix) then OnKeyCompletePrefix(Self);
|
||||||
Key:=VK_UNKNOWN;
|
Key:=VK_UNKNOWN;
|
||||||
end;
|
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}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
{$ifdef SYN_LAZARUS}
|
{$ifdef SYN_LAZARUS}
|
||||||
@ -731,6 +755,26 @@ procedure TSynBaseCompletion.SetOnKeyCompletePrefix(const AValue: TNotifyEvent);
|
|||||||
begin
|
begin
|
||||||
Form.OnKeyCompletePrefix:=AValue;
|
Form.OnKeyCompletePrefix:=AValue;
|
||||||
end;
|
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}
|
{$ENDIF}
|
||||||
|
|
||||||
procedure TSynBaseCompletion.Execute(s: string; x, y: integer);
|
procedure TSynBaseCompletion.Execute(s: string; x, y: integer);
|
||||||
|
@ -471,6 +471,8 @@ type
|
|||||||
X, Y: integer; ItemSelected: boolean; Index: integer): boolean;
|
X, Y: integer; ItemSelected: boolean; Index: integer): boolean;
|
||||||
procedure OnSynCompletionSearchPosition(var APosition: integer);
|
procedure OnSynCompletionSearchPosition(var APosition: integer);
|
||||||
procedure OnSynCompletionCompletePrefix(Sender: TObject);
|
procedure OnSynCompletionCompletePrefix(Sender: TObject);
|
||||||
|
procedure OnSynCompletionNextChar(Sender: TObject);
|
||||||
|
procedure OnSynCompletionPrevChar(Sender: TObject);
|
||||||
procedure OnSynCompletionKeyPress(Sender: TObject; var Key: Char);
|
procedure OnSynCompletionKeyPress(Sender: TObject; var Key: Char);
|
||||||
procedure DeactivateCompletionForm;
|
procedure DeactivateCompletionForm;
|
||||||
procedure InitIdentCompletion(S: TStrings);
|
procedure InitIdentCompletion(S: TStrings);
|
||||||
@ -2388,6 +2390,8 @@ begin
|
|||||||
OnPaintItem:=@OnSynCompletionPaintItem;
|
OnPaintItem:=@OnSynCompletionPaintItem;
|
||||||
OnSearchPosition:=@OnSynCompletionSearchPosition;
|
OnSearchPosition:=@OnSynCompletionSearchPosition;
|
||||||
OnKeyCompletePrefix:=@OnSynCompletionCompletePrefix;
|
OnKeyCompletePrefix:=@OnSynCompletionCompletePrefix;
|
||||||
|
OnKeyNextChar:=@OnSynCompletionNextChar;
|
||||||
|
OnKeyPrevChar:=@OnSynCompletionPrevChar;
|
||||||
OnKeyPress:=@OnSynCompletionKeyPress;
|
OnKeyPress:=@OnSynCompletionKeyPress;
|
||||||
ShortCut:=Menus.ShortCut(VK_UNKNOWN,[]);
|
ShortCut:=Menus.ShortCut(VK_UNKNOWN,[]);
|
||||||
end;
|
end;
|
||||||
@ -2639,17 +2643,66 @@ begin
|
|||||||
CurCompletionControl.Editor.SelText:=AddPrefix;
|
CurCompletionControl.Editor.SelText:=AddPrefix;
|
||||||
CurCompletionControl.Editor.LogicalCaretXY:=
|
CurCompletionControl.Editor.LogicalCaretXY:=
|
||||||
CurCompletionControl.Editor.BlockBegin;
|
CurCompletionControl.Editor.BlockBegin;
|
||||||
SL:=TStringList.Create;
|
if CurrentCompletionType=ctWordCompletion then begin
|
||||||
try
|
SL:=TStringList.Create;
|
||||||
aWordCompletion.GetWordList(SL, NewPrefix, false, 100);
|
try
|
||||||
CurCompletionControl.ItemList:=SL;
|
aWordCompletion.GetWordList(SL, NewPrefix, false, 100);
|
||||||
finally
|
CurCompletionControl.ItemList:=SL;
|
||||||
SL.Free;
|
finally
|
||||||
|
SL.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
CurCompletionControl.CurrentString:=NewPrefix;
|
CurCompletionControl.CurrentString:=NewPrefix;
|
||||||
end;
|
end;
|
||||||
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;
|
procedure TSourceNotebook.OnSynCompletionKeyPress(Sender: TObject;
|
||||||
var Key: Char);
|
var Key: Char);
|
||||||
begin
|
begin
|
||||||
|
@ -238,7 +238,7 @@ function NtoLE(const AValue: QWord): QWord;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
var
|
var
|
||||||
InterfaceFinalizationHandlers: TList;
|
InterfaceFinalizationHandlers: TFPList;
|
||||||
DebugTextAlloced: boolean;
|
DebugTextAlloced: boolean;
|
||||||
DebugText: ^Text;
|
DebugText: ^Text;
|
||||||
|
|
||||||
@ -1926,7 +1926,7 @@ end;
|
|||||||
|
|
||||||
initialization
|
initialization
|
||||||
InitializeDebugOutput;
|
InitializeDebugOutput;
|
||||||
InterfaceFinalizationHandlers:=TList.Create;
|
InterfaceFinalizationHandlers:=TFPList.Create;
|
||||||
finalization
|
finalization
|
||||||
InterfaceFinalizationHandlers.Free;
|
InterfaceFinalizationHandlers.Free;
|
||||||
InterfaceFinalizationHandlers:=nil;
|
InterfaceFinalizationHandlers:=nil;
|
||||||
|
Loading…
Reference in New Issue
Block a user