|
|
1.1 root 1: #import "textundo.h"
2:
3: @implementation TextSelChange
4:
5: /*
6: * The TextSelChange is the workhorse of undoable text. It records the
7: * contents of the selection (via TextSelection objects) before and after
8: * a change is made. By alternately installing and removing the old and new
9: * selections, the original change can be undone and redone.
10: */
11:
12: - initView:aView name:(const char *)str
13: {
14: [super initView:aView];
15:
16: oldSel = nil;
17: newSel = nil;
18:
19: name = str;
20:
21: return self;
22: }
23:
24: - free
25: {
26: if (newSel) {
27: [newSel free];
28: }
29:
30: if (oldSel) {
31: [oldSel free];
32: }
33:
34: return [super free];
35: }
36:
37: - (const char *)changeName
38: {
39: return name;
40: }
41:
42: - saveAfterChange
43: {
44: newSel = [[[TextSelection alloc] initText:textView] capture];
45: return self;
46: }
47:
48: - saveBeforeChange
49: {
50: NXSelPt start, end;
51:
52: [textView getSel:&start :&end];
53: selStart = start.cp;
54: selEnd = end.cp;
55:
56: oldSel = [TextSelection alloc];
57: [[oldSel initText:textView start:selStart end:selEnd] capture];
58: [oldSel setClickCount:[newSel clickCount]];
59:
60: return self;
61: }
62:
63: - undoChange
64: {
65: [[textView window] disableFlushWindow];
66: [newSel remove];
67: [oldSel install];
68: [[[textView window] reenableFlushWindow] flushWindow];
69:
70: return [super undoChange];
71: }
72:
73: - redoChange
74: {
75: NXRect oldBounds, invalidRect;
76: id delegate;
77:
78: [[textView window] disableFlushWindow];
79:
80: if (delegate = [textView delegate]) {
81: [textView getBounds:&oldBounds];
82: invalidRect = oldBounds;
83: invalidRect.size.width = 0.0;
84: invalidRect.size.height = 0.0;
85: } else {
86: delegate = nil;
87: }
88:
89: [oldSel remove];
90: [newSel install];
91:
92: if (delegate != nil &&
93: [delegate respondsTo:@selector(textDidResize:oldBounds:invalid:)])
94: {
95: [delegate textDidResize:textView
96: oldBounds:&oldBounds
97: invalid:&invalidRect];
98: }
99:
100: [[[textView window] reenableFlushWindow] flushWindow];
101:
102: return [super redoChange];
103: }
104:
105: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.