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

View File

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

View File

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

View File

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