SynEdit, added 2nd "home" command: first word in line / issue #14440

git-svn-id: trunk@21592 -
This commit is contained in:
martin 2009-09-06 15:09:35 +00:00
parent cf84b01168
commit 793e654d38
4 changed files with 28 additions and 7 deletions

View File

@ -314,6 +314,7 @@ type
TSynMouseLinkEvent = procedure (
Sender: TObject; X, Y: Integer; var AllowMouseLink: Boolean) of object;
TSynHomeMode = (synhmDefault, synhmFirstWord);
{ TCustomSynEdit }
TCustomSynEdit = class(TSynEditBase)
@ -475,7 +476,7 @@ type
procedure ComputeCaret(X, Y: Integer);
procedure DoBlockIndent;
procedure DoBlockUnindent;
procedure DoHomeKey;
procedure DoHomeKey(aMode: TSynHomeMode = synhmDefault);
procedure DoEndKey;
procedure DoTabKey;
function FindHookedCmdEvent(AHandlerProc: THookedCommandEvent): integer;
@ -5648,6 +5649,10 @@ begin
begin
DoHomeKey;
end;
ecLineTextStart, ecSelLineTextStart, ecColSelLineTextStart:
begin
DoHomeKey(synhmFirstWord);
end;
ecLineEnd, ecSelLineEnd, ecColSelLineEnd:
begin
DoEndKey;
@ -7341,7 +7346,7 @@ begin
end;
end;
procedure TCustomSynEdit.DoHomeKey;
procedure TCustomSynEdit.DoHomeKey(aMode: TSynHomeMode = synhmDefault);
// jump to start of line (x=1),
// or if already there, jump to first non blank char
// or if blank line, jump to line indent position
@ -7356,7 +7361,7 @@ begin
OldPos := LogicalCaretXY;
NewPos := OldPos;
if not (eoEnhanceHomeKey in fOptions) and (CaretX > 1) then
if not(eoEnhanceHomeKey in fOptions) and (CaretX > 1) and (aMode in [synhmDefault]) then
begin
// not at start of line -> jump to start of line
NewPos.X := 1;
@ -7377,7 +7382,7 @@ begin
end else
s := '';
if FirstNonBlank >= 1 then
if (FirstNonBlank >= 1) or (aMode in [synhmFirstWord]) then
begin
// this line is not blank
LineStart := FirstNonBlank;
@ -7389,7 +7394,8 @@ begin
end;
NewPos.X:=LineStart;
if (eoEnhanceHomeKey in fOptions) and (OldPos.X>1) and (OldPos.X<=NewPos.X)
if (eoEnhanceHomeKey in fOptions) and (aMode in [synhmDefault]) and
(OldPos.X>1) and (OldPos.X<=NewPos.X)
then begin
NewPos.X:=1;
end;

View File

