add option top insert * or + on newline in ddoc, close #138

This commit is contained in:
Basile Burg 2017-04-27 15:30:09 +02:00
parent 6be3267993
commit b5f2822abb
No known key found for this signature in database
GPG Key ID: 1868039F415CB8CF
2 changed files with 76 additions and 9 deletions

View File

@ -62,6 +62,7 @@ type
fPhobosDocRoot: TCEPathname; fPhobosDocRoot: TCEPathname;
fAlwaysAdvancedFeatures: boolean; fAlwaysAdvancedFeatures: boolean;
fAutoClosedPairs: TAutoClosePairs; fAutoClosedPairs: TAutoClosePairs;
fSmartDdocNewline: boolean;
// //
procedure setPhobosDocRoot(value: TCEPathname); procedure setPhobosDocRoot(value: TCEPathname);
procedure setFont(value: TFont); procedure setFont(value: TFont);
@ -111,6 +112,7 @@ type
property rightEdgeColor: TColor read fRightEdgeColor write fRightEdgeColor default clSilver; property rightEdgeColor: TColor read fRightEdgeColor write fRightEdgeColor default clSilver;
property selection: TSynSelectedColor read fSelAttribs write setSelCol; property selection: TSynSelectedColor read fSelAttribs write setSelCol;
property shortcuts: TCollection read fShortCuts write setShortcuts; property shortcuts: TCollection read fShortCuts write setShortcuts;
property smartDdocNewline: boolean read fSmartDdocNewline write fSmartDdocNewline;
property tabulationWidth: Integer read fTabWidth write fTabWidth default 4; property tabulationWidth: Integer read fTabWidth write fTabWidth default 4;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -303,6 +305,10 @@ begin
detectIndentMode:=srcopt.detectIndentMode; detectIndentMode:=srcopt.detectIndentMode;
fPhobosDocRoot:=srcopt.fPhobosDocRoot; fPhobosDocRoot:=srcopt.fPhobosDocRoot;
fSmartDdocNewline:=srcopt.fSmartDdocNewline;
if fSmartDdocNewline then
fOptions1 += [eoAutoIndent];
tabulationWidth := srcopt.tabulationWidth; tabulationWidth := srcopt.tabulationWidth;
blockIndentation := srcopt.blockIndentation; blockIndentation := srcopt.blockIndentation;
lineSpacing := srcopt.lineSpacing; lineSpacing := srcopt.lineSpacing;
@ -667,6 +673,7 @@ begin
anEditor.detectIndentMode := detectIndentMode; anEditor.detectIndentMode := detectIndentMode;
anEditor.phobosDocRoot:=fPhobosDocRoot; anEditor.phobosDocRoot:=fPhobosDocRoot;
anEditor.alwaysAdvancedFeatures:=fAlwaysAdvancedFeatures; anEditor.alwaysAdvancedFeatures:=fAlwaysAdvancedFeatures;
anEditor.smartDdocNewline:= fSmartDdocNewline;
for i := 0 to anEditor.Keystrokes.Count-1 do for i := 0 to anEditor.Keystrokes.Count-1 do
begin begin
kst := anEditor.Keystrokes.Items[i]; kst := anEditor.Keystrokes.Items[i];

View File

