SynEdit: Syncro-Edit, fixed interference with trim space

git-svn-id: trunk@33158 -
This commit is contained in:
martin 2011-10-29 22:44:58 +00:00
parent cd8bcdaa55
commit fafe5534bc
2 changed files with 28 additions and 16 deletions

View File

@ -219,7 +219,8 @@ type
procedure DoSelectionChanged(Sender: TObject); procedure DoSelectionChanged(Sender: TObject);
procedure DoScanSelection(Data: PtrInt); procedure DoScanSelection(Data: PtrInt);
procedure DoOnDeactivate; override; procedure DoOnDeactivate; override;
procedure DoBeforeEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean); override; procedure DoPreActiveEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean);
override;
function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo; function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean; HandleActionProc: TSynEditMouseActionHandler): Boolean;
@ -1023,6 +1024,7 @@ begin
if FWordIndex.MultiWordCount = 0 then exit; if FWordIndex.MultiWordCount = 0 then exit;
Mode := spseEditing; Mode := spseEditing;
Active := True;
AreaMarkupEnabled := True; AreaMarkupEnabled := True;
SetUndoStart; SetUndoStart;
@ -1100,7 +1102,7 @@ begin
If (not SelectionObj.SelAvail) or (SelectionObj.ActiveSelectionMode = smColumn) then begin If (not SelectionObj.SelAvail) or (SelectionObj.ActiveSelectionMode = smColumn) then begin
FLastSelStart := Point(-1,-1); FLastSelStart := Point(-1,-1);
FLastSelEnd := Point(-1,-1); FLastSelEnd := Point(-1,-1);
if Active then begin if Active or PreActive then begin
FWordIndex.Clear; FWordIndex.Clear;
Editor.Invalidate; Editor.Invalidate;
Active := False; Active := False;
@ -1116,7 +1118,7 @@ begin
Cells.Clear; Cells.Clear;
AreaMarkupEnabled := False; AreaMarkupEnabled := False;
MarkupEnabled := False; MarkupEnabled := False;
Active := True; PreActive := True;
end; end;
Mode := spseSelecting; Mode := spseSelecting;
Markup.GlyphAtLine := -1; Markup.GlyphAtLine := -1;
@ -1237,15 +1239,12 @@ begin
inherited DoOnDeactivate; inherited DoOnDeactivate;
end; end;
procedure TSynPluginSyncroEdit.DoBeforeEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean); procedure TSynPluginSyncroEdit.DoPreActiveEdit(aX, aY, aCount, aLineBrkCnt: Integer;
aUndoRedo: Boolean);
begin begin
if (Mode = spseSelecting) then begin
FWordIndex.Clear; FWordIndex.Clear;
Active := False; Active := False;
Mode := spseInvalid; Mode := spseInvalid;
end
else
inherited DoBeforeEdit(aX, aY, aCount, aLineBrkCnt, aUndoRedo);
end; end;
function TSynPluginSyncroEdit.MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo; function TSynPluginSyncroEdit.MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
@ -1253,7 +1252,7 @@ function TSynPluginSyncroEdit.MaybeHandleMouseAction(var AnInfo: TSynEditMouseAc
var var
r: TRect; r: TRect;
begin begin
Result := Active and Result := (Active or PreActive) and
( ((Mode = spseSelecting) and (MarkupEnabled = True)) or ( ((Mode = spseSelecting) and (MarkupEnabled = True)) or
(Mode = spseEditing) ); (Mode = spseEditing) );
if not Result then exit; if not Result then exit;
@ -1323,7 +1322,7 @@ procedure TSynPluginSyncroEdit.TranslateKey(Sender: TObject; Code: word; SState:
var var
keys: TSynEditKeyStrokes; keys: TSynEditKeyStrokes;
begin begin
if (not Active) or Handled then if (not (Active or PreActive)) or Handled then
exit; exit;
keys := nil; keys := nil;
@ -1367,7 +1366,7 @@ procedure TSynPluginSyncroEdit.ProcessSynCommand(Sender: TObject; AfterProcessin
var var
Cmd: TSynEditorCommand; Cmd: TSynEditorCommand;
begin begin
if Handled or AfterProcessing or not Active then exit; if Handled or AfterProcessing or not (Active or PreActive) then exit;
if Mode = spseSelecting then begin if Mode = spseSelecting then begin
// todo: finish word-hash calculations / check if any cells exist // todo: finish word-hash calculations / check if any cells exist

View File

@ -179,6 +179,7 @@ type
fMarkupInfoArea: TSynSelectedColor; fMarkupInfoArea: TSynSelectedColor;
FOnActivate: TNotifyEvent; FOnActivate: TNotifyEvent;
FOnDeactivate: TNotifyEvent; FOnDeactivate: TNotifyEvent;
FPreActive: Boolean;
function GetActive: Boolean; function GetActive: Boolean;
procedure SetActive(const AValue: Boolean); procedure SetActive(const AValue: Boolean);
@ -195,6 +196,7 @@ type
procedure DoLinesEdited(Sender: TSynEditStrings; aLinePos, aBytePos, aCount, procedure DoLinesEdited(Sender: TSynEditStrings; aLinePos, aBytePos, aCount,
aLineBrkCnt: Integer; aText: String); aLineBrkCnt: Integer; aText: String);
procedure ApplyChangeList; procedure ApplyChangeList;
procedure DoPreActiveEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean); virtual;
procedure DoBeforeEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean); virtual; procedure DoBeforeEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean); virtual;
procedure DoAfterEdit(aX, aY: Integer; aUndoRedo: Boolean); virtual; procedure DoAfterEdit(aX, aY: Integer; aUndoRedo: Boolean); virtual;
procedure DoPaintLockStarted; virtual; procedure DoPaintLockStarted; virtual;
@ -216,6 +218,7 @@ type
procedure Clear; procedure Clear;
property Enabled: Boolean read FEnabled write SetEnabled; property Enabled: Boolean read FEnabled write SetEnabled;
property Active: Boolean read GetActive write SetActive; property Active: Boolean read GetActive write SetActive;
property PreActive: Boolean read FPreActive write FPreActive; // e.g. collecting words => Reacts to LinesEdited
property MarkupInfo: TSynSelectedColor read FMarkupInfo; property MarkupInfo: TSynSelectedColor read FMarkupInfo;
property MarkupInfoCurrent: TSynSelectedColor read FMarkupInfoCurrent; property MarkupInfoCurrent: TSynSelectedColor read FMarkupInfoCurrent;
@ -753,7 +756,7 @@ begin
FMarkup := CreateMarkup; FMarkup := CreateMarkup;
FMarkup.Cells := FCells; FMarkup.Cells := FCells;
FMarkup.CurrentCell := FCurrentCell; FMarkup.CurrentCell := FCurrentCell;
FMarkup.Enabled := Active; FMarkup.Enabled := (Active or PreActive) and FMarkupEnabled;
TSynEditMarkupManager(MarkupMgr).AddMarkUp(FMarkup); TSynEditMarkupManager(MarkupMgr).AddMarkUp(FMarkup);
FMarkupArea := TSynPluginSyncronizedEditMarkupArea.Create(Editor); FMarkupArea := TSynPluginSyncronizedEditMarkupArea.Create(Editor);
FMarkupArea.Cells := FCells; FMarkupArea.Cells := FCells;
@ -789,7 +792,7 @@ begin
IsActive := Active; IsActive := Active;
FEnabled := AValue; FEnabled := AValue;
if FMarkup <> nil then if FMarkup <> nil then
FMarkup.Enabled := Active and FMarkupEnabled; FMarkup.Enabled := (Active or PreActive) and FMarkupEnabled;
if FMarkupArea <> nil then if FMarkupArea <> nil then
FMarkupArea.Enabled := Active and FAreaMarkupEnabled; FMarkupArea.Enabled := Active and FAreaMarkupEnabled;
if IsActive <> Active then begin if IsActive <> Active then begin
@ -804,7 +807,7 @@ begin
if FMarkupEnabled = AValue then exit; if FMarkupEnabled = AValue then exit;
FMarkupEnabled := AValue; FMarkupEnabled := AValue;
if FMarkup <> nil then if FMarkup <> nil then
FMarkup.Enabled := Active and FMarkupEnabled; FMarkup.Enabled := (Active or PreActive) and FMarkupEnabled;
end; end;
procedure TSynPluginSyncronizedEditBase.MarkupChanged(AMarkup: TObject); procedure TSynPluginSyncronizedEditBase.MarkupChanged(AMarkup: TObject);
@ -834,8 +837,9 @@ var
begin begin
IsActive := Active; IsActive := Active;
FActive := AValue; FActive := AValue;
PreActive := False; // change in active, always disables PreActive
if FMarkup <> nil then if FMarkup <> nil then
FMarkup.Enabled := Active and FMarkupEnabled; FMarkup.Enabled := (Active or PreActive) and FMarkupEnabled;
if FMarkupArea <> nil then if FMarkupArea <> nil then
FMarkupArea.Enabled := Active and FAreaMarkupEnabled; FMarkupArea.Enabled := Active and FAreaMarkupEnabled;
if IsActive <> Active then begin if IsActive <> Active then begin
@ -886,7 +890,10 @@ var
edit: Boolean; edit: Boolean;
CellAtPos: Integer; CellAtPos: Integer;
begin begin
if not Active then exit; if not Active then begin
if PreActive then DoPreActiveEdit(aBytePos, aLinePos, aCount, aLineBrkCnt, IsUndoing or IsRedoing);
exit;
end;
Pos := Point(aBytePos, aLinePos); Pos := Point(aBytePos, aLinePos);
Pos2 := Pos; Pos2 := Pos;
if not FEditing then if not FEditing then
@ -992,6 +999,12 @@ begin
FChangeList.Clear; FChangeList.Clear;
end; end;
procedure TSynPluginSyncronizedEditBase.DoPreActiveEdit(aX, aY, aCount, aLineBrkCnt: Integer;
aUndoRedo: Boolean);
begin
//
end;
procedure TSynPluginSyncronizedEditBase.DoBeforeEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean); procedure TSynPluginSyncronizedEditBase.DoBeforeEdit(aX, aY, aCount, aLineBrkCnt: Integer; aUndoRedo: Boolean);
begin begin
(* Do Nothing *); (* Do Nothing *);