@ -76,7 +76,7 @@ const
ecDown = 4; // Move cursor down one line
ecWordLeft = 5; // Move cursor left one word
ecWordRight = 6; // Move cursor right one word
ecLineStart = 7; // Move cursor to beginning of line
ecLineStart = 7; // Move cursor to beginning of line (smart home)
ecLineEnd = 8; // Move cursor to end of line
ecPageUp = 9; // Move cursor up one page
ecPageDown = 10; // Move cursor down one page
@ -87,6 +87,7 @@ const
ecEditorTop = 15; // Move cursor to absolute beginning
ecEditorBottom = 16; // Move cursor to absolute end
ecGotoXY = 17; // Move cursor to specific coordinates, Data = PPoint
ecLineTextStart = 18; // Move cursor to the first none whitespace in the line
//******************************************************************************
// Maybe the command processor should just take a boolean that signifies if
@ -118,6 +119,7 @@ const
ecSelEditorTop = ecEditorTop + ecSelection;
ecSelEditorBottom = ecEditorBottom + ecSelection;
ecSelGotoXY = ecGotoXY + ecSelection; // Data = PPoint
ecSelLineTextStart= ecLineTextStart + ecSelection; // Move cursor to the first none whitespace in the line
ecSelCmdRangeStart = ecLeft + ecSelection;
ecSelCmdRangeEnd = ecLeft + ecSelection + 49;
@ -141,6 +143,7 @@ const
ecColSelPageBottom = ecPageBottom + ecColumnSelection;
ecColSelEditorTop = ecEditorTop + ecColumnSelection;
ecColSelEditorBottom = ecEditorBottom + ecColumnSelection;
ecColSelLineTextStart= ecLineTextStart + ecColumnSelection;
ecSelColCmdRangeStart = ecLeft + ecColumnSelection;
ecSelColCmdRangeEnd = ecLeft + ecColumnSelection + 48; // 1 less for ecSelectAll
@ -477,7 +480,7 @@ type
{$ENDIF}
const
EditorCommandStrs: array[0..138] of TIdentMapEntry = (
EditorCommandStrs: array[0..141] of TIdentMapEntry = (
(Value: ecNone; Name: 'ecNone'),
(Value: ecLeft; Name: 'ecLeft'),
(Value: ecRight; Name: 'ecRight'),
@ -496,6 +499,7 @@ const
(Value: ecEditorTop; Name: 'ecEditorTop'),
(Value: ecEditorBottom; Name: 'ecEditorBottom'),
(Value: ecGotoXY; Name: 'ecGotoXY'),
(Value: ecLineTextStart; Name: 'ecLineTextStart'),
(Value: ecSelLeft; Name: 'ecSelLeft'),
(Value: ecSelRight; Name: 'ecSelRight'),
(Value: ecSelUp; Name: 'ecSelUp'),
@ -513,6 +517,7 @@ const
(Value: ecSelEditorTop; Name: 'ecSelEditorTop'),
(Value: ecSelEditorBottom; Name: 'ecSelEditorBottom'),
(Value: ecSelGotoXY; Name: 'ecSelGotoXY'),
(Value: ecSelLineTextStart; Name: 'ecSelLineTextStart'),
(Value: ecColSelLeft; Name: 'ecColSelLeft'),
(Value: ecColSelRight; Name: 'ecColSelRight'),
(Value: ecColSelUp; Name: 'ecColSelUp'),
@ -529,6 +534,7 @@ const
(Value: ecColSelPageBottom; Name: 'ecColSelPageBottom'),
(Value: ecColSelEditorTop; Name: 'ecColSelEditorTop'),
(Value: ecColSelEditorBottom; Name: 'ecColSelEditorBottom'),
(Value: ecColSelLineTextStart; Name: 'ecColSelLineTextStart'),
(Value: ecSelectAll; Name: 'ecSelectAll'),
(Value: ecDeleteLastChar; Name: 'ecDeleteLastChar'),
(Value: ecDeleteChar; Name: 'ecDeleteChar'),

View File

@ -1751,6 +1751,7 @@ begin
ecEditorTop : Result:= srkmecEditorTop;
ecEditorBottom : Result:= srkmecEditorBottom;
ecGotoXY : Result:= srkmecGotoXY;
ecLineTextStart : Result:= srkmecLineTextStart;
ecSelLeft : Result:= srkmecSelLeft;
ecSelRight : Result:= srkmecSelRight;
ecSelUp : Result:= srkmecSelUp;
@ -1767,6 +1768,7 @@ begin
ecSelPageBottom : Result:= srkmecSelPageBottom;
ecSelEditorTop : Result:= srkmecSelEditorTop;
ecSelEditorBottom : Result:= srkmecSelEditorBottom;
ecSelLineTextStart : Result:= srkmecSelLineTextStart;
ecColSelUp : Result:= srkmecColSelUp;
ecColSelDown : Result:= srkmecColSelDown;
ecColSelLeft : Result:= srkmecColSelLeft;
@ -1781,6 +1783,7 @@ begin
ecColSelLineEnd : Result:= srkmecColSelLineEnd;
ecColSelEditorTop : Result:= srkmecColSelEditorTop;
ecColSelEditorBottom : Result:= srkmecColSelEditorBottom;
ecColSelLineTextStart : Result:= srkmecColSelLineTextStart;
ecSelGotoXY : Result:= srkmecSelGotoXY;
ecSelectAll : Result:= srkmecSelectAll;
ecDeleteLastChar : Result:= srkmecDeleteLastChar;
@ -2257,6 +2260,7 @@ begin
AddDefault(C, 'Move cursor word left', srkmecWordLeft, ecWordLeft);
AddDefault(C, 'Move cursor word right', srkmecWordRight, ecWordRight);
AddDefault(C, 'Move cursor to line start', srkmecLineStart, ecLineStart);
AddDefault(C, 'Move cursor to text start in line', srkmecLineTextStart, ecLineTextStart);
AddDefault(C, 'Move cursor to line end', srkmecLineEnd, ecLineEnd);
AddDefault(C, 'Move cursor up one page', srkmecPageUp, ecPageUp);
AddDefault(C, 'Move cursor down one page', srkmecPageDown, ecPageDown);
@ -2304,6 +2308,7 @@ begin
AddDefault(C, 'Select word left', lisKMSelectWordLeft, ecSelWordLeft);
AddDefault(C, 'Select word right', lisKMSelectWordRight, ecSelWordRight);
AddDefault(C, 'Select line start', lisKMSelectLineStart, ecSelLineStart);
AddDefault(C, 'Select to text start in line', srkmecSelLineTextStart, ecSelLineTextStart);
AddDefault(C, 'Select line end', lisKMSelectLineEnd, ecSelLineEnd);
AddDefault(C, 'Select page top', lisKMSelectPageTop, ecSelPageTop);
AddDefault(C, 'Select page bottom', lisKMSelectPageBottom, ecSelPageBottom);
@ -2344,6 +2349,7 @@ begin
AddDefault(C, 'Column Select Page Up', srkmecColSelPageUp, ecColSelPageUp);
AddDefault(C, 'Column Select Page Top', srkmecColSelPageTop, ecColSelPageTop);
AddDefault(C, 'Column Select Line Start', srkmecColSelLineStart, ecColSelLineStart);
AddDefault(C, 'Column Select to text start in line', srkmecColSelLineTextStart, ecColSelLineTextStart);
AddDefault(C, 'Column Select Line End', srkmecColSelLineEnd, ecColSelLineEnd);
AddDefault(C, 'Column Select to absolute beginning', srkmecColSelEditorTop, ecColSelEditorTop);
AddDefault(C, 'Column Select to absolute end', srkmecColSelEditorBottom, ecColSelEditorBottom);

View File

@ -2057,6 +2057,7 @@ resourcestring
srkmecEditorTop = 'Move cursor to absolute beginning';
srkmecEditorBottom = 'Move cursor to absolute end';
srkmecGotoXY = 'Goto XY';
srkmecLineTextStart = 'Move cursor to text start in line';
srkmecSelLeft = 'SelLeft';
srkmecSelRight = 'SelRight';
srkmecSelUp = 'Select Up';
@ -2073,6 +2074,7 @@ resourcestring
srkmecSelPageBottom = 'Select Page Bottom';
srkmecSelEditorTop = 'Select to absolute beginning';
srkmecSelEditorBottom = 'Select to absolute end';
srkmecSelLineTextStart = 'Select to text start in line';
srkmecColSelUp = 'Column Select Up';
srkmecColSelDown = 'Column Select Down';
srkmecColSelLeft = 'Column Select Left';
@ -2087,6 +2089,7 @@ resourcestring
srkmecColSelLineEnd = 'Column Select Line End';
srkmecColSelEditorTop = 'Column Select to absolute beginning';
srkmecColSelEditorBottom = 'Column Select to absolute end';
srkmecColSelLineTextStart = 'Column Select to text start in line';
srkmecSelGotoXY = 'Select Goto XY';
srkmecSelectAll = 'Select All';
srkmecDeleteLastChar = 'Delete Last Char';