diff mde/content/AStringContent.d @ 119:d28aea50c6da

Basic edit cursor placement using the mouse. Moved textContent.d's contents into TextWidget.d.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 01 Jan 2009 14:52:09 +0000
parents 1b1e2297e2fc
children d3b2cefd46c9
line wrap: on
line diff
--- a/mde/content/AStringContent.d	Sun Dec 28 10:55:15 2008 +0000
+++ b/mde/content/AStringContent.d	Thu Jan 01 14:52:09 2009 +0000
@@ -115,7 +115,9 @@
 	return sv;
     }
     
-    /// Get the character the edit cursor is in front of
+    /** Get the character the edit cursor is in front of.
+     *
+     * NOTE: unused. */
     size_t editIndex () {
 	size_t i = 0;
 	for (size_t p = 0; p < pos; ++p)
@@ -123,6 +125,17 @@
 		++i;
 	return i;
     }
+    /** Set the edit position in front of i'th character.
+     *
+     * Assumes at least i characters are present; if not this will work but not be optimal. */
+    void editIndex (size_t i) {
+        pos = 0;
+        for (; i > 0; --i) {	// NOTE: could be slightly optimised
+            if (pos < sv.length) ++pos;
+            while (pos < sv.length && (sv[pos] & 0x80) && !(sv[pos] & 0x40))
+                ++pos;
+        }
+    }
     
     /** Call after editing a string; return new string (may be changed/reverted). */
     char[] endEdit ();