diff --git a/components/synedit/syneditautocomplete.pp b/components/synedit/syneditautocomplete.pp index c234a4b1fb..26a5f9e99c 100644 --- a/components/synedit/syneditautocomplete.pp +++ b/components/synedit/syneditautocomplete.pp @@ -373,7 +373,7 @@ begin AEditor.SelText := ''; AEditor.SetTextBetweenPoints(p2, p2, s, [], scamEnd); if NewCaretPos then - AEditor.CaretXY := p; + AEditor.LogicalCaretXY := p; AEditor.EnsureCursorPosVisible; finally AEditor.EndUpdate; diff --git a/components/synedit/synplugintemplateedit.pp b/components/synedit/synplugintemplateedit.pp index 2326bade21..ec37f908d9 100644 --- a/components/synedit/synplugintemplateedit.pp +++ b/components/synedit/synplugintemplateedit.pp @@ -74,7 +74,7 @@ type class function ConvertCommandToBase(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) procedure AddEditCells(aCellList: TSynPluginSyncronizedEditList); @@ -296,7 +296,7 @@ begin Active := False; end; -procedure TSynPluginTemplateEdit.SetTemplate(aTmpl: String; aCaretPos: TPoint); +procedure TSynPluginTemplateEdit.SetTemplate(aTmpl: String; aLogCaretPos: TPoint); var Temp: TStringList; CellStart, StartPos: TPoint; @@ -383,8 +383,8 @@ begin Editor.SelText := aTmpl; with Cells.AddNew do begin Group := -2; - LogStart := aCaretPos; - LogEnd := aCaretPos; + LogStart := aLogCaretPos; + LogEnd := aLogCaretPos; end; if (Cells.Count > 1) then begin Active := True; @@ -394,7 +394,7 @@ begin SetUndoStart; end else - Editor.MoveCaretIgnoreEOL(aCaretPos); + Editor.MoveCaretIgnoreEOL(Editor.LogicalToPhysicalPos(aLogCaretPos)); end; procedure TSynPluginTemplateEdit.AddEditCells(aCellList: TSynPluginSyncronizedEditList); diff --git a/ide/codemacroprompt.pas b/ide/codemacroprompt.pas index 47cd3290bc..01b59e5693 100644 --- a/ide/codemacroprompt.pas +++ b/ide/codemacroprompt.pas @@ -457,7 +457,7 @@ var p: TPoint; TokenStartX: LongInt; s: string; - BaseIndent: Integer; + BaseIndent, LogBaseIndent: Integer; i: Integer; j: LongInt; Pattern: String; @@ -491,13 +491,14 @@ begin and ((BaseIndent>length(s)) or (s[BaseIndent] in [#9,' '])) do inc(BaseIndent); end; + LogBaseIndent := BaseIndent - 1; BaseIndent:=AEditor.LogicalToPhysicalCol(s, p.y - 1, BaseIndent);// consider tabs dec(BaseIndent); end; Parser.EnableMacros := Attributes.IndexOfName(CodeTemplateEnableMacros)>=0; Parser.KeepSubIndent := Attributes.IndexOfName(CodeTemplateKeepSubIndent)>=0; - Parser.Indent := BaseIndent; + Parser.Indent := LogBaseIndent; CodeToolBossOriginalIndent := CodeToolBoss.IndentSize; if Parser.KeepSubIndent then CodeToolBoss.IndentSize := BaseIndent // Use additional indentation @@ -522,11 +523,12 @@ begin AEditor.BlockEnd := p; // New Caret - p := Parser.DestCaret; + p := Parser.DestCaret; // Logical if p.y >= 0 then begin if p.y = 1 then 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; // 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 AEditor.SetTextBetweenPoints(AEditor.BlockBegin, AEditor.BlockEnd, Parser.DestTemplate, [], scamEnd); if p.y > 0 then - AEditor.MoveCaretIgnoreEOL(p); + AEditor.MoveCaretIgnoreEOL(AEditor.LogicalToPhysicalPos(p)); end; finally AEditor.EndUpdate;