SynEdit, IDE: Fix phys/logic char pos in autocomplete. Issue #0026038

git-svn-id: trunk@44755 -
This commit is contained in:
martin 2014-04-17 22:25:13 +00:00
parent f46dd07c9d
commit 845d3c0084
3 changed files with 13 additions and 11 deletions

View File

@ -373,7 +373,7 @@ begin
AEditor.SelText := ''; AEditor.SelText := '';
AEditor.SetTextBetweenPoints(p2, p2, s, [], scamEnd); AEditor.SetTextBetweenPoints(p2, p2, s, [], scamEnd);
if NewCaretPos then if NewCaretPos then
AEditor.CaretXY := p; AEditor.LogicalCaretXY := p;
AEditor.EnsureCursorPosVisible; AEditor.EnsureCursorPosVisible;
finally finally
AEditor.EndUpdate; AEditor.EndUpdate;

View File

@ -74,7 +74,7 @@ type
class function ConvertCommandToBase(Command: TSynEditorCommand): TSynEditorCommand; class function ConvertCommandToBase(Command: TSynEditorCommand): TSynEditorCommand;
class function ConvertBaseToCommand(Command: TSynEditorCommand): TSynEditorCommand; class function ConvertBaseToCommand(Command: TSynEditorCommand): TSynEditorCommand;
procedure SetTemplate(aTmpl: String; aCaretPos: TPoint); // Replaces current selection procedure SetTemplate(aTmpl: String; aLogCaretPos: TPoint); // Replaces current selection
// Coords relativ to the template. base (1, 1) // Coords relativ to the template. base (1, 1)
procedure AddEditCells(aCellList: TSynPluginSyncronizedEditList); procedure AddEditCells(aCellList: TSynPluginSyncronizedEditList);
@ -296,7 +296,7 @@ begin
Active := False; Active := False;
end; end;
procedure TSynPluginTemplateEdit.SetTemplate(aTmpl: String; aCaretPos: TPoint); procedure TSynPluginTemplateEdit.SetTemplate(aTmpl: String; aLogCaretPos: TPoint);
var var
Temp: TStringList; Temp: TStringList;
CellStart, StartPos: TPoint; CellStart, StartPos: TPoint;
@ -383,8 +383,8 @@ begin
Editor.SelText := aTmpl; Editor.SelText := aTmpl;
with Cells.AddNew do begin with Cells.AddNew do begin
Group := -2; Group := -2;
LogStart := aCaretPos; LogStart := aLogCaretPos;
LogEnd := aCaretPos; LogEnd := aLogCaretPos;
end; end;
if (Cells.Count > 1) then begin if (Cells.Count > 1) then begin
Active := True; Active := True;
@ -394,7 +394,7 @@ begin
SetUndoStart; SetUndoStart;
end end
else else
Editor.MoveCaretIgnoreEOL(aCaretPos); Editor.MoveCaretIgnoreEOL(Editor.LogicalToPhysicalPos(aLogCaretPos));
end; end;
procedure TSynPluginTemplateEdit.AddEditCells(aCellList: TSynPluginSyncronizedEditList); procedure TSynPluginTemplateEdit.AddEditCells(aCellList: TSynPluginSyncronizedEditList);

View File

@ -457,7 +457,7 @@ var
p: TPoint; p: TPoint;
TokenStartX: LongInt; TokenStartX: LongInt;
s: string; s: string;
BaseIndent: Integer; BaseIndent, LogBaseIndent: Integer;
i: Integer; i: Integer;
j: LongInt; j: LongInt;
Pattern: String; Pattern: String;
@ -491,13 +491,14 @@ begin
and ((BaseIndent>length(s)) or (s[BaseIndent] in [#9,' '])) do and ((BaseIndent>length(s)) or (s[BaseIndent] in [#9,' '])) do
inc(BaseIndent); inc(BaseIndent);
end; end;
LogBaseIndent := BaseIndent - 1;
BaseIndent:=AEditor.LogicalToPhysicalCol(s, p.y - 1, BaseIndent);// consider tabs BaseIndent:=AEditor.LogicalToPhysicalCol(s, p.y - 1, BaseIndent);// consider tabs
dec(BaseIndent); dec(BaseIndent);
end; end;
Parser.EnableMacros := Attributes.IndexOfName(CodeTemplateEnableMacros)>=0; Parser.EnableMacros := Attributes.IndexOfName(CodeTemplateEnableMacros)>=0;
Parser.KeepSubIndent := Attributes.IndexOfName(CodeTemplateKeepSubIndent)>=0; Parser.KeepSubIndent := Attributes.IndexOfName(CodeTemplateKeepSubIndent)>=0;
Parser.Indent := BaseIndent; Parser.Indent := LogBaseIndent;
CodeToolBossOriginalIndent := CodeToolBoss.IndentSize; CodeToolBossOriginalIndent := CodeToolBoss.IndentSize;
if Parser.KeepSubIndent then if Parser.KeepSubIndent then
CodeToolBoss.IndentSize := BaseIndent // Use additional indentation CodeToolBoss.IndentSize := BaseIndent // Use additional indentation
@ -522,11 +523,12 @@ begin
AEditor.BlockEnd := p; AEditor.BlockEnd := p;
// New Caret // New Caret
p := Parser.DestCaret; p := Parser.DestCaret; // Logical
if p.y >= 0 then begin if p.y >= 0 then begin
if p.y = 1 then if p.y = 1 then
p.x := p.x + TokenStartX - 1; p.x := p.x + TokenStartX - 1;
p.y := p.y + AEditor.BlockBegin.y - 1; // Todo: logicalToPhysical p.y := p.y + AEditor.BlockBegin.y - 1;
// p must be logical, until template text is inserted
end; end;
// delete double end separator (e.g. avoid creating two semicolons 'begin end;;') // delete double end separator (e.g. avoid creating two semicolons 'begin end;;')
@ -560,7 +562,7 @@ begin
// replace the selected text and position the caret // replace the selected text and position the caret
AEditor.SetTextBetweenPoints(AEditor.BlockBegin, AEditor.BlockEnd, Parser.DestTemplate, [], scamEnd); AEditor.SetTextBetweenPoints(AEditor.BlockBegin, AEditor.BlockEnd, Parser.DestTemplate, [], scamEnd);
if p.y > 0 then if p.y > 0 then
AEditor.MoveCaretIgnoreEOL(p); AEditor.MoveCaretIgnoreEOL(AEditor.LogicalToPhysicalPos(p));
end; end;
finally finally
AEditor.EndUpdate; AEditor.EndUpdate;