ui/cocoa/text.m

changeset 686
1e2f3a44d455
parent 685
36e08a9aff8e
child 718
06eec75a6fd5
--- a/ui/cocoa/text.m	Fri Aug 01 22:17:27 2025 +0200
+++ b/ui/cocoa/text.m	Sun Aug 03 10:53:58 2025 +0200
@@ -85,7 +85,6 @@
     NSTextStorage *textStorage;
     if(text->data1) {
         textStorage = (__bridge NSTextStorage*)text->data1;
-        
     } else {
         textStorage = [[NSTextStorage alloc] init];
     }
@@ -135,7 +134,9 @@
 }
 
 int ui_textarea_position(UiText *text) {
-    return 0;
+    NSTextView *textview = (__bridge NSTextView*)text->obj;
+    NSRange range = textview.selectedRange;
+    return (int)range.location;
 }
 
 void ui_textarea_setselection(UiText *text, int begin, int end) {
@@ -145,15 +146,30 @@
 }
 
 void ui_textarea_selection(UiText *text, int *begin, int *end) {
-    
+    NSTextView *textview = (__bridge NSTextView*)text->obj;
+    NSRange range = textview.selectedRange;
+    if(begin) {
+        *begin = (int)range.location;
+    }
+    if(end) {
+        *end = (int)(range.location+range.length);
+    }
 }
 
 int ui_textarea_length(UiText *text) {
-    return 0;
+    NSTextView *textview = (__bridge NSTextView*)text->obj;
+    return (int)textview.string.length;
 }
 
 void ui_textarea_remove(UiText *text, int begin, int end) {
+    NSTextView *textview = (__bridge NSTextView*)text->obj;
     
+    if (begin < 0 || end < begin || end > textview.string.length) {
+        return;
+    }
+    
+    NSRange range = NSMakeRange(begin, end - begin);
+    [[textview textStorage] deleteCharactersInRange:range];
 }
 
 

mercurial