From aef5fe1cfc096c0559d7aa75ca64011f08787822 Mon Sep 17 00:00:00 2001 From: Steven Guh Date: Thu, 29 Aug 2019 15:15:46 +0800 Subject: [PATCH 1/3] Make ReplaceWithRegister work in visual mode Fixes #4015 --- README.md | 11 +++++------ src/actions/plugins/replaceWithRegister.ts | 4 ++-- test/plugins/replaceWithRegister.test.ts | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b6bd20f1dbb..d438eb47eb7 100644 --- a/README.md +++ b/README.md @@ -598,12 +598,11 @@ Based on [ReplaceWithRegister](https://github.com/vim-scripts/ReplaceWithRegiste Once active, type `gr` (say "go replace") followed by a motion to describe the text you want replaced by the contents of the register. -| Motion Command | Description | -| -------------- | ---------------------------------------------------------------------------------- | -| `gr` | Replace the text described by the motion with the contents of the default register | -| `"agr` | Replace the text described by the motion with the contents of the `a` register | -| `grr` | Replace the currentline with the contents of the default register | -| `grr` | Replace the specified number of lines with the contents of the default register | +| Motion Command | Description | +| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | +| `[count]["a]gr` | Replace the text described by the motion with the contents of the default register or the specified register `a` in the example | +| `[count]["a]grr` | Replace the \[count\] lines or current line with the contents of the default register or the specified register `a` in the example | +| `{Visual}["a]gr` | Replace the selection with the contents of default register or the specified register `a` in the example | ## 🎩 VSCodeVim tricks! diff --git a/src/actions/plugins/replaceWithRegister.ts b/src/actions/plugins/replaceWithRegister.ts index 904d06ff5dd..61f8d5e0404 100644 --- a/src/actions/plugins/replaceWithRegister.ts +++ b/src/actions/plugins/replaceWithRegister.ts @@ -11,7 +11,7 @@ import { RegisterAction } from './../base'; @RegisterAction export class ReplaceOperator extends BaseOperator { public keys = ['g', 'r']; - public modes = [ModeName.Normal]; + public modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; public doesActionApply(vimState: VimState, keysPressed: string[]): boolean { return configuration.replaceWithRegister && super.doesActionApply(vimState, keysPressed); @@ -27,7 +27,7 @@ export class ReplaceOperator extends BaseOperator { const replaceWith = register.text as string; await TextEditor.replace(range, replaceWith); - + await vimState.setCurrentMode(ModeName.Normal); return updateCursorPosition(vimState, range, replaceWith); } } diff --git a/test/plugins/replaceWithRegister.test.ts b/test/plugins/replaceWithRegister.test.ts index 9be1453fb8c..7cc74fcc145 100644 --- a/test/plugins/replaceWithRegister.test.ts +++ b/test/plugins/replaceWithRegister.test.ts @@ -112,4 +112,25 @@ suite('replaceWithRegister plugin', () => { keysPressed: `${YankInnerWord}2grr`, end: ['|first', 'third'], }); + + newTest({ + title: 'Replaces in visual mode', + start: ['|first second'], + keysPressed: `${YankInnerWord}wviw${ReplaceOperator}`, + end: ['first firs|t'], + }); + + newTest({ + title: 'Replaces in visual mode using a specified register', + start: ['|first second'], + keysPressed: `"a${YankInnerWord}wviw"a${ReplaceOperator}`, + end: ['first firs|t'], + }); + + newTest({ + title: 'Replaces in visual line mode', + start: ['|first second'], + keysPressed: `${YankInnerWord}wV${ReplaceOperator}`, + end: ['firs|t'], + }); }); From 95378853d10c6a387f90e868477e9f9b4ffc86a9 Mon Sep 17 00:00:00 2001 From: Steven Guh Date: Thu, 29 Aug 2019 15:57:48 +0800 Subject: [PATCH 2/3] Force prettier --- src/cmd_line/commands/sort.ts | 6 +++--- src/configuration/notation.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd_line/commands/sort.ts b/src/cmd_line/commands/sort.ts index bdb1f3ac5a1..b6fa786f9be 100644 --- a/src/cmd_line/commands/sort.ts +++ b/src/cmd_line/commands/sort.ts @@ -58,9 +58,9 @@ export class SortCommand extends node.CommandBase { let lastLineLength = originalLines[originalLines.length - 1].length; - const compareFn = this._arguments.ignoreCase ? - (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase()) : - (a: string, b: string) => a.localeCompare(b); + const compareFn = this._arguments.ignoreCase + ? (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase()) + : (a: string, b: string) => a.localeCompare(b); let sortedLines = originalLines.sort(compareFn); diff --git a/src/configuration/notation.ts b/src/configuration/notation.ts index 7e7d8a6634b..a2f2e81e246 100644 --- a/src/configuration/notation.ts +++ b/src/configuration/notation.ts @@ -17,7 +17,7 @@ export class Notation { // Converts keystroke like to a single control character like \t public static ToControlCharacter(key: string) { - if (key === "") { + if (key === '') { return '\t'; } From fee1b953251a6ab5b24c56fded9e17bca41d712f Mon Sep 17 00:00:00 2001 From: Steven Guh Date: Fri, 30 Aug 2019 10:43:09 +0800 Subject: [PATCH 3/3] Update README to be less verbose --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d438eb47eb7..39585e5f3f8 100644 --- a/README.md +++ b/README.md @@ -598,11 +598,11 @@ Based on [ReplaceWithRegister](https://github.com/vim-scripts/ReplaceWithRegiste Once active, type `gr` (say "go replace") followed by a motion to describe the text you want replaced by the contents of the register. -| Motion Command | Description | -| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -| `[count]["a]gr` | Replace the text described by the motion with the contents of the default register or the specified register `a` in the example | -| `[count]["a]grr` | Replace the \[count\] lines or current line with the contents of the default register or the specified register `a` in the example | -| `{Visual}["a]gr` | Replace the selection with the contents of default register or the specified register `a` in the example | +| Motion Command | Description | +| ----------------------- | --------------------------------------------------------------------------------------- | +| `[count]["a]gr` | Replace the text described by the motion with the contents of the specified register | +| `[count]["a]grr` | Replace the \[count\] lines or current line with the contents of the specified register | +| `{Visual}["a]gr` | Replace the selection with the contents of the specified register | ## 🎩 VSCodeVim tricks!