diff --git a/components/synedit/test/testsyncroedit.pas b/components/synedit/test/testsyncroedit.pas index 864cf8af2c..075828dece 100644 --- a/components/synedit/test/testsyncroedit.pas +++ b/components/synedit/test/testsyncroedit.pas @@ -5,8 +5,8 @@ unit TestSyncroEdit; interface uses - Classes, SysUtils, testregistry, LCLProc, TestBase, - SynPluginSyncroEdit; + Classes, SysUtils, testregistry, LCLProc, LCLType, Forms, TestBase, + SynEdit, SynPluginSyncroEdit, SynEditKeyCmds; type @@ -14,9 +14,13 @@ type TTestSyncroEdit = class(TTestBase) protected + FSyncroModule: TSynPluginSyncroEdit; procedure Dump(hsh: TSynPluginSyncroEditWordsHash); + procedure ReCreateEdit; reintroduce; + procedure StartSyncroMode; published - procedure TestWordsHash; + procedure WordsHash; + procedure SyncroEdit; end; implementation @@ -42,7 +46,28 @@ begin end; end; -procedure TTestSyncroEdit.TestWordsHash; +procedure TTestSyncroEdit.ReCreateEdit; +begin + inherited; + FSyncroModule := TSynPluginSyncroEdit.Create(SynEdit); +end; + +procedure TTestSyncroEdit.StartSyncroMode; +var + i: Integer; +begin + //DoKeyPress(VK_J, [ssCtrl]); + SynEdit.CommandProcessor(ecSynPSyncroEdStart, '', nil); + i := 5; + while (i > 0) and (not FSyncroModule.Active) do begin + dec(i); + Application.ProcessMessages; + end; + AssertTrue('SyncroMode started', FSyncroModule.Active ); + Application.ProcessMessages; +end; + +procedure TTestSyncroEdit.WordsHash; var hsh: TSynPluginSyncroEditWordsHash; @@ -141,6 +166,881 @@ begin end; end; +procedure TTestSyncroEdit.SyncroEdit; +var + Name: String; + DoUndo: Boolean; + + procedure SetTestText(TextIdx: Integer = 0); + begin + case TextIdx of + 0: SetLines(['abc foo', // 1 + 'foo abc xy', // 2 + ' abc foo', // 4 + '', // 5 + 'foo' // 6 + ]); + 1: SetLines(['abc foo', // 1 + 'foo abc xy', // 2 + ' foo foo abc',//4 + '', // 5 + 'foo' // 6 + ]); + end; + end; + procedure InitTestText(X1, Y1, X2, Y2: Integer; TextIdx: Integer = 0); + begin + ReCreateEdit; + SynEdit.Options := SynEdit.Options - [eoGroupUndo, eoSmartTabDelete, eoSmartTabs] + [eoAutoIndent]; + SetTestText(TextIdx); + SetCaretAndSel(X1, Y1, X2, Y2); + StartSyncroMode; + end; + + procedure TestCmdAt(AName: String; X, Y: Integer; Cmd: TSynEditorCommand; + Exp: Array of String; SyncRunning: Boolean = True); + var + t: String; + begin + t := SynEdit.Text; + SetCaret(x, y); + SynEdit.CommandProcessor(Cmd, '', nil); + TestIsFullText(Format('Cmd at (%d,%d) %s / %s', [X, Y, Name, AName]), Exp); + AssertEquals(Format('Cmd at (%d,%d) %s / %s - Sync Running', [X, Y, Name, AName]), SyncRunning, FSyncroModule.Active ); + if not DoUndo then exit; + SynEdit.Undo; + TestIsFullText(Format('Cmd at (%d,%d) %s / %s UNDONE', [X, Y, Name, AName]), t); + SynEdit.Redo; + TestIsFullText(Format('Cmd at (%d,%d) %s / %s REDONE', [X, Y, Name, AName]), Exp); + AssertEquals(Format('Cmd at (%d,%d) %s / %s - REDONE Sync Running', [X, Y, Name, AName]), SyncRunning, FSyncroModule.Active ); + end; + + procedure TestKeyAt(AName: String; X, Y: Integer; Key: Word; Shift: TShiftState; + Exp: Array of String; SyncRunning: Boolean = True); + var + t: String; + begin + t := SynEdit.Text; + SetCaret(x, y); + DoKeyPress(Key, Shift); + TestIsFullText(Format('KeyPress at (%d,%d) %s / %s', [X, Y, Name, AName]), Exp); + AssertEquals(Format('KeyPress at (%d,%d) %s / %s - Sync Running', [X, Y, Name, AName]), SyncRunning, FSyncroModule.Active ); + if not DoUndo then exit; + SynEdit.Undo; + TestIsFullText(Format('KeyPress at (%d,%d) %s / %s UNDONE', [X, Y, Name, AName]), t); + SynEdit.Redo; + TestIsFullText(Format('KeyPress at (%d,%d) %s / %s REDONE', [X, Y, Name, AName]), Exp); + AssertEquals(Format('KeyPress at (%d,%d) %s / %s - REDONE Sync Running', [X, Y, Name, AName]), SyncRunning, FSyncroModule.Active ); + end; + + procedure TestKeyAtSel(AName: String; X, Y, X2, Y2: Integer; Key: Word; Shift: TShiftState; + Exp: Array of String; SyncRunning: Boolean = True); + var + t: String; + begin + t := SynEdit.Text; + SetCaretAndSel(x, y, X2, Y2); + DoKeyPress(Key, Shift); + TestIsFullText(Format('KeyPress+Sel at (%d,%d) %s / %s', [X, Y, Name, AName]), Exp); + AssertEquals(Format('KeyPress+Sel at (%d,%d) %s / %s - Sync Running', [X, Y, Name, AName]), SyncRunning, FSyncroModule.Active ); + if not DoUndo then exit; + SynEdit.Undo; + TestIsFullText(Format('KeyPress+Sel at (%d,%d) %s / %s UNDONE', [X, Y, Name, AName]), t); + SynEdit.Redo; + TestIsFullText(Format('KeyPress+Sel at (%d,%d) %s / %s REDONE', [X, Y, Name, AName]), Exp); + AssertEquals(Format('KeyPress+Sel at (%d,%d) %s / %s - REDONE Sync Running', [X, Y, Name, AName]), SyncRunning, FSyncroModule.Active ); + end; + + procedure TestSyncro; + begin + (* Edit at start/end of cell (insert/delete [backspace/del] ) + Edit cell, delete all, type again / Cut,Paste / newline + Edit selection at start/end/complete of cell (delete/replace) + Edit Cells, with 2 synced cells on same line + + Insert, delete linebreak in cell (with/without auto-indent) + - includes some trim space + - include 2 cells on one line + + Edit just before/after cell, while caret in cell (backspace at start / del at end) + - same with emptied cell + Edit just before/after cell, while caret in cell (selection outside cell / replace, delete) + - part in/ part out of cell + + External Edit outside cell +TODO External Edit inside current/other cell (or while caret outside any cell) + +TODO Lines[x] := ''; Lines.Add(); should deactivate the syncroMode + + TODO: more trim-space + TODO: Delete word / last word => restrain to cell + TODO: Change trim spaces, so it does keep spaces after undo + see note in tests + *) + + {%region Edit at start/end of cell (insert/delete [backspace/del] ) } + {%region 'Insert/KeyPress inside cell' } + name := 'Insert/KeyPress inside cell'; + InitTestText(1,2, 1,4); + TestKeyAt('Insert at Cell FOO (1 of 2), pos=1', 1, 2, VK_M, [], + ['abc foo', + 'mfoo abc xy', + ' abc mfoo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('insert at cell FOO (1 of 2), pos=end', 4, 2, VK_M, [], + ['abc foo', + 'foom abc xy', + ' abc foom', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('insert at cell FOO (2 of 2), pos=1', 7, 3, VK_M, [], + ['abc foo', + 'mfoo abc xy', + ' abc mfoo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('insert at cell FOO (2 of 2), pos=end', 10, 3, VK_M, [], + ['abc foo', + 'foom abc xy', + ' abc foom', + '', + 'foo', + '']); + + InitTestText(1,1, 1,4); + TestKeyAt('insert at cell FOO (2 of 3), pos=1', 1, 2, VK_M, [], + ['abc mfoo', + 'mfoo abc xy', + ' abc mfoo', + '', + 'foo', + '']); + + InitTestText(1,1, 1,4); + TestKeyAt('insert at cell FOO (2 of 3), pos=end', 4, 2, VK_M, [], + ['abc foom', + 'foom abc xy', + ' abc foom', + '', + 'foo', + '']); + TestKeyAt('insert(continue) at cell FOO (2 of 3), pos=new-end', 5, 2, VK_X, [], + ['abc foomx', + 'foomx abc xy', + ' abc foomx', + '', + 'foo', + '']); + TestKeyAt('insert(continue) at cell FOO (2 of 3), pos=1', 1, 2, VK_N, [], + ['abc nfoomx', + 'nfoomx abc xy', + ' abc nfoomx', + '', + 'foo', + '']); + TestKeyAt('insert(continue) at cell ABC(was FOO) (2 of 3), pos=1', 8, 2, VK_D, [], + ['dabc nfoomx', + 'nfoomx dabc xy', + ' dabc nfoomx', + '', + 'foo', + '']); + TestKeyAt('insert(continue) at cell ABC(was FOO) (2 of 3), pos=end', 12, 2, VK_E, [], + ['dabce nfoomx', + 'nfoomx dabce xy', + ' dabce nfoomx', + '', + 'foo', + '']); + TestKeyAt('insert(continue) at cell ABC(was FOO) (1 of 3), pos=mid', 3, 1, VK_F, [], + ['dafbce nfoomx', + 'nfoomx dafbce xy', + ' dafbce nfoomx', + '', + 'foo', + '']); + {%endregion} + {%region 'Delete/KeyPress inside cell' } + name := 'Delete/KeyPress inside cell'; + InitTestText(1,2, 1,4); + TestKeyAt('Delete at Cell FOO (1 of 2), pos=1', 1, 2, VK_DELETE, [], + ['abc foo', + 'oo abc xy', + ' abc oo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('Backspace at Cell FOO (1 of 2), pos=1', 2, 2, VK_BACK, [], + ['abc foo', + 'oo abc xy', + ' abc oo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('Delete at cell FOO (1 of 2), pos=end', 3, 2, VK_DELETE, [], + ['abc foo', + 'fo abc xy', + ' abc fo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('Backspace at cell FOO (1 of 2), pos=end', 4, 2, VK_BACK, [], + ['abc foo', + 'fo abc xy', + ' abc fo', + '', + 'foo', + '']); + + + InitTestText(1,1, 1,4); + TestKeyAt('Delete at Cell FOO (3 of 3), pos=1', 7, 3, VK_DELETE, [], + ['abc oo', + 'oo abc xy', + ' abc oo', + '', + 'foo', + '']); + + InitTestText(1,1, 1,4); + TestKeyAt('Backspace at cell FOO (3 of 3), pos=end', 10, 3, VK_BACK, [], + ['abc fo', + 'fo abc xy', + ' abc fo', + '', + 'foo', + '']); + TestKeyAt('Delete(continue) at cell FOO (1 of 3), pos=end', 5, 1, VK_DELETE, [], + ['abc o', + 'o abc xy', + ' abc o', + '', + 'foo', + '']); + TestKeyAt('Delete(continue) at cell ABC(was FOO) (2 of 3), pos=1', 3, 2, VK_DELETE, [], + ['bc o', + 'o bc xy', + ' bc o', + '', + 'foo', + '']); + TestKeyAt('Backspace(continue) at cell ABC(was FOO) (2 of 3), pos=end', 5, 2, VK_BACK, [], + ['b o', + 'o b xy', + ' b o', + '', + 'foo', + '']); + {%endregion} + {%endregion} + + {%region Edit cell, delete all, type again } + name := 'DeleteAll-Retype/KeyPress inside cell'; + InitTestText(1,2, 1,4); + TestKeyAt('Delete at Cell FOO (1 of 2), pos=1', 1, 2, VK_DELETE, [], + ['abc foo', + 'oo abc xy', + ' abc oo', + '', + 'foo', + '']); + TestKeyAt('Delete at Cell OO (1 of 2), pos=1', 1, 2, VK_DELETE, [], + ['abc foo', + 'o abc xy', + ' abc o', + '', + 'foo', + '']); + TestKeyAt('Delete at Cell O (1 of 2), pos=1', 1, 2, VK_DELETE, [], + ['abc foo', + ' abc xy', + ' abc ', + '', + 'foo', + '']); + TestKeyAt('Retype(del) at Cell FOO (1 of 2), pos=1', 1, 2, VK_X, [], + ['abc foo', + 'x abc xy', + ' abc x', + '', + 'foo', + '']); +if not DoUndo then begin // todo: fails with undo +(* loosing trailing space on undo + This is due to "FTrimmedLinesView.ForceTrim;" in SynEdit.Undo + Which in turn is there, because the trimming in undo, must be done while the UndoList is still locked.... +*) + TestKeyAt('Delete at Cell X (1 of 2), pos=1', 1, 2, VK_DELETE, [], + ['abc foo', + ' abc xy', + ' abc ', + '', + 'foo', + '']); + TestKeyAt('Retype / Insert new line', 1, 2, VK_RETURN, [], + ['abc foo', + '',' abc xy', + ' abc ','', + '', + 'foo', + '']); +end; + + InitTestText(1,2, 1,4); + TestCmdAt('DeleteLastWord at Cell FOO (1 of 2), pos=end', 4, 2, ecDeleteLastWord, + ['abc foo', + ' abc xy', + ' abc ', + '', + 'foo', + '']); + TestKeyAt('Retype(bck-sp) at Cell FOO (1 of 2)', 1, 2, VK_X, [], + ['abc foo', + 'x abc xy', + ' abc x', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestCmdAt('DeleteLastWord at Cell FOO (1 of 2), pos=end', 4, 2, ecDeleteLastWord, + ['abc foo', + ' abc xy', + ' abc ', + '', + 'foo', + '']); + TestKeyAt('Retype(bck-sp) at other Cell FOO (2 of 2)', 7, 3, VK_X, [], + ['abc foo', + 'x abc xy', + ' abc x', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Cut at Cell FOO (1 of 2), pos=1', 4,2, 1,2, VK_X, [ssCtrl], + ['abc foo', + ' abc xy', + ' abc ', + '', + 'foo', + '']); + TestKeyAt('paste at Cell FOO (1 of 2), pos=1', 1, 2, VK_V, [ssCtrl], + ['abc foo', + 'foo abc xy', + ' abc foo', + '', + 'foo', + '']); + {%endregion} + + {%region Edit selection at start/end/complete of cell (delete/replace) } + name := 'Delete/Selection'; + InitTestText(1,2, 1,4); + TestKeyAtSel('at start of cell', 3,2, 1,2, VK_DELETE, [], + ['abc foo', + 'o abc xy', + ' abc o', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAtSel('at end of cell', 2,2, 4,2, VK_DELETE, [], + ['abc foo', + 'f abc xy', + ' abc f', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAtSel('full cell', 4,2, 1,2, VK_DELETE, [], + ['abc foo', + ' abc xy', + ' abc ', + '', + 'foo', + '']); + TestKeyAt('full cell(continue, reinsert)', 1,2, VK_A, [], + ['abc foo', + 'a abc xy', + ' abc a', + '', + 'foo', + '']); + + name := 'Replace/Selection'; + InitTestText(1,2, 1,4); + TestKeyAtSel('at start of cell', 3,2, 1,2, VK_L, [], + ['abc foo', + 'lo abc xy', + ' abc lo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAtSel('at end of cell', 2,2, 4,2, VK_L, [], + ['abc foo', + 'fl abc xy', + ' abc fl', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAtSel('full cell', 4,2, 1,2, VK_L, [], + ['abc foo', + 'l abc xy', + ' abc l', + '', + 'foo', + '']); + {%endregion} + + {%region Edit Edit Cells, with 2 synced cells on same line } + name := 'Two cells on one line'; + InitTestText(1,2, 1,4, 1); + TestKeyAt('insert in 1st cell', 3, 3, VK_X, [], + ['abc foo', + 'xfoo abc xy', + ' xfoo xfoo abc', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAt('insert in 2nd cell', 7, 3, VK_Y, [], + ['abc foo', + 'yfoo abc xy', + ' yfoo yfoo abc', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAt('insert in 2nd cell (2)', 10, 3, VK_Y, [], + ['abc foo', + 'fooy abc xy', + ' fooy fooy abc', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAt('delete in 1st cell', 6, 3, VK_BACK, [], + ['abc foo', + 'fo abc xy', + ' fo fo abc', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAt('delete in 2nd cell', 7, 3, VK_DELETE, [], + ['abc foo', + 'oo abc xy', + ' oo oo abc', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAtSel('Sel-Replace in 1st cell', 4,3, 6,3, VK_M, [], + ['abc foo', + 'fm abc xy', + ' fm fm abc', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAtSel('Sel-Replace in 2nd cell', 7,3, 9,3, VK_N, [], + ['abc foo', + 'no abc xy', + ' no no abc', + '', + 'foo', + '']); + {%endregion} + + {%region Insert, delete linebreak in cell (with/without auto-indent) } + Name := 'LineBreaks'; + InitTestText(1,2, 1,4); + TestKeyAt('Return middle of FOO, no indent', 2, 2, VK_RETURN, [], + ['abc foo', + 'f','oo abc xy', + ' abc f','oo', + '', + 'foo', + '']); + TestKeyAt('Return middle of FOO, no indent - continue 1', 2, 2, VK_A, [], + ['abc foo', + 'fa','oo abc xy', + ' abc fa','oo', + '', + 'foo', + '']); + TestKeyAt('Return middle of FOO, no indent - continue 2', 1, 3, VK_B, [], + ['abc foo', + 'fa','boo abc xy', + ' abc fa','boo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('Return begin of FOO, no indent', 1, 2, VK_RETURN, [], + ['abc foo', + '','foo abc xy', + ' abc ','foo', + '', + 'foo', + '']); + TestKeyAt('Return begin of FOO, no indent - cotinue 1', 1, 3, VK_C, [], + ['abc foo', + '','cfoo abc xy', + ' abc ','cfoo', + '', + 'foo', + '']); +if not DoUndo then begin +// TODO: fails due to trim space + TestKeyAt('Return begin of FOO, no indent - cotinue 2', 1, 2, VK_D, [], + ['abc foo', + 'd','cfoo abc xy', + ' abc d','cfoo', + '', + 'foo', + '']); +end; + + InitTestText(1,2, 1,4); + TestKeyAt('Return end of FOO, no indent', 4, 2, VK_RETURN, [], + ['abc foo', + 'foo',' abc xy', + ' abc foo','', + '', + 'foo', + '']); + TestKeyAt('Return end of FOO, no indent - continue 1', 1, 5, VK_E, [], + ['abc foo', + 'foo','e abc xy', + ' abc foo','e', + '', + 'foo', + '']); + TestKeyAt('Return end of FOO, no indent - continue 2', 7, 4, VK_A, [], + ['abc foo', + 'afoo','e abc xy', + ' abc afoo','e', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('Return middle of ABC, with indent', 4, 3, VK_RETURN, [], + ['abc foo', + 'foo a',' bc xy', + ' a',' bc foo', + '', + 'foo', + '']); + TestKeyAt('Return middle of ABC, with indent - continue 1', 5, 3, VK_A, [], + ['abc foo', + 'foo a',' bca xy', + ' a',' bca foo', + '', + 'foo', + '']); + TestKeyAt('Return middle of ABC, with indent - continue 2', 6, 2, VK_B, [], + ['abc foo', + 'foo ab',' bca xy', + ' ab',' bca foo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('Return begin of ABC, with indent', 3, 3, VK_RETURN, [], + ['abc foo', + 'foo ',' abc xy', + ' ',' abc foo', + '', + 'foo', + '']); + TestKeyAt('Return begin of ABC, with indent - continue 1', 5, 2, VK_C, [], + ['abc foo', + 'foo c',' abc xy', + ' c',' abc foo', + '', + 'foo', + '']); + TestKeyAt('Return begin of ABC, with indent - continue 2', 6, 3, VK_D, [], + ['abc foo', + 'foo c',' abcd xy', + ' c',' abcd foo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + TestKeyAt('Return end of ABC, with indent', 6, 3, VK_RETURN, [], + ['abc foo', + 'foo abc',' xy', + ' abc',' foo', + '', + 'foo', + '']); + TestKeyAt('Return end of ABC, with indent - continue 1', 6, 4, VK_E, [], + ['abc foo', + 'foo abce',' xy', + ' abce',' foo', + '', + 'foo', + '']); + TestKeyAt('Return end of ABC, with indent - continue 2', 3, 5, VK_F, [], + ['abc foo', + 'foo abce',' f xy', + ' abce',' f foo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAt('2 cells in one line: insert in 1st cell', 4, 3, VK_RETURN, [], + ['abc foo', + 'f',' oo abc xy', + ' f',' oo f',' oo abc', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4, 1); + TestKeyAt('2 cells in one line: insert in 2nd cell', 8, 3, VK_RETURN, [], + ['abc foo', + 'f',' oo abc xy', + ' f',' oo f',' oo abc', + '', + 'foo', + '']); + {%endregion} + + {%region Edit just before/after cell, while caret in cell (backspace at start / del at end) } + name := 'Delete/KeyPress caret in cell, text out of cell'; + InitTestText(1,2, 1,4); + TestKeyAt('Delete after Cell ABC', 8, 2, VK_DELETE, [], + ['abc foo', + 'foo abcxy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAt('Delete before Cell ABC', 5, 2, VK_BACK, [], + ['abc foo', + 'fooabc xy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('prepare empty cell', 5,2, 8,2, VK_BACK, [], + ['abc foo', + 'foo xy', + ' foo', + '', + 'foo', + ''], TRUE); + TestKeyAt('Backspace, start of empty cell', 5,2, VK_BACK, [], + ['abc foo', + 'foo xy', + ' foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('prepare empty cell', 5,2, 8,2, VK_BACK, [], + ['abc foo', + 'foo xy', + ' foo', + '', + 'foo', + ''], TRUE); + TestKeyAt('Delete, end of empty cell', 5,2, VK_DELETE, [], + ['abc foo', + 'foo xy', + ' foo', + '', + 'foo', + ''], FALSE); + {%endregion} + + {%region Edit just before/after cell, while caret in cell (selection outside cell / replace, delete) } + name := 'Delete/Selection: caret in cell, text out of cell'; +if not DoUndo then begin + InitTestText(1,2, 1,4); + TestKeyAtSel('Delete-Sel, after cell', 9,2, 8,2, VK_DELETE, [], + ['abc foo', + 'foo abcxy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Replace-Sel, after cell', 9,2, 8,2, VK_M, [], + ['abc foo', + 'foo abcmxy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Delete-Sel, part-in,part-after cell', 9,2, 7,2, VK_DELETE, [], + ['abc foo', + 'foo abxy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Delete-Sel, part-in,part-after cell (caret out of cell)', 7,2, 9,2, VK_DELETE, [], + ['abc foo', + 'foo abxy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Delete-Sel, before cell', 4,2, 5,2, VK_DELETE, [], + ['abc foo', + 'fooabc xy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Replace-Sel, before cell', 4,2, 5,2, VK_M, [], + ['abc foo', + 'foomabc xy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Delete-Sel, part-in,part-before cell', 4,2, 6,2, VK_DELETE, [], + ['abc foo', + 'foobc xy', + ' abc foo', + '', + 'foo', + ''], FALSE); + + InitTestText(1,2, 1,4); + TestKeyAtSel('Delete-Sel, part-in,part-before cell (caret out of cell)', 6,2, 4,2, VK_DELETE, [], + ['abc foo', + 'foobc xy', + ' abc foo', + '', + 'foo', + ''], FALSE); +end; + {%endregion} + + + //Edit just before/after cell, while caret in cell (selection outside cell / replace, delete) + // - same with emptied cell + // - part in/ part out of cell + + {%region External Edit outside cell } + name := 'External Edit outside cell'; + InitTestText(1,2, 1,4); + SetCaret(4,3); // into cell def + FSyncroModule.IncExternalEditLock; + SynEdit.TextBetweenPoints[Point(1,3), Point(2,3)] := 'a'; + FSyncroModule.DecExternalEditLock; + TestKeyAt('with cell active', 3, 3, VK_B, [], + ['abc foo', + 'foo babc xy', + 'a babc foo', + '', + 'foo', + '']); + + InitTestText(1,2, 1,4); + SetCaret(1,3); // out of cell abc + FSyncroModule.IncExternalEditLock; + SynEdit.TextBetweenPoints[Point(1,3), Point(2,3)] := 'a'; + FSyncroModule.DecExternalEditLock; + TestKeyAt('with cell not active', 3, 3, VK_B, [], + ['abc foo', + 'foo babc xy', + 'a babc foo', + '', + 'foo', + '']); + +(* + InitTestText(1,2, 1,4); + SetCaret(1,3); // out of cell abc + FSyncroModule.IncExternalEditLock; + SynEdit.TextBetweenPoints[Point(3,3), Point(3,3)] := 'a'; + FSyncroModule.DecExternalEditLock; + TestKeyAt('with cell not active, extern in cell', 3, 3, VK_C, [], + ['abc foo', + 'foo caabc xy', + ' caabc foo', + '', + 'foo', + '']); +*) + + {%endregion} + + + //External Edit inside current/other cell (or while caret outside any cell) + + //Application.ProcessMessages; + //Application.ProcessMessages; sleep(2500); + + end; + +begin + DoUndo := False; + PushBaseName('simple'); + TestSyncro; + DoUndo := True; + PopPushBaseName('undo/redo'); + TestSyncro; +end; + initialization RegisterTest(TTestSyncroEdit);