From dcf923b406fbffe86a18be3c31af5ae5a329d0ad Mon Sep 17 00:00:00 2001 From: Horace He Date: Fri, 21 Apr 2017 22:14:16 -0400 Subject: [PATCH 1/9] Fixes #1193 --- src/actions/actions.ts | 4 +++- test/mode/modeNormal.test.ts | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 2e1d0a98343..2162dcb1884 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -5297,7 +5297,9 @@ class SelectWord extends TextObjectMovement { stop = position.getWordRight().getLeftThroughLineBreaks(); // If we aren't separated from the next word by whitespace(like in "horse ca|t,dog" or at the end of the line) // then we delete the spaces to the left of the current word. Otherwise, we delete to the right. - if (stop.isEqual(position.getCurrentWordEnd(true))) { + if (stop.isEqual(position.getCurrentWordEnd(true)) && !position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())) { + start = position.getWordLeft(true); + start = position.getFirstLineNonBlankChar(); start = position.getLastWordEnd().getRight(); } else { start = position.getWordLeft(true); diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 28b2366ae63..391897c9715 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -683,7 +683,14 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - + newTestOnly({ + title: "Can handle daw on words at beginning of line with leading whitespace", + start: ['if (something){', + ' |this.method();'], + keysPressed: 'daw', + end: ['if (something){', + ' |.method();'] + }); newTest({ title: "Can handle 'diw' on word with cursor inside spaces", From 719ab2888ea2c20f92029fa639cec3a5291253d8 Mon Sep 17 00:00:00 2001 From: Horace He Date: Fri, 21 Apr 2017 22:17:31 -0400 Subject: [PATCH 2/9] Added comment explaining the new condition --- src/actions/actions.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 728c840ad2f..0d1e1e275d4 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -5297,9 +5297,8 @@ class SelectWord extends TextObjectMovement { stop = position.getWordRight().getLeftThroughLineBreaks(); // If we aren't separated from the next word by whitespace(like in "horse ca|t,dog" or at the end of the line) // then we delete the spaces to the left of the current word. Otherwise, we delete to the right. - if (stop.isEqual(position.getCurrentWordEnd(true)) && !position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())) { - start = position.getWordLeft(true); - start = position.getFirstLineNonBlankChar(); + if (stop.isEqual(position.getCurrentWordEnd(true)) && + !position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())) { start = position.getLastWordEnd().getRight(); } else { start = position.getWordLeft(true); From 68d6531714125ecdbd11d3a0286c8f251d6c1b29 Mon Sep 17 00:00:00 2001 From: Horace He Date: Fri, 21 Apr 2017 22:20:18 -0400 Subject: [PATCH 3/9] removed newtestonly --- src/actions/actions.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 0d1e1e275d4..efc66accf35 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -5297,6 +5297,8 @@ class SelectWord extends TextObjectMovement { stop = position.getWordRight().getLeftThroughLineBreaks(); // If we aren't separated from the next word by whitespace(like in "horse ca|t,dog" or at the end of the line) // then we delete the spaces to the left of the current word. Otherwise, we delete to the right. + // Also, if the current word is the leftmost word, we only delete from the start of the word to the end. + if (stop.isEqual(position.getCurrentWordEnd(true)) && !position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())) { start = position.getLastWordEnd().getRight(); From 4465846fc9c78009df8fdb3a4d3b8e93ae570e71 Mon Sep 17 00:00:00 2001 From: Horace He Date: Fri, 21 Apr 2017 22:22:09 -0400 Subject: [PATCH 4/9] Moved new daw test to be with other daw tests --- test/mode/modeNormal.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 391897c9715..4dbc480f14f 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -643,6 +643,15 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); + newTest({ + title: "Can handle daw on words at beginning of line with leading whitespace", + start: ['if (something){', + ' |this.method();'], + keysPressed: 'daw', + end: ['if (something){', + ' |.method();'] + }); + newTest({ title: "Can handle 'daW' on big word with cursor inside spaces", start: ['one two | three, four '], @@ -683,15 +692,6 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ - title: "Can handle daw on words at beginning of line with leading whitespace", - start: ['if (something){', - ' |this.method();'], - keysPressed: 'daw', - end: ['if (something){', - ' |.method();'] - }); - newTest({ title: "Can handle 'diw' on word with cursor inside spaces", start: ['one two | three, four '], From 809dc6ee8bb702d87b492446027c31555393cdc0 Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 22 Apr 2017 17:08:26 -0400 Subject: [PATCH 5/9] Fixes #1350 --- src/actions/actions.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index efc66accf35..138a4063d18 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -5294,11 +5294,15 @@ class SelectWord extends TextObjectMovement { start = position.getLastWordEnd().getRight(); stop = position.getCurrentWordEnd(); } else { - stop = position.getWordRight().getLeftThroughLineBreaks(); + stop = position.getWordRight(); + if (stop.isEqual(stop.getFirstLineNonBlankChar())) { + stop = stop.getLineBegin(); + } + stop = stop.getLeftThroughLineBreaks().getLeftIfEOL(); // If we aren't separated from the next word by whitespace(like in "horse ca|t,dog" or at the end of the line) // then we delete the spaces to the left of the current word. Otherwise, we delete to the right. // Also, if the current word is the leftmost word, we only delete from the start of the word to the end. - + let t = position.getCurrentWordEnd(true) if (stop.isEqual(position.getCurrentWordEnd(true)) && !position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())) { start = position.getLastWordEnd().getRight(); From 78a0064d7ab7d5141726458d93d60dc8a9e6a804 Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 22 Apr 2017 17:08:48 -0400 Subject: [PATCH 6/9] Added new unit tests for 'daw' --- test/mode/modeNormal.test.ts | 70 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 4dbc480f14f..1963db20bb6 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -579,7 +579,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ + newTestOnly({ title: "Can handle 'ca`' inside word", start: ['one `t|wo`'], keysPressed: 'ca`', @@ -587,7 +587,7 @@ suite("Mode Normal", () => { endMode: ModeName.Insert }); - newTest({ + newTestOnly({ title: "Can handle 'daw' on word with cursor inside spaces", start: ['one two | three, four '], keysPressed: 'daw', @@ -595,7 +595,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ + newTestOnly({ title: "Can handle 'daw' on word with trailing spaces", start: ['one tw|o three, four '], keysPressed: 'daw', @@ -603,7 +603,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ + newTestOnly({ title: "Can handle 'daw' on word with leading spaces", start: ['one two th|ree, four '], keysPressed: 'daw', @@ -611,7 +611,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ + newTestOnly({ title: "Can handle 'daw' on word with numeric prefix", start: ['on|e two three, four '], keysPressed: 'd3aw', @@ -619,7 +619,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ + newTestOnly({ title: "Can handle 'daw' on word with numeric prefix and across lines", start: ['one two three, fo|ur ', 'five six'], keysPressed: 'd2aw', @@ -627,7 +627,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ + newTestOnly({ title: "Can handle 'daw' on word with numeric prefix and across lines, containing words end with `.`", start: ['one two three, fo|ur ', 'five. six'], keysPressed: 'd2aw', @@ -635,7 +635,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ + newTestOnly({ title: "Can handle 'daw' on end of word", start: ['one two three fou|r'], keysPressed: 'daw', @@ -643,8 +643,8 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ - title: "Can handle daw on words at beginning of line with leading whitespace", + newTestOnly({ + title: "Can handle 'daw' on words at beginning of line with leading whitespace", start: ['if (something){', ' |this.method();'], keysPressed: 'daw', @@ -652,6 +652,55 @@ suite("Mode Normal", () => { ' |.method();'] }); + newTestOnly({ + title: "Can handle 'daw' on words at ends of lines in the middle of whitespace", + start: ['one two | ', + 'four'], + keysPressed: 'daw', + end: ['one tw|o'] + }); + + newTestOnly({ + title: "Can handle 'daw' on word at beginning of file", + start: ['o|ne'], + keysPressed: 'daw', + end: ['|'] + }) + + newTestOnly({ + title: "Can handle 'daw' on word at beginning of line", + start: ['one two', + 'th|ree'], + keysPressed: 'daw', + end: ['one two', + '|'] + }); + + newTestOnly({ + title: "Can handle 'daw' on word at end of line with trailing whitespace", + start: ['one tw|o ', + 'three four'], + keysPressed: 'daw', + end: ['one| ', + 'three four'] + }) + + newTestOnly({ + title: "Can handle 'daw' around word at end of line", + start: ['one t|wo', + ' three'], + keysPressed: 'daw', + end: ['on|e', + ' three'] + }) + // newTestOnly({ + // title: "Can handle 'daw' on newline with words after", + // start: ['one two', + // '|', + // 'asdf'], + // keysPressed: 'daw', + // end: ['one tw|o'] + // }) newTest({ title: "Can handle 'daW' on big word with cursor inside spaces", start: ['one two | three, four '], @@ -660,6 +709,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); + newTest({ title: "Can handle 'daW' on word with trailing spaces", start: ['one tw|o three, four '], From 22460af052f93ecbf40188a0d40f38630e7bc63d Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 22 Apr 2017 17:10:48 -0400 Subject: [PATCH 7/9] removed broken test --- test/mode/modeNormal.test.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 1963db20bb6..9398203ea06 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -693,14 +693,6 @@ suite("Mode Normal", () => { end: ['on|e', ' three'] }) - // newTestOnly({ - // title: "Can handle 'daw' on newline with words after", - // start: ['one two', - // '|', - // 'asdf'], - // keysPressed: 'daw', - // end: ['one tw|o'] - // }) newTest({ title: "Can handle 'daW' on big word with cursor inside spaces", start: ['one two | three, four '], From 59e5a7380c25356fa5478887971ac67d735a043d Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 22 Apr 2017 17:16:37 -0400 Subject: [PATCH 8/9] Fixed linting issues --- src/actions/actions.ts | 1 - test/mode/modeNormal.test.ts | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 138a4063d18..9db662ea5c3 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -5302,7 +5302,6 @@ class SelectWord extends TextObjectMovement { // If we aren't separated from the next word by whitespace(like in "horse ca|t,dog" or at the end of the line) // then we delete the spaces to the left of the current word. Otherwise, we delete to the right. // Also, if the current word is the leftmost word, we only delete from the start of the word to the end. - let t = position.getCurrentWordEnd(true) if (stop.isEqual(position.getCurrentWordEnd(true)) && !position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())) { start = position.getLastWordEnd().getRight(); diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 9398203ea06..0eecb821535 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -665,7 +665,7 @@ suite("Mode Normal", () => { start: ['o|ne'], keysPressed: 'daw', end: ['|'] - }) + }); newTestOnly({ title: "Can handle 'daw' on word at beginning of line", @@ -683,7 +683,7 @@ suite("Mode Normal", () => { keysPressed: 'daw', end: ['one| ', 'three four'] - }) + }); newTestOnly({ title: "Can handle 'daw' around word at end of line", @@ -692,7 +692,8 @@ suite("Mode Normal", () => { keysPressed: 'daw', end: ['on|e', ' three'] - }) + }); + newTest({ title: "Can handle 'daW' on big word with cursor inside spaces", start: ['one two | three, four '], @@ -701,7 +702,6 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTest({ title: "Can handle 'daW' on word with trailing spaces", start: ['one tw|o three, four '], From ffef703e4d31f6435ddbf69baa5f89f9c05ae472 Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 22 Apr 2017 17:24:05 -0400 Subject: [PATCH 9/9] Removed newTestOnly --- test/mode/modeNormal.test.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 0eecb821535..f1983737e2c 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -579,7 +579,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'ca`' inside word", start: ['one `t|wo`'], keysPressed: 'ca`', @@ -587,7 +587,7 @@ suite("Mode Normal", () => { endMode: ModeName.Insert }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word with cursor inside spaces", start: ['one two | three, four '], keysPressed: 'daw', @@ -595,7 +595,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word with trailing spaces", start: ['one tw|o three, four '], keysPressed: 'daw', @@ -603,7 +603,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word with leading spaces", start: ['one two th|ree, four '], keysPressed: 'daw', @@ -611,7 +611,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word with numeric prefix", start: ['on|e two three, four '], keysPressed: 'd3aw', @@ -619,7 +619,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word with numeric prefix and across lines", start: ['one two three, fo|ur ', 'five six'], keysPressed: 'd2aw', @@ -627,7 +627,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word with numeric prefix and across lines, containing words end with `.`", start: ['one two three, fo|ur ', 'five. six'], keysPressed: 'd2aw', @@ -635,7 +635,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on end of word", start: ['one two three fou|r'], keysPressed: 'daw', @@ -643,7 +643,7 @@ suite("Mode Normal", () => { endMode: ModeName.Normal }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on words at beginning of line with leading whitespace", start: ['if (something){', ' |this.method();'], @@ -652,7 +652,7 @@ suite("Mode Normal", () => { ' |.method();'] }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on words at ends of lines in the middle of whitespace", start: ['one two | ', 'four'], @@ -660,14 +660,14 @@ suite("Mode Normal", () => { end: ['one tw|o'] }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word at beginning of file", start: ['o|ne'], keysPressed: 'daw', end: ['|'] }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word at beginning of line", start: ['one two', 'th|ree'], @@ -676,7 +676,7 @@ suite("Mode Normal", () => { '|'] }); - newTestOnly({ + newTest({ title: "Can handle 'daw' on word at end of line with trailing whitespace", start: ['one tw|o ', 'three four'], @@ -685,7 +685,7 @@ suite("Mode Normal", () => { 'three four'] }); - newTestOnly({ + newTest({ title: "Can handle 'daw' around word at end of line", start: ['one t|wo', ' three'],