Lines 47-52
Link Here
|
47 |
import java.beans.PropertyChangeListener; |
47 |
import java.beans.PropertyChangeListener; |
48 |
import java.io.IOException; |
48 |
import java.io.IOException; |
49 |
import java.util.ArrayList; |
49 |
import java.util.ArrayList; |
|
|
50 |
import java.util.logging.Level; |
51 |
import java.util.logging.Logger; |
50 |
import javax.swing.event.UndoableEditEvent; |
52 |
import javax.swing.event.UndoableEditEvent; |
51 |
import javax.swing.event.UndoableEditListener; |
53 |
import javax.swing.event.UndoableEditListener; |
52 |
import javax.swing.text.*; |
54 |
import javax.swing.text.*; |
Lines 90-107
Link Here
|
90 |
return new NbLikeEditorKit(); |
92 |
return new NbLikeEditorKit(); |
91 |
} |
93 |
} |
92 |
|
94 |
|
|
|
95 |
// could install a logger "Handler" and test the warning only when |
96 |
// expected. Maybe later. |
97 |
Level disableWarning() |
98 |
{ |
99 |
Logger l = Logger.getLogger("org.openide.text.CloneableEditorSupport"); |
100 |
Level level = l.getLevel(); |
101 |
l.setLevel(Level.SEVERE); |
102 |
return level; |
103 |
} |
104 |
void enableWarning(Level level) |
105 |
{ |
106 |
Logger l = Logger.getLogger("org.openide.text.CloneableEditorSupport"); |
107 |
l.setLevel(level); |
108 |
} |
109 |
|
93 |
// Use these methods with the UndoRedoGroup patch |
110 |
// Use these methods with the UndoRedoGroup patch |
94 |
CompoundEdit beginChunk(Document d) { |
111 |
CompoundEdit beginChunk(Document d) { |
95 |
// ur().beginUndoGroup(); |
|
|
96 |
sendUndoableEdit(d, CloneableEditorSupport.BEGIN_COMMIT_GROUP); |
112 |
sendUndoableEdit(d, CloneableEditorSupport.BEGIN_COMMIT_GROUP); |
97 |
return null; |
113 |
return null; |
98 |
} |
114 |
} |
99 |
|
115 |
|
|
|
116 |
void endChunk(Document d) { |
117 |
endChunk(d, null); |
118 |
} |
119 |
|
100 |
void endChunk(Document d, CompoundEdit ce) { |
120 |
void endChunk(Document d, CompoundEdit ce) { |
101 |
// ur().endUndoGroup(); |
|
|
102 |
sendUndoableEdit(d, CloneableEditorSupport.END_COMMIT_GROUP); |
121 |
sendUndoableEdit(d, CloneableEditorSupport.END_COMMIT_GROUP); |
103 |
} |
122 |
} |
104 |
|
123 |
|
|
|
124 |
void markChunk(Document d) { |
125 |
sendUndoableEdit(d, CloneableEditorSupport.MARK_COMMIT_GROUP); |
126 |
} |
127 |
|
105 |
void sendUndoableEdit(Document d, UndoableEdit ue) { |
128 |
void sendUndoableEdit(Document d, UndoableEdit ue) { |
106 |
if(d instanceof AbstractDocument) { |
129 |
if(d instanceof AbstractDocument) { |
107 |
UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners(); |
130 |
UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners(); |
Lines 203-235
Link Here
|
203 |
endChunk(d, ce); |
226 |
endChunk(d, ce); |
204 |
assertEquals("chunk: data", "ab", d.getText(0, d.getLength())); |
227 |
assertEquals("chunk: data", "ab", d.getText(0, d.getLength())); |
205 |
|
228 |
|
206 |
endChunk(d, ce); |
229 |
Level level = disableWarning(); |
207 |
endChunk(d, ce); |
230 |
try { |
|
|
231 |
endChunk(d, ce); |
232 |
endChunk(d, ce); |
208 |
|
233 |
|
209 |
assertEquals("extraEnd: data", "ab", d.getText(0, d.getLength())); |
234 |
assertEquals("extraEnd: data", "ab", d.getText(0, d.getLength())); |
210 |
assertTrue("extraEnd: modified", support.isModified()); |
235 |
assertTrue("extraEnd: modified", support.isModified()); |
211 |
assertTrue("extraEnd: can undo", ur().canUndo()); |
236 |
assertTrue("extraEnd: can undo", ur().canUndo()); |
212 |
assertFalse("extraEnd: no redo", ur().canRedo()); |
237 |
assertFalse("extraEnd: no redo", ur().canRedo()); |
213 |
|
238 |
|
214 |
d.insertString(d.getLength(), "c", null); |
239 |
d.insertString(d.getLength(), "c", null); |
215 |
d.insertString(d.getLength(), "d", null); |
240 |
d.insertString(d.getLength(), "d", null); |
216 |
endChunk(d, ce); |
241 |
endChunk(d, ce); |
217 |
assertEquals("extraEnd2: data", "abcd", d.getText(0, d.getLength())); |
242 |
assertEquals("extraEnd2: data", "abcd", d.getText(0, d.getLength())); |
218 |
ur().undo(); |
243 |
ur().undo(); |
219 |
endChunk(d, ce); |
244 |
endChunk(d, ce); |
220 |
assertEquals("undo1: data", "abc", d.getText(0, d.getLength())); |
245 |
assertEquals("undo1: data", "abc", d.getText(0, d.getLength())); |
221 |
ur().undo(); |
246 |
ur().undo(); |
222 |
assertEquals("undo2: data", "ab", d.getText(0, d.getLength())); |
247 |
assertEquals("undo2: data", "ab", d.getText(0, d.getLength())); |
223 |
ur().undo(); |
248 |
ur().undo(); |
224 |
endChunk(d, ce); |
249 |
endChunk(d, ce); |
225 |
assertEquals("undo3: data", "", d.getText(0, d.getLength())); |
250 |
assertEquals("undo3: data", "", d.getText(0, d.getLength())); |
226 |
ur().redo(); |
251 |
ur().redo(); |
227 |
assertEquals("redo1: data", "ab", d.getText(0, d.getLength())); |
252 |
assertEquals("redo1: data", "ab", d.getText(0, d.getLength())); |
228 |
ur().redo(); |
253 |
ur().redo(); |
229 |
endChunk(d, ce); |
254 |
endChunk(d, ce); |
230 |
assertEquals("redo2: data", "abc", d.getText(0, d.getLength())); |
255 |
assertEquals("redo2: data", "abc", d.getText(0, d.getLength())); |
231 |
ur().redo(); |
256 |
ur().redo(); |
232 |
assertEquals("redo3: data", "abcd", d.getText(0, d.getLength())); |
257 |
assertEquals("redo3: data", "abcd", d.getText(0, d.getLength())); |
|
|
258 |
} finally { |
259 |
enableWarning(level); |
260 |
} |
233 |
} |
261 |
} |
234 |
|
262 |
|
235 |
public void testUndoRedoWhileActiveChunk() throws Exception { |
263 |
public void testUndoRedoWhileActiveChunk() throws Exception { |
Lines 369-374
Link Here
|
369 |
ur().undo(); |
397 |
ur().undo(); |
370 |
assertEquals("undo3", "", d.getText(0, d.getLength())); |
398 |
assertEquals("undo3", "", d.getText(0, d.getLength())); |
371 |
} |
399 |
} |
|
|
400 |
|
401 |
public void testNestedEmpyChunks() throws Exception { |
402 |
content = ""; |
403 |
StyledDocument d = support.openDocument(); |
404 |
beginChunk(d); |
405 |
d.insertString(d.getLength(), "a", null); |
406 |
d.insertString(d.getLength(), "b", null); |
407 |
|
408 |
// should have no effect |
409 |
beginChunk(d); |
410 |
endChunk(d); |
411 |
|
412 |
d.insertString(d.getLength(), "e", null); |
413 |
d.insertString(d.getLength(), "f", null); |
414 |
|
415 |
endChunk(d); |
416 |
|
417 |
assertEquals("data", "abef", d.getText(0, d.getLength())); |
418 |
|
419 |
ur().undo(); |
420 |
assertEquals("undo3", "", d.getText(0, d.getLength())); |
421 |
} |
422 |
|
423 |
public void testNestedEmpyChunks2() throws Exception { |
424 |
content = ""; |
425 |
StyledDocument d = support.openDocument(); |
426 |
beginChunk(d); |
427 |
d.insertString(d.getLength(), "a", null); |
428 |
d.insertString(d.getLength(), "b", null); |
429 |
|
430 |
// should have no effect |
431 |
beginChunk(d); |
432 |
beginChunk(d); |
433 |
endChunk(d); |
434 |
endChunk(d); |
435 |
beginChunk(d); |
436 |
endChunk(d); |
437 |
|
438 |
d.insertString(d.getLength(), "e", null); |
439 |
d.insertString(d.getLength(), "f", null); |
440 |
|
441 |
endChunk(d); |
442 |
|
443 |
assertEquals("data", "abef", d.getText(0, d.getLength())); |
444 |
|
445 |
ur().undo(); |
446 |
assertEquals("undo3", "", d.getText(0, d.getLength())); |
447 |
} |
448 |
|
449 |
public void testNestedEmpyChunks3() throws Exception { |
450 |
content = ""; |
451 |
StyledDocument d = support.openDocument(); |
452 |
beginChunk(d); |
453 |
d.insertString(d.getLength(), "a", null); |
454 |
d.insertString(d.getLength(), "b", null); |
455 |
|
456 |
beginChunk(d); |
457 |
d.insertString(d.getLength(), "c", null); |
458 |
|
459 |
// should have no effect |
460 |
beginChunk(d); |
461 |
endChunk(d); |
462 |
|
463 |
d.insertString(d.getLength(), "d", null); |
464 |
endChunk(d); |
465 |
|
466 |
// should have no effect |
467 |
beginChunk(d); |
468 |
endChunk(d); |
469 |
|
470 |
d.insertString(d.getLength(), "e", null); |
471 |
|
472 |
// should have no effect |
473 |
beginChunk(d); |
474 |
endChunk(d); |
475 |
|
476 |
d.insertString(d.getLength(), "f", null); |
477 |
|
478 |
// should have no effect |
479 |
beginChunk(d); |
480 |
endChunk(d); |
481 |
|
482 |
d.insertString(d.getLength(), "g", null); |
483 |
|
484 |
endChunk(d); |
485 |
|
486 |
assertEquals("data", "abcdefg", d.getText(0, d.getLength())); |
487 |
|
488 |
// following fails if nesting not supported |
489 |
ur().undo(); |
490 |
assertEquals("undo1", "abcd", d.getText(0, d.getLength())); |
491 |
|
492 |
ur().undo(); |
493 |
assertEquals("undo2", "ab", d.getText(0, d.getLength())); |
494 |
|
495 |
ur().undo(); |
496 |
assertEquals("undo3", "", d.getText(0, d.getLength())); |
497 |
} |
498 |
|
499 |
public void testMarkCommitGroup() throws Exception { |
500 |
content = ""; |
501 |
StyledDocument d = support.openDocument(); |
502 |
beginChunk(d); |
503 |
d.insertString(d.getLength(), "a", null); |
504 |
d.insertString(d.getLength(), "b", null); |
505 |
|
506 |
markChunk(d); // creates a separate undoable chunk |
507 |
|
508 |
d.insertString(d.getLength(), "c", null); |
509 |
d.insertString(d.getLength(), "d", null); |
510 |
|
511 |
markChunk(d); |
512 |
|
513 |
d.insertString(d.getLength(), "e", null); |
514 |
d.insertString(d.getLength(), "f", null); |
515 |
|
516 |
endChunk(d); |
517 |
|
518 |
assertEquals("data", "abcdef", d.getText(0, d.getLength())); |
519 |
|
520 |
// following fails if nesting not supported |
521 |
ur().undo(); |
522 |
assertEquals("undo1", "abcd", d.getText(0, d.getLength())); |
523 |
|
524 |
ur().undo(); |
525 |
assertEquals("undo2", "ab", d.getText(0, d.getLength())); |
526 |
|
527 |
ur().undo(); |
528 |
assertEquals("undo3", "", d.getText(0, d.getLength())); |
529 |
} |
372 |
|
530 |
|
373 |
// |
531 |
// |
374 |
// Implementation of the CloneableEditorSupport.Env |
532 |
// Implementation of the CloneableEditorSupport.Env |