Skip to content

Commit

Permalink
0, $ and ^
Browse files Browse the repository at this point in the history
  • Loading branch information
mls-m5 committed Nov 1, 2023
1 parent 9970824 commit 13b92f3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/modes/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ bool Mode::keyPress(std::shared_ptr<IEnvironment> env) {

if (key.key == Key::Text) {
auto intRep = static_cast<uint32_t>(key.symbol);
if (_shouldEnableNumbers && (intRep >= '0' && intRep <= '9')) {

/// "0" is a valid command also
if (_repetitions == 0 && intRep == '0') {
/// Do nothing
}
else if (_shouldEnableNumbers && (intRep >= '0' && intRep <= '9')) {
auto number = intRep - '0';
if (_repetitions) {
_repetitions = _repetitions * 10 + number;
Expand Down
18 changes: 17 additions & 1 deletion src/script/vimcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "text/fstring.h"
#include "text/fstringview.h"
#include "text/utf8char.h"
#include "text/utf8charops.h"
#include "views/editor.h"
#include <array>
#include <optional>
Expand Down Expand Up @@ -40,14 +41,26 @@ std::function<Cursor(Cursor)> combine(Args... args) {
Cursor lastNonSpaceOnLine(Cursor cursor) {
for (auto cur = cursor; cur != end(cursor); ++cur) {
auto c = content(cur);
if (!(c == '\t' || c == ' ' || c == '\n' || c == '\r')) {
if (!isSpace(c)) {
cursor = cur;
}
}

return cursor;
}

Cursor firstNonSpaceOnLine(Cursor cursor) {
for (auto cur = home(cursor); cur != end(cursor); ++cur) {
auto c = content(cur);
cursor = cur;
if (!isSpace(c)) {
return cursor;
}
}

return cursor;
}

/// std::less is used to be able to compare with FString
const static auto map =
std::map<FString, std::function<Cursor(Cursor)>, std::less<>>{
Expand All @@ -59,6 +72,9 @@ const static auto map =
{"w", combine(wordEnd, wrap(right, true), wordEnd, wordBegin)},
{"e", combine(wrap(right, true), wordEnd)},
{"b", wordBegin},
{"0", home},
{"$", end},
{"^", firstNonSpaceOnLine},
{"g_", lastNonSpaceOnLine},
{"gg", [](Cursor c) { return c.buffer().begin(); }},
{"G", [](Cursor c) { return c.buffer().end(); }},
Expand Down
1 change: 1 addition & 0 deletions src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
#include "text/rawbuffer.cpp"
#include "text/utf8caseconversion.cpp"
#include "text/utf8char.cpp"
#include "text/utf8charops.cpp"
5 changes: 5 additions & 0 deletions src/text/utf8charops.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "utf8charops.h"

bool isSpace(Utf8Char c) {
return (c == '\t' || c == ' ' || c == '\n' || c == '\r');
}
5 changes: 5 additions & 0 deletions src/text/utf8charops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "text/utf8char.h"

bool isSpace(Utf8Char);

0 comments on commit 13b92f3

Please sign in to comment.