Skip to content

Commit

Permalink
chore: fix the note about multiple cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
gikari authored and sassanh committed Apr 19, 2023
1 parent cd8c871 commit e249c22
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/qnvimplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ void QNVimPlugin::syncSelectionToVim(Core::IEditor *editor) {
// because it is the cursor user controls with hjkl
auto nvimPos = mainCursor.position();

// NOTE: Theoretically, it is not alwaus the case,
// NOTE: Theoretically, it is not always the case
// that the main cursor is at the ends of mtc array,
// but for creating our own block selections it works
// but for creating our own block selections it works,
// because we create cursors one after another, where
// main cursor is at the end or in the beginning.
// @see syncCursorFromVim
auto lastCursor = mainCursor == *mtc.begin() ? *(mtc.end() - 1) : *mtc.begin();
auto nvimAnchor = lastCursor.anchor();

Expand Down Expand Up @@ -306,7 +309,16 @@ void QNVimPlugin::syncCursorFromVim(const QVariantList &pos, const QVariantList
};

auto mtc = Utils::MultiTextCursor();
for (auto curBlock = firstBlock; curBlock != after(lastBlock); curBlock = after(curBlock)) {
for (auto curBlock = firstBlock; //
curBlock.isValid() && curBlock != after(lastBlock); //
curBlock = after(curBlock)) {

auto columnsCountInCurBlock = tabs.columnCountForText(curBlock.text());

// Skip cursor, if it goes out of the block
if (columnsCountInCurBlock < localAnchor && columnsCountInCurBlock < localPos)
continue;

auto newCursor = QTextCursor(curBlock);

auto anchorBoundOffset = tabs.positionAtColumn(curBlock.text(), localAnchor);
Expand Down

0 comments on commit e249c22

Please sign in to comment.