void Cursor::replaceAtCursor(const QByteArray &data) { //if (m_selection_valid ) { // if (current_cursor_new_y() >= m_selection_start.new_y() && current_cursor_new_y() <= m_selection_end.new_y()) // //don't need to schedule as event since it will only happen once // setSelectionEnabled(false); //} const QString text = m_gl_text_codec->toUnicode(data); if (new_x() + text.size() <= m_screen->width()) { Block *block = screen_data()->blockContainingLine(new_y()); block->replaceAtPos(new_x(), text, m_current_text_style); new_rx() += text.size(); } else if (m_wrap_around) { Block *block = screen_data()->blockContainingLine(new_y()); block->replaceAtPos(new_x(), text, m_current_text_style); int line_feeds = (new_x() + text.size()) / m_screen->width(); new_rx() = (new_x() + text.size()) % m_screen->width(); for (int i = 0; i < line_feeds; i++) { lineFeed(); } }else { const int size = m_document_width - new_x(); QString toBlock = text.mid(0,size); toBlock.replace(toBlock.size() - 1, 1, text.at(text.size()-1)); Block *block = screen_data()->blockContainingLine(new_y()); block->replaceAtPos(new_x(),toBlock, m_current_text_style); new_rx() += toBlock.size(); } if (new_x() >= m_document_width) new_rx() = m_document_width - 1; notifyChanged(); }
void Cursor::setScreenWidth(int newWidth, int removedBeginning, int reclaimed) { if (newWidth > m_screen_width) { for (int i = m_screen_width -1; i < newWidth; i++) { if (i % 8 == 0) { m_tab_stops.append(i); } } } m_screen_width = newWidth; auto it = m_screen->currentScreenData()->it_for_block(m_resize_block); if (m_screen->currentScreenData()->it_is_end(it)) { if (removedBeginning > reclaimed) { new_ry() = 0; new_rx() = 0; } else { new_ry() = m_screen_height - 1; new_rx() = 0; } } else { new_ry() = (*it)->screenIndex() + m_current_pos_in_block / newWidth; new_rx() = m_current_pos_in_block % newWidth; } m_resize_block = 0; m_current_pos_in_block = 0; notifyChanged(); }
void Cursor::insertAtCursor(const QByteArray &data, bool only_latin) { const QString text = m_gl_text_codec->toUnicode(data); auto diff = screen_data()->insert(m_new_position, text, m_current_text_style, only_latin); new_rx() += diff.character; new_ry() += diff.line; if (new_y() >= m_screen_height) new_ry() = m_screen_height - 1; if (new_x() >= m_screen_width) new_rx() = m_screen_width - 1; }
void Cursor::moveLeft(int positions) { if (!new_x() || !positions) return; if (positions < new_x()) { new_rx() -= positions; } else { new_rx() = 0; } notifyChanged(); }
void Cursor::moveRight(int positions) { int width = m_screen->width(); if (new_x() == width -1 || !positions) return; if (positions < width - new_x()) { new_rx() += positions; } else { new_rx() = width -1; } notifyChanged(); }
void Cursor::replaceAtCursor(const QByteArray &data, bool only_latin) { const QString text = m_gl_text_codec->toUnicode(data); if (!m_wrap_around && new_x() + text.size() > m_screen->width()) { const int size = m_screen_width - new_x(); QString toBlock = text.mid(0,size); toBlock.replace(toBlock.size() - 1, 1, text.at(text.size()-1)); screen_data()->replace(m_new_position, toBlock, m_current_text_style, only_latin); new_rx() += toBlock.size(); } else { auto diff = screen_data()->replace(m_new_position, text, m_current_text_style, only_latin); new_rx() += diff.character; new_ry() += diff.line; } if (new_y() >= m_screen_height) { new_ry() = m_screen_height - 1; } notifyChanged(); }
void Cursor::moveToCharacter(int character) { const int width = m_screen->width(); if (character < 0) { character = 1; } else if (character > width) { character = width; } if (character != new_x()) { new_rx() = character; notifyChanged(); } }
void Cursor::insertAtCursor(const QByteArray &data) { //if (m_selection_valid) { // if (current_cursor_new_y() >= m_selection_start.new_y() && current_cursor_new_y() <= m_selection_end.new_y()) // //don't need to schedule as event since it will only happen once // setSelectionEnabled(false); //} const QString text = m_gl_text_codec->toUnicode(data); Block *line = screen_data()->blockContainingLine(new_y()); line->insertAtPos(new_x(), text, m_screen->defaultTextStyle()); new_rx() += text.size(); }
void Cursor::moveToLine(int line) { const int height = m_screen->height(); if (line < adjusted_top()) { line = 0; } else if (line > adjusted_bottom()) { line = height -1; } if (line != new_y()) { new_rx() = line; notifyChanged(); } }
void Cursor::setDocumentWidth(int width) { if (width > m_document_width) { for (int i = m_document_width -1; i < width; i++) { if (i % 8 == 0) { m_tab_stops.append(i); } } } m_document_width = width; if (new_x() >= width) { new_rx() = width - 1; notifyChanged(); } }
void Cursor::moveBeginningOfLine() { new_rx() = 0; notifyChanged(); }