@@ -207,20 +207,22 @@ Used textField::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len
207207 out.fmtStart (*this ,menuOut::fmtTextField,root.node (),idx);
208208 #endif
209209 idx_t tit=hasTitle (root.node ())?1 :0 ;
210+ idx_t c=l+1 ;// initial cursor, after label
210211 idx_t line=idx+tit;// -out.tops[root.level];
211- idx_t c=l+1 ;
212- idx_t w=len-l;
213- idx_t at=cursor>=w?cursor-w:0 ;
214- trace (MENU_DEBUG_OUT<<" at:" <<at<<" tit:" <<tit<<" line:" <<line<<" cursor:" <<cursor<<" l:" <<l<<" len:" <<len);// <<endl;)
215- while (buffer ()[at]&&l++<len)
216- if (at==cursor&&editing) {
217- // MENU_DEBUG_OUT<<"idx:"<<idx<<" line:"<<line<<" at:"<<at<<" l:"<<l<<endl;
218- // c=l+1;
212+ idx_t ew=len-c;// editable width
213+ idx_t at=cursor>=ew?cursor-ew:0 ;// adjust print start
214+ while (buffer ()[at]&&l++<len) {// while not string terminated or buffer length reached
215+ trace (if (editing) MENU_DEBUG_OUT<<endl<<" {" <<at<<" }" );
216+ if (at==cursor&&editing) {// edit cursor
217+ trace (MENU_DEBUG_OUT<<" ew:" <<ew<<" cursor:" <<cursor<<" l:" <<l<<" len:" <<len<<endl);
218+ c=l;// store cursor position
219219 l+=out.startCursor (root,l,line,charEdit);// draw text cursor or color code start
220220 out.write (buffer ()[at++]);// draw focused character
221221 l+=out.endCursor (root,l,line,charEdit);// draw text cursor or color code end
222- } else out.write (buffer ()[at++]);
223- out.editCursor (root,c+cursor,line,editing,charEdit);// reposition a gfx cursor
222+ } else out.write (buffer ()[at++]);// just the character
223+ }
224+ // this is the cursor frame
225+ out.editCursor (root,c,line,editing,charEdit);// reposition a gfx cursor
224226 #ifdef MENU_FMT_WRAPS
225227 out.fmtEnd (*this ,menuOut::fmtTextField,root.node (),idx);
226228 #endif
0 commit comments