Skip to content

Commit

Permalink
r
Browse files Browse the repository at this point in the history
  • Loading branch information
mls-m5 committed Nov 1, 2023
1 parent 21464d1 commit 814f82c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/script/vimcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ std::optional<std::function<CursorRange(Cursor, VimMode, int)>> getSelection(
throw "error";
}

// auto front = static_cast<uint32_t>(buffer.front().c);

auto f = getMotion(buffer);

if (f) {
Expand Down Expand Up @@ -253,6 +251,32 @@ std::shared_ptr<IMode> vim::createMode(VimMode resultMode) {
ActionResultT findVimAction(FStringView buffer, VimMode modeName) {
auto bestResult = vim::MatchType::NoMatch;

if (buffer.empty()) {
return {vim::NoMatch};
}

if (buffer.front() == 'r') {
if (buffer.size() == 1) {
return {vim::MatchType::PartialMatch};
}
auto replacement = buffer.at(1);

auto f = [replacement](std::shared_ptr<IEnvironment> env) {
auto &editor = env->editor();
auto cursor = editor.cursor();
auto repetitions = editor.mode().repetitions();
auto end = cursor;
for (size_t i = 0; i < repetitions; ++i) {
end = right(end);
}
replace({cursor, end},
FString{static_cast<size_t>(repetitions), replacement});
editor.cursor(left(end));
};

return {vim::Match, f};
}

{
auto motion = getMotion(buffer);
if (motion.match == vim::Match) {
Expand Down

0 comments on commit 814f82c

Please sign in to comment.