27
27
If you do not delete the provisions above, a recipient may use your version
28
28
of this file under either the MPL or the GPL.
30
$Id: syneditkeycmds.pp 22581 2009-11-13 21:56:26Z martin $
30
$Id: syneditkeycmds.pp 36049 2012-03-15 22:59:28Z mattias $
32
32
You may retrieve the latest version of this file at the SynEdit home page,
33
33
located at http://SynEdit.SourceForge.net
88
88
ecEditorBottom = 16; // Move cursor to absolute end
89
89
ecGotoXY = 17; // Move cursor to specific coordinates, Data = PPoint
90
90
ecLineTextStart = 18; // Move cursor to the first none whitespace in the line
91
ecWordEndLeft = 19; // Move cursor left one word (to end of word)
92
ecWordEndRight = 20; // Move cursor right one word (to end of word)
93
ecHalfWordLeft = 21; // Move cursor left to word-begin/end or case change lower to uppper
94
ecHalfWordRight = 22; // Move cursor right to word-begin/end or case change lower to uppper
92
96
//******************************************************************************
93
97
// Maybe the command processor should just take a boolean that signifies if
120
124
ecSelEditorBottom = ecEditorBottom + ecSelection;
121
125
ecSelGotoXY = ecGotoXY + ecSelection; // Data = PPoint
122
126
ecSelLineTextStart= ecLineTextStart + ecSelection; // Move cursor to the first none whitespace in the line
127
ecSelWordEndLeft = ecWordEndLeft + ecSelection;
128
ecSelWordEndRight = ecWordEndRight + ecSelection;
129
ecSelHalfWordLeft = ecHalfWordLeft + ecSelection;
130
ecSelHalfWordRight= ecHalfWordRight + ecSelection;
124
132
ecSelCmdRangeStart = ecLeft + ecSelection;
125
133
ecSelCmdRangeEnd = ecLeft + ecSelection + 49;
274
285
// If ask by SynEdit they add an offset
276
287
// Return the next offset
277
function AllocatePluginKeyRange(Count: Integer): integer;
288
function AllocatePluginKeyRange(Count: Integer; OffsetOnly: Boolean = False): integer;
280
291
ESynKeyError = class(Exception);
349
360
function FindKeycode(Code: word; SS: TShiftState): integer;
350
361
function FindKeycodeEx(Code: word; SS: TShiftState; var Data: pointer;
351
362
out IsStartOfCombo: boolean;
352
FinishComboOnly: Boolean = False): TSynEditorCommand;
363
FinishComboOnly: Boolean = False;
364
ComboStart: TSynEditKeyStrokes = nil): TSynEditorCommand;
353
365
procedure ResetKeyCombo;
354
366
function FindShortcut(SC: TShortcut): integer;
355
367
function FindShortcut2(SC, SC2: TShortcut): integer;
484
EditorCommandStrs: array[0..141] of TIdentMapEntry = (
499
EditorCommandStrs: array[0..149] of TIdentMapEntry = (
485
500
(Value: ecNone; Name: 'ecNone'),
486
501
(Value: ecLeft; Name: 'ecLeft'),
487
502
(Value: ecRight; Name: 'ecRight'),
489
504
(Value: ecDown; Name: 'ecDown'),
490
505
(Value: ecWordLeft; Name: 'ecWordLeft'),
491
506
(Value: ecWordRight; Name: 'ecWordRight'),
507
(Value: ecWordEndLeft; Name: 'ecWordEndLeft'),
508
(Value: ecWordEndRight; Name: 'ecWordEndRight'),
509
(Value: ecHalfWordLeft; Name: 'ecHalfWordLeft'),
510
(Value: ecHalfWordRight; Name: 'ecHalfWordRight'),
492
511
(Value: ecLineStart; Name: 'ecLineStart'),
493
512
(Value: ecLineEnd; Name: 'ecLineEnd'),
494
513
(Value: ecPageUp; Name: 'ecPageUp'),
507
526
(Value: ecSelDown; Name: 'ecSelDown'),
508
527
(Value: ecSelWordLeft; Name: 'ecSelWordLeft'),
509
528
(Value: ecSelWordRight; Name: 'ecSelWordRight'),
529
(Value: ecSelWordEndLeft; Name: 'ecSelWordEndLeft'),
530
(Value: ecSelWordEndRight; Name: 'ecSelWordEndRight'),
531
(Value: ecSelHalfWordLeft; Name: 'ecSelHalfWordLeft'),
532
(Value: ecSelHalfWordRight; Name: 'ecSelHalfWordRight'),
510
533
(Value: ecSelLineStart; Name: 'ecSelLineStart'),
511
534
(Value: ecSelLineEnd; Name: 'ecSelLineEnd'),
512
535
(Value: ecSelPageUp; Name: 'ecSelPageUp'),
630
653
ExtraIdentToIntFn: Array of TIdentToInt = nil;
631
654
ExtraIntToIdentFn: Array of TIntToIdent = nil;
655
ExtraGetEditorCommandValues: Array of TGetEditorCommandValuesProc = nil;
633
657
procedure GetEditorCommandValues(Proc: TGetStrProc);
662
Proc('ecUserDefined' + IntToStr(i));
637
663
for i := Low(EditorCommandStrs) to High(EditorCommandStrs) do
638
664
Proc(EditorCommandStrs[I].Name);
666
while (i < length(ExtraGetEditorCommandValues)) do begin
667
ExtraGetEditorCommandValues[i](Proc);
641
672
function IdentToEditorCommand(const Ident: string; var Cmd: longint): boolean;
676
if (copy(Ident, 1 , 13) = 'ecUserDefined') then begin
677
Cmd := StrToIntDef(copy(Ident, 14, length(Ident)), -1) + ecUserDefinedFirst;
678
Result := (Cmd >= ecUserDefinedFirst) and (Cmd <= ecUserDefinedLast);
645
682
Result := IdentToInt(Ident, Cmd, EditorCommandStrs);
647
684
while (i < length(ExtraIdentToIntFn)) and (not Result) do begin
694
if (Cmd >= ecUserDefinedFirst) and (Cmd <= ecUserDefinedLast) then begin
695
Ident := 'ecUserDefined' + IntToStr(Cmd - ecUserDefinedFirst);
657
699
Result := IntToIdent(Cmd, Ident, EditorCommandStrs);
659
701
while (i < length(ExtraIntToIdentFn)) and (not Result) do begin
675
717
ExtraIntToIdentFn[i] := IntToIdentFn;
679
function AllocatePluginKeyRange(Count: Integer): integer;
720
procedure RegisterExtraGetEditorCommandValues(AProc: TGetEditorCommandValuesProc);
724
i := length(ExtraGetEditorCommandValues);
725
SetLength(ExtraGetEditorCommandValues, i + 1);
726
ExtraGetEditorCommandValues[i] := AProc;
730
function AllocatePluginKeyRange(Count: Integer; OffsetOnly: Boolean): integer;
681
732
CurOffset : integer = 0;
683
734
Result := CurOffset;
684
735
inc(CurOffset, Count);
736
if not OffsetOnly then
737
inc(Result, ecPluginFirst);
687
740
function EditorCommandToDescrString(Cmd: TSynEditorCommand): string;
908
function TSynEditKeyStrokes.FindKeycodeEx(Code: word; SS: TShiftState; var Data: pointer; out
909
IsStartOfCombo: boolean; FinishComboOnly: Boolean = False): TSynEditorCommand;
961
function TSynEditKeyStrokes.FindKeycodeEx(Code: word; SS: TShiftState; var Data: pointer;
962
out IsStartOfCombo: boolean;
963
FinishComboOnly: Boolean; ComboStart: TSynEditKeyStrokes): TSynEditorCommand;
966
CurComboStart: TSynEditKeyStrokes;
912
967
{$IFNDEF SYN_COMPILER_3_UP}
917
i := FindKeycode2(fLastKey, fLastShiftState, Code, SS);
918
if (i < 0) and not FinishComboOnly then
919
i := FindKeycode(Code, SS);
921
Result := Items[i].Command
972
(* if FinishComboOnly=True then ComboStart are the KeyStrokes, which have the
973
already received keys.
974
If several TSynEditKeyStrokes have combos, starting with the same key(s)
975
only one needs to keep the info. The others chek, if they have a matching combo
979
IsStartOfCombo := False;
981
if ComboStart = nil then
982
CurComboStart := self
925
if (Result = ecNone) and (Code >= VK_ACCEPT) and (Code <= VK_SCROLL) and
926
(FindKeycode2Start(Code, SS) >= 0) and not FinishComboOnly then
984
CurComboStart := ComboStart;
986
if CurComboStart.fLastKey <> 0 then begin
987
// Try to finish the combo
988
i := FindKeycode2(CurComboStart.fLastKey, CurComboStart.fLastShiftState, Code, SS);
989
if (i >= 0) then begin
990
Result := Items[i].Command;
991
CurComboStart.ResetKeyCombo;
995
if FinishComboOnly then
998
// Check for single stroke
999
i := FindKeycode(Code, SS);
1000
if i >= 0 then begin
1001
Result := Items[i].Command;
1003
if (ComboStart <> nil) and (ComboStart <> self) then
1004
ComboStart.ResetKeyCombo;
1008
if (FindKeycode2Start(Code, SS) >= 0) and not FinishComboOnly then
928
1010
fLastKey := Code;
929
1011
fLastShiftState := SS;
930
1012
IsStartOfCombo := True;
933
fLastShiftState := [];
934
IsStartOfCombo := False;
1013
// Now this is the start of combo
1014
if (ComboStart <> nil) and (ComboStart <> self) then
1015
ComboStart.ResetKeyCombo;
1018
// Nothing was found.
1019
// Keep CurComboStart.fLastKey. It may be ued by another TSynEditKeyStrokes
1020
if (ComboStart <> self) then
1021
ResetKeyCombo; // reset self, if not CurComboStart
938
1025
procedure TSynEditKeyStrokes.ResetKeyCombo;