@ -168,6 +168,7 @@ type
fCallTipStrings: TStringList; fCallTipStrings: TStringList;
fOverrideColMode: boolean; fOverrideColMode: boolean;
fAutoCloseCurlyBrace: TBraceAutoCloseStyle; fAutoCloseCurlyBrace: TBraceAutoCloseStyle;
fSmartDdocNewline: boolean;
fLexToks: TLexTokenList; fLexToks: TLexTokenList;
fDisableFileDateCheck: boolean; fDisableFileDateCheck: boolean;
fDetectIndentMode: boolean; fDetectIndentMode: boolean;
@ -203,6 +204,7 @@ type
var SourceStart, SourceEnd: TPoint; KeyChar: TUTF8Char; Shift: TShiftState); var SourceStart, SourceEnd: TPoint; KeyChar: TUTF8Char; Shift: TShiftState);
procedure showCallTips(const tips: string); procedure showCallTips(const tips: string);
function lexCanCloseBrace: boolean; function lexCanCloseBrace: boolean;
function lexInDdoc: char;
procedure handleStatusChanged(Sender: TObject; Changes: TSynStatusChanges); procedure handleStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
procedure gotoToChangedArea(next: boolean); procedure gotoToChangedArea(next: boolean);
procedure gotoToProtectionGroup(next: boolean); procedure gotoToProtectionGroup(next: boolean);
@ -255,6 +257,7 @@ type
procedure saveTempFile; procedure saveTempFile;
// //
procedure curlyBraceCloseAndIndent; procedure curlyBraceCloseAndIndent;
procedure insertLeadingDDocSymbol(c: char);
procedure commentSelection; procedure commentSelection;
procedure commentIdentifier; procedure commentIdentifier;
procedure renameIdentifier; procedure renameIdentifier;
@ -301,6 +304,7 @@ type
property autoDotDelay: Integer read fAutoDotDelay write setAutoDotDelay; property autoDotDelay: Integer read fAutoDotDelay write setAutoDotDelay;
property autoCloseCurlyBrace: TBraceAutoCloseStyle read fAutoCloseCurlyBrace write fAutoCloseCurlyBrace; property autoCloseCurlyBrace: TBraceAutoCloseStyle read fAutoCloseCurlyBrace write fAutoCloseCurlyBrace;
property autoClosedPairs: TAutoClosePairs read fAutoClosedPairs write fAutoClosedPairs; property autoClosedPairs: TAutoClosePairs read fAutoClosedPairs write fAutoClosedPairs;
property smartDdocNewline: boolean read fSmartDdocNewline write fSmartDdocNewline;
end; end;
TSortDialog = class(TForm) TSortDialog = class(TForm)
@ -697,6 +701,7 @@ begin
Font.Size:=10; Font.Size:=10;
SetDefaultCoeditKeystrokes(Self); // not called in inherited if owner = nil ! SetDefaultCoeditKeystrokes(Self); // not called in inherited if owner = nil !
fLexToks:= TLexTokenList.Create; fLexToks:= TLexTokenList.Create;
fSmartDdocNewline := true;
OnDragDrop:= @ddHandler.DragDrop; OnDragDrop:= @ddHandler.DragDrop;
OnDragOver:= @ddHandler.DragOver; OnDragOver:= @ddHandler.DragOver;
@ -1135,6 +1140,15 @@ begin
end; end;
end; end;
procedure TCESynMemo.insertLeadingDDocSymbol(c: char);
begin
BeginUndoBlock;
if ((CaretX-1) and 1) = 0 then
ExecuteCommand(ecChar, ' ', nil);
ExecuteCommand(ecChar, c, nil);
EndUndoBlock;
end;
procedure TCESynMemo.curlyBraceCloseAndIndent; procedure TCESynMemo.curlyBraceCloseAndIndent;
var var
i: integer; i: integer;
@ -2131,6 +2145,8 @@ procedure TCESynMemo.handleStatusChanged(Sender: TObject; Changes: TSynStatusCha
begin begin
if scOptions in Changes then if scOptions in Changes then
begin begin
if fSmartDdocNewline and not (eoAutoIndent in Options) then
Options := Options + [eoAutoIndent];
if Beautifier.isNotNil and (Beautifier is TSynBeautifier) then if Beautifier.isNotNil and (Beautifier is TSynBeautifier) then
begin begin
if not (eoTabsToSpaces in Options) and not (eoSpacesToTabs in Options) then if not (eoTabsToSpaces in Options) and not (eoSpacesToTabs in Options) then
@ -2181,6 +2197,32 @@ begin
end; end;
end; end;
function TCESynMemo.lexInDdoc: char;
var
i: integer;
p: integer;
tk1: PLexToken = nil;
tk2: PLexToken = nil;
begin
result := #0;
p := SelStart;
for i := 0 to fLexToks.Count-1 do
begin
tk1 := fLexToks[i];
if (i <> fLexToks.Count-1) then
begin
tk2 := fLexToks[i+1];
if (tk1^.offset < p) and (tk1^.kind in [ltkComment, ltkIllegal])
and (tk2^.offset > p) then
exit(tk1^.Data[1])
else if (tk1^.offset > p) then
exit;
end
else if (tk1^.offset < p) and (tk1^.kind in [ltkComment, ltkIllegal]) then
exit(tk1^.Data[1]);
end;
end;
function TCESynMemo.lexCanCloseBrace: boolean; function TCESynMemo.lexCanCloseBrace: boolean;
var var
i: integer; i: integer;
@ -2502,6 +2544,7 @@ end;
procedure TCESynMemo.KeyDown(var Key: Word; Shift: TShiftState); procedure TCESynMemo.KeyDown(var Key: Word; Shift: TShiftState);
var var
line: string; line: string;
ddc: char;
begin begin
case Key of case Key of
VK_BACK: if fCallTipWin.Visible and (CaretX > 1) VK_BACK: if fCallTipWin.Visible and (CaretX > 1)
@ -2510,7 +2553,7 @@ begin
VK_RETURN: VK_RETURN:
begin begin
line := LineText; line := LineText;
if (fAutoCloseCurlyBrace in [autoCloseOnNewLineEof .. autoCloseOnNewLineLexically]) then
case fAutoCloseCurlyBrace of case fAutoCloseCurlyBrace of
autoCloseOnNewLineAlways: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then autoCloseOnNewLineAlways: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
begin begin
@ -2523,17 +2566,34 @@ begin
Key := 0; Key := 0;
curlyBraceCloseAndIndent; curlyBraceCloseAndIndent;
end; end;
autoCloseOnNewLineLexically: if (LogicalCaretXY.X - 1 >= line.length) end;
or isBlank(line[LogicalCaretXY.X .. line.length]) then
if (fAutoCloseCurlyBrace = autoCloseOnNewLineLexically) or
fSmartDdocNewline then
begin begin
fLexToks.Clear; fLexToks.Clear;
lex(lines.Text, fLexToks); lex(lines.Text, fLexToks);
if (LogicalCaretXY.X - 1 >= line.length)
or isBlank(line[LogicalCaretXY.X .. line.length]) then
begin
if lexCanCloseBrace then if lexCanCloseBrace then
begin begin
Key := 0; Key := 0;
curlyBraceCloseAndIndent; curlyBraceCloseAndIndent;
end; end;
end; end;
if (fSmartDdocNewline) then
begin
ddc := lexInDdoc;
if ddc in ['*', '+'] then
begin
inherited;
insertLeadingDDocSymbol(ddc);
fCanShowHint:=false;
fDDocWin.Hide;
exit;
end;
end;
end; end;
end; end;
end; end;