/* * move the cursor left one character */ void CHtmlInputBuf::move_left(int extend, int word) { size_t idx; /* if not already showing the caret, make it visible again */ show_caret(); /* if we're already at the start of the command, there's nothing to do */ if (caret_ == 0) return; /* start by moving back one character */ idx = prevchar(caret_); /* if moving by a word, skip to the start of the current/prior word */ if (word) { /* move left until we're not in spaces */ while (idx > 0 && is_space(buf_[idx])) idx = prevchar(idx); /* move left until the character to the left is a space */ while (idx > 0 && !is_space(buf_[prevchar(idx)])) idx = prevchar(idx); } /* adjust selection */ adjust_sel(idx, extend); }
void Buffer::delchar() { if (m_cur.x != 0) { m_lines[m_cur.y].erase(m_cur.x - 1, 1); prevchar(); } else if (m_cur.y != 0) { string old_line = m_lines[m_cur.y]; m_lines.erase(m_lines.begin() + m_cur.y); prevchar(); // Append what was left of the erased line to the now current line m_lines[m_cur.y] += old_line; } }
void Buffer::update(int ch) { switch (ch) { case KEY_UP: prevline(); break; case KEY_DOWN: nextline(); break; case KEY_RIGHT: nextchar(); break; case KEY_LEFT: prevchar(); break; case KEY_HOME: begofline(); break; case KEY_END: endofline(); break; case 127: delchar(); break; case '\n': case '\r': newline(); break; default: addchar(ch); } }
/* * backspace */ int CHtmlInputBuf::backspace() { /* if not already showing the caret, make it visible again */ show_caret(); /* see if there's a selection range */ if (sel_start_ != sel_end_) { /* there's a range - delete it */ return del_selection(); } else if (caret_ > 0) { /* save undo */ save_undo(); /* * no range - delete character to left of cursor. Move the * characters to the right of the cursor over the character to * the left of the cursor, if necessary. */ size_t prv = prevchar(caret_); if (len_ > caret_) memmove(buf_ + prv, buf_ + caret_, len_ - caret_); /* it's now one character shorter */ len_ -= (caret_ - prv); /* back up the caret one position */ sel_start_ = sel_end_ = caret_ = prv; /* we made a change */ return TRUE; } else { /* we didn't change anything */ return FALSE; } }