ui/cocoa/text.m

changeset 26
a137277f9173
parent 23
decc6bf584aa
child 29
c96169444d88
--- a/ui/cocoa/text.m	Sat Apr 05 13:02:37 2014 +0200
+++ b/ui/cocoa/text.m	Sat Apr 05 15:53:41 2014 +0200
@@ -91,6 +91,8 @@
         value->set = ui_textarea_set;
         value->getsubstr = ui_textarea_getsubstr;
         value->insert = ui_textarea_insert;
+        value->position = ui_textarea_position;
+        value->selection = ui_textarea_selection;
         value->value = NULL;
         value->obj = textview;
         
@@ -154,9 +156,6 @@
     if(text->value) {
         free(text->value);
     }
-    if(text->value) {
-        free(text->value);
-    }
     NSTextView *textview = (NSTextView*)text->obj;
     NSString *s = [[NSString alloc]initWithUTF8String:str];
     NSAttributedString *as = [[NSAttributedString alloc]initWithString:s];
@@ -164,6 +163,16 @@
     text->value = NULL;
 }
 
+int ui_textarea_position(UiText *text) {
+    return [[[(NSTextView*)text->obj selectedRanges] objectAtIndex:0] rangeValue].location;
+}
+
+void ui_textarea_selection(UiText *text, int *begin, int *end) {
+    NSRange range = [[[(NSTextView*)text->obj selectedRanges] objectAtIndex:0] rangeValue];
+    *begin = range.location;
+    *end = range.location + range.length;
+}
+
 void ui_text_undo(UiText *text) {
     [(NSUndoManager*)text->undomgr undo];
 }

mercurial