ui/cocoa/text.m

changeset 23
decc6bf584aa
parent 13
2dbc56c2323b
child 26
a137277f9173
equal deleted inserted replaced
22:bcf880b29bc3 23:decc6bf584aa
33 #import "text.h" 33 #import "text.h"
34 #import "container.h" 34 #import "container.h"
35 35
36 @implementation TextChangeMgr 36 @implementation TextChangeMgr
37 37
38 - (TextChangeMgr*)initWithValue:(UiText*)text { 38 - (TextChangeMgr*)initWithValue:(UiText*)text context:(UiContext*)ctx {
39 value = text; 39 value = text;
40 context = ctx;
41 last_length = 0;
40 return self; 42 return self;
41 } 43 }
42 44
43 - (NSUndoManager*)undoManagerForTextView:(NSTextView*)textview { 45 - (NSUndoManager*)undoManagerForTextView:(NSTextView*)textview {
44 return (NSUndoManager*)value->undomgr; 46 return (NSUndoManager*)value->undomgr;
47 }
48
49 - (NSRange)textView:(NSTextView *)textview
50 willChangeSelectionFromCharacterRange:(NSRange)oldrange
51 toCharacterRange:(NSRange)newrange
52 {
53 if(newrange.length != last_length) {
54 if(newrange.length == 0) {
55 ui_unset_group(context, UI_GROUP_SELECTION);
56 } else {
57 ui_set_group(context, UI_GROUP_SELECTION);
58 }
59 }
60
61 last_length = newrange.length;
62 return newrange;
45 } 63 }
46 64
47 @end 65 @end
48 66
49 67
74 value->getsubstr = ui_textarea_getsubstr; 92 value->getsubstr = ui_textarea_getsubstr;
75 value->insert = ui_textarea_insert; 93 value->insert = ui_textarea_insert;
76 value->value = NULL; 94 value->value = NULL;
77 value->obj = textview; 95 value->obj = textview;
78 96
79 TextChangeMgr *delegate = [[TextChangeMgr alloc]initWithValue:value]; 97 TextChangeMgr *delegate = [[TextChangeMgr alloc]initWithValue:value context:obj->ctx];
80 [textview setDelegate:delegate]; 98 [textview setDelegate:delegate];
81 99
82 NSUndoManager *undomgr = [[NSUndoManager alloc]init]; 100 NSUndoManager *undomgr = [[NSUndoManager alloc]init];
83 value->undomgr = undomgr; 101 value->undomgr = undomgr;
84 } 102 }

mercurial