mirror of https://gitlab.com/basile.b/dexed.git
editor, comment selection, align comments
+ fix brace auto-closing bug (on new line + tab2sapces not activated)
This commit is contained in:
parent
abfb1728d3
commit
1e73d618b5
|
@ -794,19 +794,30 @@ begin
|
||||||
editor.CommandProcessor(ecInsertLine, '', nil);
|
editor.CommandProcessor(ecInsertLine, '', nil);
|
||||||
editor.CommandProcessor(ecDown, '', nil);
|
editor.CommandProcessor(ecDown, '', nil);
|
||||||
while editor.CaretX <> 1 do editor.CommandProcessor(ecLeft, '' , nil);
|
while editor.CaretX <> 1 do editor.CommandProcessor(ecLeft, '' , nil);
|
||||||
for j := 1 to i do editor.CommandProcessor(ecChar, beg[j], nil);
|
for j := 1 to i do
|
||||||
|
begin
|
||||||
|
if beg[j] = #9 then
|
||||||
|
editor.CommandProcessor(ecTab, '', nil)
|
||||||
|
else
|
||||||
|
editor.CommandProcessor(ecChar, beg[j], nil);
|
||||||
|
end;
|
||||||
editor.CommandProcessor(ecChar, '}', nil);
|
editor.CommandProcessor(ecChar, '}', nil);
|
||||||
editor.CommandProcessor(ecUp, '', nil);
|
editor.CommandProcessor(ecUp, '', nil);
|
||||||
for j := 1 to i do editor.CommandProcessor(ecChar, beg[j], nil);
|
for j := 1 to i do
|
||||||
|
begin
|
||||||
|
if beg[j] = #9 then
|
||||||
|
editor.CommandProcessor(ecTab, '', nil)
|
||||||
|
else
|
||||||
|
editor.CommandProcessor(ecChar, beg[j], nil);
|
||||||
|
end;
|
||||||
editor.CommandProcessor(ecTab, '', nil);
|
editor.CommandProcessor(ecTab, '', nil);
|
||||||
while editor.CaretX > 1 + i + editor.TabWidth do editor.CommandProcessor(ecLeft, '' , nil);
|
while editor.LogicalCaretXY.X > 1 + i + editor.TabWidth do editor.CommandProcessor(ecLeft, '' , nil);
|
||||||
editor.EndUndoBlock;
|
editor.EndUndoBlock;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure commentSelection(editor: TSynEdit);
|
procedure commentSelection(editor: TSynEdit);
|
||||||
procedure commentHere;
|
procedure commentHere;
|
||||||
begin
|
begin
|
||||||
editor.ExecuteCommand(ecLineTextStart, '', nil);
|
|
||||||
editor.ExecuteCommand(ecChar, '/', nil);
|
editor.ExecuteCommand(ecChar, '/', nil);
|
||||||
editor.ExecuteCommand(ecChar, '/', nil);
|
editor.ExecuteCommand(ecChar, '/', nil);
|
||||||
end;
|
end;
|
||||||
|
@ -817,7 +828,7 @@ procedure commentSelection(editor: TSynEdit);
|
||||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
||||||
end;
|
end;
|
||||||
var
|
var
|
||||||
i: integer;
|
i, j, dx, lx, numUndo: integer;
|
||||||
line: string;
|
line: string;
|
||||||
undo: boolean = false;
|
undo: boolean = false;
|
||||||
pt, cp: TPoint;
|
pt, cp: TPoint;
|
||||||
|
@ -828,6 +839,7 @@ begin
|
||||||
line := TrimLeft(editor.LineText);
|
line := TrimLeft(editor.LineText);
|
||||||
undo := (line.length > 1) and (line[1..2] = '//');
|
undo := (line.length > 1) and (line[1..2] = '//');
|
||||||
editor.BeginUndoBlock;
|
editor.BeginUndoBlock;
|
||||||
|
editor.ExecuteCommand(ecLineTextStart, '', nil);
|
||||||
if not undo then
|
if not undo then
|
||||||
begin
|
begin
|
||||||
commentHere;
|
commentHere;
|
||||||
|
@ -841,25 +853,38 @@ begin
|
||||||
editor.EndUndoBlock;
|
editor.EndUndoBlock;
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
pt.X:= 0;
|
undo := false;
|
||||||
|
pt.X:= high(pt.X);
|
||||||
cp := editor.CaretXY;
|
cp := editor.CaretXY;
|
||||||
|
numUndo := 0;
|
||||||
for i := editor.BlockBegin.Y-1 to editor.BlockEnd.Y-1 do
|
for i := editor.BlockBegin.Y-1 to editor.BlockEnd.Y-1 do
|
||||||
begin
|
begin
|
||||||
line := TrimLeft(editor.Lines[i]);
|
line := TrimLeft(editor.Lines[i]);
|
||||||
|
dx := editor.Lines[i].length - line.length;
|
||||||
|
lx := 0;
|
||||||
|
for j := 1 to dx do
|
||||||
|
if editor.Lines[i][j] = #9 then
|
||||||
|
lx += editor.TabWidth
|
||||||
|
else
|
||||||
|
lx += 1;
|
||||||
|
if lx + 1 < pt.X then
|
||||||
|
pt.X:= lx + 1;
|
||||||
if (line.length > 1) and (line[1..2] = '//') then
|
if (line.length > 1) and (line[1..2] = '//') then
|
||||||
undo := true
|
numUndo += 1;
|
||||||
else begin
|
|
||||||
undo := false;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
if numUndo = 0 then
|
||||||
|
undo := false
|
||||||
|
else if numUndo = editor.BlockEnd.Y + 1 - editor.BlockBegin.Y then
|
||||||
|
undo := true;
|
||||||
editor.BeginUndoBlock;
|
editor.BeginUndoBlock;
|
||||||
for i := editor.BlockBegin.Y to editor.BlockEnd.Y do
|
for i := editor.BlockBegin.Y to editor.BlockEnd.Y do
|
||||||
begin
|
begin
|
||||||
pt.Y:= i;
|
pt.Y:= i;
|
||||||
editor.ExecuteCommand(ecGotoXY, '', @pt);
|
editor.ExecuteCommand(ecGotoXY, '', @pt);
|
||||||
if not undo then
|
if not undo then
|
||||||
commentHere
|
begin
|
||||||
|
commentHere;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
unCommentHere;
|
unCommentHere;
|
||||||
end;
|
end;
|
||||||
|
@ -1397,7 +1422,7 @@ begin
|
||||||
if Key = VK_RETURN then
|
if Key = VK_RETURN then
|
||||||
begin
|
begin
|
||||||
if (fAutoCloseCurlyBrace in [autoCloseOnNewLineEof .. autoCloseOnNewLineLexically])
|
if (fAutoCloseCurlyBrace in [autoCloseOnNewLineEof .. autoCloseOnNewLineLexically])
|
||||||
and (CaretX > 1) and (LineText[CaretX-1] = '{') then
|
and (CaretX > 1) and (LineText[LogicalCaretXY.X - 1] = '{') then
|
||||||
case fAutoCloseCurlyBrace of
|
case fAutoCloseCurlyBrace of
|
||||||
autoCloseOnNewLineAlways:
|
autoCloseOnNewLineAlways:
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Reference in New Issue