comparison 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
comparison
equal deleted inserted replaced
118:9ac208b53582 119:d28aea50c6da
113 debug logger.trace ("Unhandled symbol: {}", sym); 113 debug logger.trace ("Unhandled symbol: {}", sym);
114 } 114 }
115 return sv; 115 return sv;
116 } 116 }
117 117
118 /// Get the character the edit cursor is in front of 118 /** Get the character the edit cursor is in front of.
119 *
120 * NOTE: unused. */
119 size_t editIndex () { 121 size_t editIndex () {
120 size_t i = 0; 122 size_t i = 0;
121 for (size_t p = 0; p < pos; ++p) 123 for (size_t p = 0; p < pos; ++p)
122 if (!(sv[p] & 0x80) || sv[p] & 0x40) 124 if (!(sv[p] & 0x80) || sv[p] & 0x40)
123 ++i; 125 ++i;
124 return i; 126 return i;
127 }
128 /** Set the edit position in front of i'th character.
129 *
130 * Assumes at least i characters are present; if not this will work but not be optimal. */
131 void editIndex (size_t i) {
132 pos = 0;
133 for (; i > 0; --i) { // NOTE: could be slightly optimised
134 if (pos < sv.length) ++pos;
135 while (pos < sv.length && (sv[pos] & 0x80) && !(sv[pos] & 0x40))
136 ++pos;
137 }
125 } 138 }
126 139
127 /** Call after editing a string; return new string (may be changed/reverted). */ 140 /** Call after editing a string; return new string (may be changed/reverted). */
128 char[] endEdit (); 141 char[] endEdit ();
129 142