Permalink
Browse files

Reimplemented paragraph text object

  • Loading branch information...
modosist committed Mar 17, 2013
1 parent b24910a commit f093f9906c7c34bb71c6c0983c689b9e54e3ae66
@@ -585,6 +585,169 @@ public void test_dt() {
"A",'l',"a ma\nkota.");
}
+ @Test
+ public void test_dap() {
+ // "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac"
+ checkCommand(forKeySeq("dap"),
+ "",'1',"ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "",'3',"ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dap"),
+ "1ac\n",'\n',"3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n",'\n'," \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n",'3',"ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n",'7',"ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n3ac\n",'4',"ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n",'7',"ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n3ac\n4ac\n\n \n",'7',"ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n3ac\n4ac\n\n \n",'1',"1ac\n12ac");
+
+ // Special cases for file end sections ("do nothing")
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac\n",'\n',"\n",
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac\n",'\n',"\n");
+
+ checkCommand(forKeySeq("dap"),
+ "\n\n\n",'f',"oo\nbar\n\n\n\n",
+ "\n\n\n",EOF,"");
+ checkCommand(forKeySeq("dap"),
+ "\n",'\n',"",
+ "\n",'\n',"");
+ checkCommand(forKeySeq("dap"),
+ "hello\n",'w',"orld",
+ "",EOF,"");
+ checkCommand(forKeySeq("dap"),
+ "hello\n",'w',"orld\n",
+ "",EOF,"");
+ checkCommand(forKeySeq("dap"),
+ "",'\n',"\nhello\nworld\n",
+ "",EOF,"");
+ checkCommand(forKeySeq("dap"),
+ "\n\n",'h',"ello\nworld",
+ "",EOF,"");
+ checkCommand(forKeySeq("dap"),
+ "",'h',"ello",
+ "",EOF,"");
+ checkCommand(forKeySeq("dap"),
+ "",EOF,"",
+ "",EOF,"");
+
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n",' '," \n\n11ac\n12ac",
+ "1ac\n\n3ac\n4ac\n\n \n",'7',"ac");
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n",'\n',"11ac\n12ac",
+ "1ac\n\n3ac\n4ac\n\n \n",'7',"ac");
+
+ // Special cases for file end sections
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n",'1',"1ac\n12ac",
+ "1ac\n\n3ac\n4ac\n\n \n",'7',"ac");
+ checkCommand(forKeySeq("dap"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n",'1',"2ac",
+ "1ac\n\n3ac\n4ac\n\n \n",'7',"ac");
+ }
+
+ @Test
+ public void test_2dap() {
+ checkCommand(forKeySeq("2dap"),
+ "",'1',"ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "",'7',"ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("2dap"),
+ "1ac\n",'\n',"3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n",'\n'," \n\n11ac\n12ac");
+ checkCommand(forKeySeq("2dap"),
+ "1ac\n\n",'3',"ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n",'1',"1ac\n12ac");
+
+ checkCommand(forKeySeq("2dap"),
+ "1ac\n\n3ac\n4ac\n",'\n'," \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n3ac\n",'4',"ac");
+ checkCommand(forKeySeq("2dap"),
+ "1ac\n\n3ac\n4ac\n\n \n",'7',"ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n3ac\n",'4',"ac");
+ }
+
+ @Test
+ public void test_dip() {
+ checkCommand(forKeySeq("dip"),
+ "",'1',"ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "",'\n',"3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dip"),
+ "1ac\n",'\n',"3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n",'3',"ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dip"),
+ "1ac\n\n",'3',"ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n",'\n'," \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dip"),
+ "1ac\n\n3ac\n",'4',"ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n",'\n'," \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("dip"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n",' '," \n\n11ac\n12ac",
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n",'1',"1ac\n12ac");
+
+ // Special cases for file end sections
+ checkCommand(forKeySeq("dip"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n",'1',"1ac\n12ac",
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n",EOF,"");
+ checkCommand(forKeySeq("dip"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n",'1',"2ac",
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n",EOF,"");
+
+ checkCommand(forKeySeq("dip"),
+ "\n\n\n",'f',"oo\nbar\n\n\n\n",
+ "\n\n\n",'\n',"\n\n");
+ checkCommand(forKeySeq("dip"),
+ "\n",'\n',"",
+ "",EOF,"");
+ checkCommand(forKeySeq("dip"),
+ "hello\n",'w',"orld",
+ "",EOF,"");
+ checkCommand(forKeySeq("dip"),
+ "hello\n",'w',"orld\n",
+ "",EOF,"");
+ checkCommand(forKeySeq("dip"),
+ "\n\n",'h',"ello\nworld",
+ "\n",EOF,"");
+ checkCommand(forKeySeq("dip"),
+ "",'h',"ello",
+ "",EOF,"");
+ checkCommand(forKeySeq("dip"),
+ "",EOF,"",
+ "",EOF,"");
+
+ // Cases for buffers with EOL at the end
+ checkCommand(forKeySeq("dip"),
+ "\n\n",'h',"ello\nworld\n",
+ "\n\n",EOF,"");
+ checkCommand(forKeySeq("dip"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac\n",'\n',"\n",
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac\n",EOF,"");
+ }
+
+ @Test
+ public void test_2dip() {
+ checkCommand(forKeySeq("2dip"),
+ "",'1',"ac\n\n3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "",'3',"ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("2dip"),
+ "1ac\n",'\n',"3ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n",'\n'," \n7ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("2dip"),
+ "1ac\n\n",'3',"ac\n4ac\n\n \n7ac\n\n \n\n11ac\n12ac",
+ "1ac\n\n",'7',"ac\n\n \n\n11ac\n12ac");
+ checkCommand(forKeySeq("2dip"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n",'\n'," \n\n11ac\n12ac",
+ "1ac\n\n3ac\n4ac\n\n \n",'7',"ac");
+
+ // Cases for buffers with EOL at the end
+ checkCommand(forKeySeq("2dip"),
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n",'\n'," \n\n11ac\n12ac\n",
+ "1ac\n\n3ac\n4ac\n\n \n7ac\n",EOF,"");
+ }
+
@Test
public void test_gq_mergeLines() {
//Some of these tests move the cursor when they shouldn't;
@@ -693,7 +856,7 @@ public void test_gq_splitLines() {
"/* this",' ',"line will be split multiple times */",
"", '/', "* this\n* line\n* will\n* be\n* split\n* multiple\n* times\n* */\n");
}
-
+
@Test
public void testSurroundPlugin_ds() {
when(platform.getPlatformSpecificStateProvider()).thenReturn(SurroundStateProvider.INSTANCE);
@@ -93,6 +93,23 @@ public static boolean isPatternDelimiter(String s) {
public static boolean isBlank(String s) {
return s == null || s.trim().equals("");
}
+
+ /**
+ * @return true, if line contains only whitespace characters
+ */
+ public static boolean isLineBlank(TextContent content, int lineNo) {
+ LineInformation line = content.getLineInformation(lineNo);
+ return VimUtils.isBlank(content.getText(line.getBeginOffset(), line.getLength()));
+ }
+
+ /**
+ * @return true, if the last character in the text buffer is newline
+ */
+ public static boolean endsWithEOL(EditorAdaptor editor) {
+ TextContent content = editor.getModelContent();
+ LineInformation line = content.getLineInformation(content.getNumberOfLines() - 1);
+ return line.getNumber() > 0 && line.getLength() == 0;
+ }
/**
* Calculates an offset position. Line breaks are not counted.
@@ -22,7 +22,21 @@ public void execute(EditorAdaptor editorAdaptor, int count) throws CommandExecut
switch (textObject.getContentType(editorAdaptor.getConfiguration())) {
case TEXT_RECTANGLE: throw new UnsupportedOperationException("rectangular selection");
case LINES:
- selection = new LineWiseSelection(editorAdaptor, region.getStart(), region.getEnd());
+ /**
+ * TODO: ugly casting. The problem is, that if textObject already
+ * returns a LineWiseSelection, then by creating new instance of
+ * LineWiseSelection from the old one we extend the selected range
+ * by one line. This is due implementation of LineWiseSelection,
+ * whose getEnd() points to the line AFTER the actual selection. It
+ * might be solved by refactoring TextRange with introduction of
+ * linewise range (by line numbers)
+ */
+ if (region instanceof LineWiseSelection) {
+ selection = (LineWiseSelection) region;
+ }
+ else {
+ selection = new LineWiseSelection(editorAdaptor, region.getStart(), region.getEnd());
+ }
newMode = LinewiseVisualMode.NAME;
break;
case TEXT:
@@ -8,7 +8,12 @@
public void execute(EditorAdaptor editorAdaptor, int count, TextObject textObject)
throws CommandExecutionException {
- execute(editorAdaptor, textObject.getRegion(editorAdaptor, count), textObject.getContentType(editorAdaptor.getConfiguration()));
+ TextRange range = textObject.getRegion(editorAdaptor, count);
+
+ // Some text objects may (for some cases) decide to do nothing (e.g. ParagraphTextObject)
+ if (range != null) {
+ execute(editorAdaptor, range, textObject.getContentType(editorAdaptor.getConfiguration()));
+ }
}
public abstract void execute(EditorAdaptor editorAdaptor, TextRange region,
Oops, something went wrong.

0 comments on commit f093f99

Please sign in to comment.