QTextCursor BaseTextBlockSelection::selection(const TabSettings &ts) const { QTextCursor cursor = firstBlock; if (anchor <= TopRight) { cursor.setPosition(lastBlock.block().position() + ts.positionAtColumn(lastBlock.block().text(), lastVisualColumn)); cursor.setPosition(firstBlock.block().position() + ts.positionAtColumn(firstBlock.block().text(), firstVisualColumn), QTextCursor::KeepAnchor); } else { cursor.setPosition(firstBlock.block().position() + ts.positionAtColumn(firstBlock.block().text(), firstVisualColumn)); cursor.setPosition(lastBlock.block().position() + ts.positionAtColumn(lastBlock.block().text(), lastVisualColumn), QTextCursor::KeepAnchor); } return cursor; }
int BaseTextBlockSelection::position(const TabSettings &ts) const { const QTextBlock &block = anchor <= TopRight ? lastBlock.block() : firstBlock.block(); const int column = anchor % 2 ? firstVisualColumn : lastVisualColumn; return block.position() + ts.positionAtColumn(block.text(), column); }