aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté <mikisabate@gmail.com>2014-01-19 14:48:33 (GMT)
committerMiquel Sabaté <mikisabate@gmail.com>2014-01-19 14:48:33 (GMT)
commit7c431c5706a9fcd544775e203a6351d6b0d2204c (patch)
treecdb2dcef03f838c181c69108f40ebcfd40c4a45b
parent001dac5b457fca84ea9872fd9e5ebc8262942630 (diff)
vimode: added the "(" and ")" motions.
REVIEW: 115106
-rw-r--r--part/vimode/katevinormalmode.cpp63
-rw-r--r--part/vimode/katevinormalmode.h3
-rw-r--r--tests/vimode_test.cpp26
3 files changed, 92 insertions, 0 deletions
diff --git a/part/vimode/katevinormalmode.cpp b/part/vimode/katevinormalmode.cpp
index 975e75f..74b7488 100644
--- a/part/vimode/katevinormalmode.cpp
+++ b/part/vimode/katevinormalmode.cpp
@@ -2887,6 +2887,67 @@ KateViRange KateViNormalMode::motionToPrevVisualLine() {
return goVisualLineUpDown( -getCount() );
}
+KateViRange KateViNormalMode::motionToPreviousSentence()
+{
+ Cursor c = findSentenceStart();
+ int linenum = c.line(), column;
+ const bool skipSpaces = doc()->line(linenum).isEmpty();
+
+ if (skipSpaces) {
+ linenum--;
+ if (linenum >= 0) {
+ column = doc()->line(linenum).size() - 1;
+ }
+ } else {
+ column = c.column();
+ }
+
+ for (int i = linenum; i >= 0; i--) {
+ const QString &line = doc()->line(i);
+
+ if (line.isEmpty() && !skipSpaces) {
+ return KateViRange(i, 0, ViMotion::InclusiveMotion);
+ }
+
+ for (int j = column; j >= 0; j--) {
+ if (skipSpaces || QString::fromLatin1(".?!").indexOf(line.at(j)) != -1) {
+ c.setLine(i);
+ c.setColumn(j);
+ updateCursor(c);
+ c = findSentenceStart();
+ return KateViRange(c.line(), c.column(), ViMotion::InclusiveMotion);
+ }
+ }
+ column = line.size() - 1;
+ }
+ return KateViRange(0, 0, ViMotion::InclusiveMotion);
+}
+
+KateViRange KateViNormalMode::motionToNextSentence()
+{
+ Cursor c = findSentenceEnd();
+ int linenum = c.line(), column = c.column() + 1;
+ const bool skipSpaces = doc()->line(linenum).isEmpty();
+
+ for (int i = linenum; i < doc()->lines(); i++) {
+ const QString &line = doc()->line(i);
+
+ if (line.isEmpty() && !skipSpaces) {
+ return KateViRange(i, 0, ViMotion::InclusiveMotion);
+ }
+
+ for (int j = column; j < line.size(); j++) {
+ if (!line.at(j).isSpace()) {
+ return KateViRange(i, j, ViMotion::InclusiveMotion);
+ }
+ }
+ column = 0;
+ }
+
+ c = doc()->documentEnd();
+ return KateViRange(c.line(), c.column(), ViMotion::InclusiveMotion);
+}
+
KateViRange KateViNormalMode::motionToBeforeParagraph()
{
Cursor c( m_view->cursorPosition() );
@@ -3599,6 +3660,8 @@ void KateViNormalMode::initializeCommands()
ADDMOTION("L", motionToLastLineOfWindow, 0 );
ADDMOTION("gj", motionToNextVisualLine, 0 );
ADDMOTION("gk", motionToPrevVisualLine, 0 );
+ ADDMOTION("(", motionToPreviousSentence, 0 );
+ ADDMOTION(")", motionToNextSentence, 0 );
ADDMOTION("{", motionToBeforeParagraph, 0 );
ADDMOTION("}", motionToAfterParagraph, 0 );
diff --git a/part/vimode/katevinormalmode.h b/part/vimode/katevinormalmode.h
index 774f566..0cd58f0 100644
--- a/part/vimode/katevinormalmode.h
+++ b/part/vimode/katevinormalmode.h
@@ -238,6 +238,9 @@ class KATEPART_TESTS_EXPORT KateViNormalMode : public KateViModeBase
KateViRange motionToNextVisualLine();
KateViRange motionToPrevVisualLine();
+ KateViRange motionToPreviousSentence();
+ KateViRange motionToNextSentence();
+
KateViRange motionToBeforeParagraph();
KateViRange motionToAfterParagraph();
diff --git a/tests/vimode_test.cpp b/tests/vimode_test.cpp
index 98226a4..4cd952e 100644
--- a/tests/vimode_test.cpp
+++ b/tests/vimode_test.cpp
@@ -1512,6 +1512,32 @@ void ViModeTest::NormalModeMotionsTest() {
DoTest("bar\n{\nfoo\n}", "ld]]", "b\n{\nfoo\n}");
DoTest("{\nfoo\n}\nbar", "jjjld[]", "{\nfoo\nar");
+ // Testing the "(" motion
+ DoTest("", "(", "");
+ DoTest("\nhello.", "fh(iX", "X\nhello.");
+ DoTest("hello. world.", "fr(iX", "Xhello. world.");
+ DoTest("hello. world.\n", "j(iX", "hello. Xworld.\n");
+ DoTest("hello. world\nyay. lol.\n", "jfl(iX", "hello. Xworld\nyay. lol.\n");
+ DoTest("Hello.\n\n", "jj(iX", "XHello.\n\n");
+ DoTest("\nHello.", "j(iX", "X\nHello.");
+ DoTest("\n\n\nHello.", "jj(iX", "X\n\n\nHello.");
+ DoTest("Hello! Bye!", "fB(iX", "XHello! Bye!");
+ DoTest("Hello! Bye! Hye!", "fH(iX", "Hello! XBye! Hye!");
+
+ // Testing the ")" motion
+ DoTest("", ")", "");
+ DoTest("\nhello.", ")iX", "\nXhello.");
+ DoTest("hello. world.", ")iX", "hello. Xworld.");
+ DoTest("hello. world\n\nasd.", "))iX", "hello. world\nX\nasd.");
+ DoTest("hello. wor\nld.?? Asd", "))iX", "hello. wor\nld.?? XAsd");
+ DoTest("hello. wor\nld.?? Asd", "jfA(iX", "hello. Xwor\nld.?? Asd");
+ DoTest("Hello.\n\n\nWorld.", ")iX", "Hello.\nX\n\nWorld.");
+ DoTest("Hello.\n\n\nWorld.", "))iX", "Hello.\n\n\nXWorld.");
+ DoTest("Hello.\n\n", ")iX", "Hello.\nX\n");
+ DoTest("Hello.\n\n", "))iX", "Hello.\n\nX");
+ DoTest("Hello. ", ")aX", "Hello. X");
+ DoTest("Hello?? Bye!", ")iX", "Hello?? XBye!");
+
// Testing "{" and "}" motions
DoTest("","{}","");
DoTest("foo","{}dd","");