@@ -148,6 +148,45 @@ public function getCursorPosition()
148148 return $ this ->linepos ;
149149 }
150150
151+ /**
152+ * move cursor to right by $n chars (or left if $n is negative)
153+ *
154+ * zero or out of range moves are simply ignored
155+ *
156+ * @param int $n
157+ * @return self
158+ * @uses self::moveCursorTo()
159+ */
160+ public function moveCursorBy ($ n )
161+ {
162+ return $ this ->moveCursorTo ($ this ->linepos + $ n );
163+ }
164+
165+ /**
166+ * move cursor to given position in current line buffer
167+ *
168+ * out of range (exceeding current input buffer) are simply ignored
169+ *
170+ * @param int $n
171+ * @return self
172+ * @uses self::redraw()
173+ */
174+ public function moveCursorTo ($ n )
175+ {
176+ if ($ n < 0 || $ n === $ this ->linepos || $ n > $ this ->strlen ($ this ->linebuffer )) {
177+ return $ this ;
178+ }
179+
180+ $ this ->linepos = $ n ;
181+
182+ // only redraw if cursor is actually visible
183+ if ($ this ->echo ) {
184+ $ this ->redraw ();
185+ }
186+
187+ return $ this ;
188+ }
189+
151190 /**
152191 * set current text input buffer
153192 *
@@ -403,45 +442,6 @@ public function deleteChar($n)
403442 $ this ->redraw ();
404443 }
405444
406- /**
407- * move cursor to right by $n chars (or left if $n is negative)
408- *
409- * zero or out of range moves are simply ignored
410- *
411- * @param int $n
412- * @return self
413- * @uses self::moveCursorTo()
414- */
415- public function moveCursorBy ($ n )
416- {
417- return $ this ->moveCursorTo ($ this ->linepos + $ n );
418- }
419-
420- /**
421- * move cursor to given position in current line buffer
422- *
423- * out of range (exceeding current input buffer) are simply ignored
424- *
425- * @param int $n
426- * @return self
427- * @uses self::redraw()
428- */
429- public function moveCursorTo ($ n )
430- {
431- if ($ n < 0 || $ n === $ this ->linepos || $ n > $ this ->strlen ($ this ->linebuffer )) {
432- return $ this ;
433- }
434-
435- $ this ->linepos = $ n ;
436-
437- // only redraw if cursor is actually visible
438- if ($ this ->echo ) {
439- $ this ->redraw ();
440- }
441-
442- return $ this ;
443- }
444-
445445 /**
446446 * process the current line buffer, emit event and redraw empty line
447447 */
0 commit comments