diff --git a/sources/appl/Buffer/Buffer.cpp b/sources/appl/Buffer/Buffer.cpp index 1ff82c9..fa24d26 100644 --- a/sources/appl/Buffer/Buffer.cpp +++ b/sources/appl/Buffer/Buffer.cpp @@ -51,6 +51,8 @@ void appl::Buffer::moveCursorRight(appl::Buffer::moveMode _mode) { break; case moveEnd: // TODO : ... + nbElement = endLine(m_cursorPos); + moveCursor(nbElement); break; } @@ -71,7 +73,8 @@ void appl::Buffer::moveCursorLeft(appl::Buffer::moveMode _mode) { // TODO : ... break; case moveEnd: - // TODO : ... + nbElement = startLine(m_cursorPos); + moveCursor(nbElement+1); break; } } @@ -145,7 +148,7 @@ bool appl::Buffer::search(esize_t _pos, const etk::UniChar& _search, esize_t& _r esize_t nbElementBuffer = 0; etk::UniChar value; for(esize_t iii=_pos ; iii pos=" << m_cursorPos); - etk::UniChar value; - esize_t nbElement = get(m_cursorPos, value); - if (nbElement>0) { - m_data.remove(m_cursorPos, nbElement); + if (hasTextSelected()) { + esize_t startPos = etk_min(m_cursorPos, m_cursorSelectPos); + esize_t endPos = etk_max(m_cursorPos, m_cursorSelectPos); + m_data.remove(startPos, endPos-startPos); + m_selectMode = false; + moveCursor(startPos); + } else { + etk::UniChar value; + esize_t nbElement = get(m_cursorPos, value); + if (nbElement>0) { + m_data.remove(m_cursorPos, nbElement); + } } - } else if (_event.getChar() == etk::UniChar::Delete) { + return true; + } else if (localValue == etk::UniChar::Delete) { //APPL_INFO("keyEvent : pos=" << m_cursorPos); - etk::UniChar value; - esize_t nbElement = getBack(m_cursorPos-1, value); - if (nbElement>0) { - m_cursorPos -= nbElement; - m_data.remove(m_cursorPos, nbElement); + if (hasTextSelected()) { + esize_t startPos = etk_min(m_cursorPos, m_cursorSelectPos); + esize_t endPos = etk_max(m_cursorPos, m_cursorSelectPos); + m_data.remove(startPos, endPos-startPos); + m_selectMode = false; + moveCursor(startPos); + } else { + etk::UniChar value; + esize_t nbElement = getBack(m_cursorPos-1, value); + if (nbElement>0) { + m_data.remove(m_cursorPos-nbElement, nbElement); + m_selectMode = false; + moveCursor(m_cursorPos-nbElement); + } } + return true; + } + m_selectMode = false; + // normal adding char ... + char output[5]; + int32_t nbElement = localValue.getUtf8(output); + if (hasTextSelected()) { + esize_t startPos = etk_min(m_cursorPos, m_cursorSelectPos); + esize_t endPos = etk_max(m_cursorPos, m_cursorSelectPos); + m_data.replace(startPos, endPos-startPos, (int8_t*)output, nbElement); + moveCursor(startPos+nbElement); } else { - // normal adding char ... - char output[5]; - int32_t nbElement = _event.getChar().getUtf8(output); if (_event.getSpecialKey().isSetInsert() == false) { m_data.insert(m_cursorPos, (int8_t*)output, nbElement); } else { @@ -215,7 +286,7 @@ bool appl::Buffer::onEventEntry(const ewol::EventEntry& _event, ewol::Text& _tes esize_t nbElementRemove = get(m_cursorPos, value); m_data.replace(m_cursorPos, nbElementRemove, (int8_t*)output, nbElement); } - m_cursorPos += nbElement; + moveCursor(m_cursorPos+nbElement); } return true; } diff --git a/sources/appl/Buffer/Buffer.h b/sources/appl/Buffer/Buffer.h index 2c3e21a..8aaa03b 100644 --- a/sources/appl/Buffer/Buffer.h +++ b/sources/appl/Buffer/Buffer.h @@ -57,6 +57,9 @@ namespace appl { void moveCursor(esize_t _pos); void mouseEventDouble(void); void mouseEventTriple(void); + bool hasTextSelected(void) { + return m_cursorSelectPos >= 0; + } bool selectAround(int32_t _startPos, int32_t &_beginPos, int32_t &_endPos); /** * @brief Get the position in the buffer of a display distance from the start of the line