From 0f4ef70757b5b0dd7c0b0c738552c75858a4d716 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 7 Oct 2017 01:09:52 +0900 Subject: [PATCH 1/6] set objective: new config param --- lib/settings.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/settings.js b/lib/settings.js index 658f48ca8..fc4a769ca 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -290,6 +290,12 @@ module.exports = new Settings("vim-mode-plus", { }, groupChangesWhenLeavingInsertMode: true, useClipboardAsDefaultRegister: true, + defaultBlackholedOperators: { + default: [], + items: {type: "string"}, + description: + "List of operator name here, for these operators, vmp does not update clipboard unless explicitly specified.
e.g. Delete, Change, Substitute", + }, dontUpdateRegisterOnChangeOrSubstitute: { default: false, description: From 4e6dfe790d635bacd95bc1d22ca126ef99fb0321 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 7 Oct 2017 02:12:50 +0900 Subject: [PATCH 2/6] Done with fake-wildcard support --- lib/operator.js | 15 ++++++ lib/settings.js | 4 +- spec/prefix-spec.coffee | 109 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) diff --git a/lib/operator.js b/lib/operator.js index 1490c5557..a4e175e2c 100644 --- a/lib/operator.js +++ b/lib/operator.js @@ -234,9 +234,14 @@ class Operator extends Base { } setTextToRegister(text, selection) { + if (this.vimState.register.isUnnamed() && this.isBlackholeRegisteredOperator()) { + return + } + if (this.target.isLinewise() && !text.endsWith("\n")) { text += "\n" } + if (text) { this.vimState.register.set(null, {text, selection}) @@ -254,6 +259,16 @@ class Operator extends Base { } } + isBlackholeRegisteredOperator() { + const operators = this.getConfig("blackholeRegisteredOperators") + const wildCardOperators = operators.filter(name => name.endsWith("*")) + const commandName = this.getCommandNameWithoutPrefix() + return ( + wildCardOperators.some(name => new RegExp("^" + name.replace("*", ".*")).test(commandName)) || + operators.includes(commandName) + ) + } + needSaveToNumberedRegister(target) { // Used to determine what register to use on change and delete operation. // Following motion should save to 1-9 register regerdless of content is small or big. diff --git a/lib/settings.js b/lib/settings.js index fc4a769ca..6378058f5 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -290,11 +290,11 @@ module.exports = new Settings("vim-mode-plus", { }, groupChangesWhenLeavingInsertMode: true, useClipboardAsDefaultRegister: true, - defaultBlackholedOperators: { + blackholeRegisteredOperators: { default: [], items: {type: "string"}, description: - "List of operator name here, for these operators, vmp does not update clipboard unless explicitly specified.
e.g. Delete, Change, Substitute", + "List of operator command name to disable register update.
e.g. `delete-right, delete-left, delete, substitute`
Also you can use special value(`delete*`, `change*`, `substitute*`) to specify all same-family operators.", }, dontUpdateRegisterOnChangeOrSubstitute: { default: false, diff --git a/spec/prefix-spec.coffee b/spec/prefix-spec.coffee index 1a1756438..90246fc44 100644 --- a/spec/prefix-spec.coffee +++ b/spec/prefix-spec.coffee @@ -438,3 +438,112 @@ describe "Prefixes", -> ensure 'd 2 w', text: "222 333 444 555 666 777 888 999" it "repeat operator and motion respectively", -> ensure '3 d 2 w', text: "666 777 888 999" + describe "Count modifier", -> + beforeEach -> + set + text: "000 111 222 333 444 555 666 777 888 999" + cursor: [0, 0] + + it "repeat operator", -> + ensure '3 d w', text: "333 444 555 666 777 888 999" + it "repeat motion", -> + ensure 'd 2 w', text: "222 333 444 555 666 777 888 999" + it "repeat operator and motion respectively", -> + ensure '3 d 2 w', text: "666 777 888 999" + + fdescribe "blackholeRegisteredOperators settings", -> + beforeEach -> + set + textC: "a|bc" + + describe "when false(default)", -> + it "default", -> ensure register: {'"': text: "initial clipboard content"} + it 'c mutate register', -> ensure 'c l', register: {'"': text: 'b'} + it 'C mutate register', -> ensure 'C', register: {'"': text: 'bc'} + it 'x mutate register', -> ensure 'x', register: {'"': text: 'b'} + it 'X mutate register', -> ensure 'X', register: {'"': text: 'a'} + it 'y mutate register', -> ensure 'y l', register: {'"': text: 'b'} + it 'Y mutate register', -> ensure 'Y', register: {'"': text: "abc\n"} + it 's mutate register', -> ensure 's', register: {'"': text: 'b'} + it 'S mutate register', -> ensure 'S', register: {'"': text: 'abc\n'} + it 'd mutate register', -> ensure 'd l', register: {'"': text: 'b'} + it 'D mutate register', -> ensure 'D', register: {'"': text: 'bc'} + + describe "when true(default)", -> + describe "blackhole all", -> + beforeEach -> + settings.set "blackholeRegisteredOperators", [ + "change" # c + "change-to-last-character-of-line" # C + "change-line" # C in visual + "change-occurrence" + "change-occurrence-from-search" + "delete" # d + "delete-to-last-character-of-line" # D + "delete-line" # D in visual + "delete-right" # x + "delete-left" # X + "substitute" # s + "substitute-line" # S + "yank" # y + "yank-line" # Y + # "delete*" + # "change*" + # "yank*" + # "substitute*" + ] + + it "default", -> ensure register: {'"': text: "initial clipboard content"} + it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content" } + it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content" } + it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content" } + it 'X NOT mutate register', -> ensure 'X', register: {'"': text: "initial clipboard content" } + it 'y NOT mutate register', -> ensure 'y l', register: {'"': text: "initial clipboard content" } + it 'Y NOT mutate register', -> ensure 'Y', register: {'"': text: "initial clipboard content" } + it 's NOT mutate register', -> ensure 's', register: {'"': text: "initial clipboard content" } + it 'S NOT mutate register', -> ensure 'S', register: {'"': text: "initial clipboard content" } + it 'd NOT mutate register', -> ensure 'd l', register: {'"': text: "initial clipboard content" } + it 'D NOT mutate register', -> ensure 'D', register: {'"': text: "initial clipboard content" } + + describe "blackhole selectively", -> + beforeEach -> + settings.set "blackholeRegisteredOperators", [ + "change-to-last-character-of-line" # C + "delete-right" # x + "substitute" # s + ] + + it "default", -> ensure register: {'"': text: "initial clipboard content"} + it 'c mutate register', -> ensure 'c l', register: {'"': text: 'b'} + it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content"} + it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content"} + it 'X mutate register', -> ensure 'X', register: {'"': text: 'a'} + it 'y mutate register', -> ensure 'y l', register: {'"': text: 'b'} + it 'Y mutate register', -> ensure 'Y', register: {'"': text: "abc\n"} + it 's NOT mutate register', -> ensure 's', register: {'"': text: "initial clipboard content"} + it 'S mutate register', -> ensure 'S', register: {'"': text: 'abc\n'} + it 'd mutate register', -> ensure 'd l', register: {'"': text: 'b'} + it 'D mutate register', -> ensure 'D', register: {'"': text: 'bc'} + + describe "blackhole by wildcard", -> + beforeEach -> + settings.set "blackholeRegisteredOperators", [ + "change*" # C + "delete*" # x + # "substitute*" # s + # "yank*" + ] + + it "default", -> ensure register: {'"': text: "initial clipboard content"} + it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content"} + it 'c still CAN update register if specified explicitly', -> ensure '" a c l', register: {'a': text: "b"} + it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content"} + it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content"} + it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content"} + it 'X NOT mutate register', -> ensure 'X', register: {'"': text: "initial clipboard content"} + it 'y mutate register', -> ensure 'y l', register: {'"': text: 'b'} + it 'Y mutate register', -> ensure 'Y', register: {'"': text: "abc\n"} + it 's mutate register', -> ensure 's', register: {'"': text: 'b'} + it 'S mutate register', -> ensure 'S', register: {'"': text: 'abc\n'} + it 'd NOT mutate register', -> ensure 'd l', register: {'"': text: "initial clipboard content"} + it 'D NOT mutate register', -> ensure 'D', register: {'"': text: "initial clipboard content"} From 88cd57ab0cd7317cafceaeecf02d5bb6c7e2d400 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 7 Oct 2017 02:20:53 +0900 Subject: [PATCH 3/6] update setting descriptions --- lib/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/settings.js b/lib/settings.js index 6378058f5..e4c7484d8 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -294,7 +294,7 @@ module.exports = new Settings("vim-mode-plus", { default: [], items: {type: "string"}, description: - "List of operator command name to disable register update.
e.g. `delete-right, delete-left, delete, substitute`
Also you can use special value(`delete*`, `change*`, `substitute*`) to specify all same-family operators.", + "Comma separated list of operator command name to disable register update.
e.g. `delete-right, delete-left, delete, substitute`
Also you can use special value(`delete*`, `change*`, `substitute*`) to specify all same-family operators.", }, dontUpdateRegisterOnChangeOrSubstitute: { default: false, From dacecfeee23f9ba7b4562fe3fb26c1ca92205cb4 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 7 Oct 2017 02:36:05 +0900 Subject: [PATCH 4/6] add migration from old dontUpdateRegisterOnChangeOrSubstitute param --- lib/settings.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/settings.js b/lib/settings.js index e4c7484d8..edfa76023 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -19,6 +19,11 @@ const RENAMED_PARAMS = [ {oldName: "keepColumnOnSelectTextObject", newName: "stayOnSelectTextObject"}, {oldName: "moveToFirstCharacterOnVerticalMotion", newName: "stayOnVerticalMotion", setValueBy: invertValue}, {oldName: "keymapSemicolonToConfirmFind", newName: "keymapSemicolonToConfirmOnFindInput"}, + { + oldName: "dontUpdateRegisterOnChangeOrSubstitute", + newName: "blackholeRegisteredOperators", + setValueBy: enabled => (enabled ? ["change*", "substitute*"] : undefined), + }, ] class Settings { @@ -296,11 +301,6 @@ module.exports = new Settings("vim-mode-plus", { description: "Comma separated list of operator command name to disable register update.
e.g. `delete-right, delete-left, delete, substitute`
Also you can use special value(`delete*`, `change*`, `substitute*`) to specify all same-family operators.", }, - dontUpdateRegisterOnChangeOrSubstitute: { - default: false, - description: - "When enabled, `change` and `substitute` no longer update register content
Affects `c`, `C`, `s`, `S` operator.", - }, startInInsertMode: false, startInInsertModeScopes: { default: [], From a722243c07f715103b232aba132ade181daf8fe3 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 7 Oct 2017 03:06:27 +0900 Subject: [PATCH 5/6] fix lint-error --- spec/prefix-spec.coffee | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/prefix-spec.coffee b/spec/prefix-spec.coffee index 90246fc44..4a3f433e0 100644 --- a/spec/prefix-spec.coffee +++ b/spec/prefix-spec.coffee @@ -494,16 +494,16 @@ describe "Prefixes", -> ] it "default", -> ensure register: {'"': text: "initial clipboard content"} - it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content" } - it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content" } - it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content" } - it 'X NOT mutate register', -> ensure 'X', register: {'"': text: "initial clipboard content" } - it 'y NOT mutate register', -> ensure 'y l', register: {'"': text: "initial clipboard content" } - it 'Y NOT mutate register', -> ensure 'Y', register: {'"': text: "initial clipboard content" } - it 's NOT mutate register', -> ensure 's', register: {'"': text: "initial clipboard content" } - it 'S NOT mutate register', -> ensure 'S', register: {'"': text: "initial clipboard content" } - it 'd NOT mutate register', -> ensure 'd l', register: {'"': text: "initial clipboard content" } - it 'D NOT mutate register', -> ensure 'D', register: {'"': text: "initial clipboard content" } + it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content"} + it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content"} + it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content"} + it 'X NOT mutate register', -> ensure 'X', register: {'"': text: "initial clipboard content"} + it 'y NOT mutate register', -> ensure 'y l', register: {'"': text: "initial clipboard content"} + it 'Y NOT mutate register', -> ensure 'Y', register: {'"': text: "initial clipboard content"} + it 's NOT mutate register', -> ensure 's', register: {'"': text: "initial clipboard content"} + it 'S NOT mutate register', -> ensure 'S', register: {'"': text: "initial clipboard content"} + it 'd NOT mutate register', -> ensure 'd l', register: {'"': text: "initial clipboard content"} + it 'D NOT mutate register', -> ensure 'D', register: {'"': text: "initial clipboard content"} describe "blackhole selectively", -> beforeEach -> From 3f2741ef3eaab8720bfb57e8dc5f4aaf2f7e8a79 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 7 Oct 2017 12:06:43 +0900 Subject: [PATCH 6/6] cleanup/unfocus --- spec/prefix-spec.coffee | 95 +++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/spec/prefix-spec.coffee b/spec/prefix-spec.coffee index 4a3f433e0..edd8cf11c 100644 --- a/spec/prefix-spec.coffee +++ b/spec/prefix-spec.coffee @@ -451,23 +451,24 @@ describe "Prefixes", -> it "repeat operator and motion respectively", -> ensure '3 d 2 w', text: "666 777 888 999" - fdescribe "blackholeRegisteredOperators settings", -> + describe "blackholeRegisteredOperators settings", -> + originalText = "initial clipboard content" beforeEach -> set textC: "a|bc" describe "when false(default)", -> - it "default", -> ensure register: {'"': text: "initial clipboard content"} - it 'c mutate register', -> ensure 'c l', register: {'"': text: 'b'} - it 'C mutate register', -> ensure 'C', register: {'"': text: 'bc'} - it 'x mutate register', -> ensure 'x', register: {'"': text: 'b'} - it 'X mutate register', -> ensure 'X', register: {'"': text: 'a'} - it 'y mutate register', -> ensure 'y l', register: {'"': text: 'b'} - it 'Y mutate register', -> ensure 'Y', register: {'"': text: "abc\n"} - it 's mutate register', -> ensure 's', register: {'"': text: 'b'} - it 'S mutate register', -> ensure 'S', register: {'"': text: 'abc\n'} - it 'd mutate register', -> ensure 'd l', register: {'"': text: 'b'} - it 'D mutate register', -> ensure 'D', register: {'"': text: 'bc'} + it "default", -> ensure register: {'"': text: originalText} + it 'c update', -> ensure 'c l', register: {'"': text: 'b'} + it 'C update', -> ensure 'C', register: {'"': text: 'bc'} + it 'x update', -> ensure 'x', register: {'"': text: 'b'} + it 'X update', -> ensure 'X', register: {'"': text: 'a'} + it 'y update', -> ensure 'y l', register: {'"': text: 'b'} + it 'Y update', -> ensure 'Y', register: {'"': text: "abc\n"} + it 's update', -> ensure 's', register: {'"': text: 'b'} + it 'S update', -> ensure 'S', register: {'"': text: 'abc\n'} + it 'd update', -> ensure 'd l', register: {'"': text: 'b'} + it 'D update', -> ensure 'D', register: {'"': text: 'bc'} describe "when true(default)", -> describe "blackhole all", -> @@ -493,17 +494,17 @@ describe "Prefixes", -> # "substitute*" ] - it "default", -> ensure register: {'"': text: "initial clipboard content"} - it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content"} - it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content"} - it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content"} - it 'X NOT mutate register', -> ensure 'X', register: {'"': text: "initial clipboard content"} - it 'y NOT mutate register', -> ensure 'y l', register: {'"': text: "initial clipboard content"} - it 'Y NOT mutate register', -> ensure 'Y', register: {'"': text: "initial clipboard content"} - it 's NOT mutate register', -> ensure 's', register: {'"': text: "initial clipboard content"} - it 'S NOT mutate register', -> ensure 'S', register: {'"': text: "initial clipboard content"} - it 'd NOT mutate register', -> ensure 'd l', register: {'"': text: "initial clipboard content"} - it 'D NOT mutate register', -> ensure 'D', register: {'"': text: "initial clipboard content"} + it "default", -> ensure register: {'"': text: originalText} + it 'c NOT update', -> ensure 'c l', register: {'"': text: originalText} + it 'C NOT update', -> ensure 'C', register: {'"': text: originalText} + it 'x NOT update', -> ensure 'x', register: {'"': text: originalText} + it 'X NOT update', -> ensure 'X', register: {'"': text: originalText} + it 'y NOT update', -> ensure 'y l', register: {'"': text: originalText} + it 'Y NOT update', -> ensure 'Y', register: {'"': text: originalText} + it 's NOT update', -> ensure 's', register: {'"': text: originalText} + it 'S NOT update', -> ensure 'S', register: {'"': text: originalText} + it 'd NOT update', -> ensure 'd l', register: {'"': text: originalText} + it 'D NOT update', -> ensure 'D', register: {'"': text: originalText} describe "blackhole selectively", -> beforeEach -> @@ -513,17 +514,17 @@ describe "Prefixes", -> "substitute" # s ] - it "default", -> ensure register: {'"': text: "initial clipboard content"} - it 'c mutate register', -> ensure 'c l', register: {'"': text: 'b'} - it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content"} - it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content"} - it 'X mutate register', -> ensure 'X', register: {'"': text: 'a'} - it 'y mutate register', -> ensure 'y l', register: {'"': text: 'b'} - it 'Y mutate register', -> ensure 'Y', register: {'"': text: "abc\n"} - it 's NOT mutate register', -> ensure 's', register: {'"': text: "initial clipboard content"} - it 'S mutate register', -> ensure 'S', register: {'"': text: 'abc\n'} - it 'd mutate register', -> ensure 'd l', register: {'"': text: 'b'} - it 'D mutate register', -> ensure 'D', register: {'"': text: 'bc'} + it "default", -> ensure register: {'"': text: originalText} + it 'c update', -> ensure 'c l', register: {'"': text: 'b'} + it 'C NOT update', -> ensure 'C', register: {'"': text: originalText} + it 'x NOT update', -> ensure 'x', register: {'"': text: originalText} + it 'X update', -> ensure 'X', register: {'"': text: 'a'} + it 'y update', -> ensure 'y l', register: {'"': text: 'b'} + it 'Y update', -> ensure 'Y', register: {'"': text: "abc\n"} + it 's NOT update', -> ensure 's', register: {'"': text: originalText} + it 'S update', -> ensure 'S', register: {'"': text: 'abc\n'} + it 'd update', -> ensure 'd l', register: {'"': text: 'b'} + it 'D update', -> ensure 'D', register: {'"': text: 'bc'} describe "blackhole by wildcard", -> beforeEach -> @@ -534,16 +535,16 @@ describe "Prefixes", -> # "yank*" ] - it "default", -> ensure register: {'"': text: "initial clipboard content"} - it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content"} - it 'c still CAN update register if specified explicitly', -> ensure '" a c l', register: {'a': text: "b"} - it 'c NOT mutate register', -> ensure 'c l', register: {'"': text: "initial clipboard content"} - it 'C NOT mutate register', -> ensure 'C', register: {'"': text: "initial clipboard content"} - it 'x NOT mutate register', -> ensure 'x', register: {'"': text: "initial clipboard content"} - it 'X NOT mutate register', -> ensure 'X', register: {'"': text: "initial clipboard content"} - it 'y mutate register', -> ensure 'y l', register: {'"': text: 'b'} - it 'Y mutate register', -> ensure 'Y', register: {'"': text: "abc\n"} - it 's mutate register', -> ensure 's', register: {'"': text: 'b'} - it 'S mutate register', -> ensure 'S', register: {'"': text: 'abc\n'} - it 'd NOT mutate register', -> ensure 'd l', register: {'"': text: "initial clipboard content"} - it 'D NOT mutate register', -> ensure 'D', register: {'"': text: "initial clipboard content"} + it "default", -> ensure register: {'"': text: originalText} + it 'c NOT update', -> ensure 'c l', register: {'"': text: originalText} + it 'c update if specified', -> ensure '" a c l', register: {'a': text: "b"} + it 'c NOT update', -> ensure 'c l', register: {'"': text: originalText} + it 'C NOT update', -> ensure 'C', register: {'"': text: originalText} + it 'x NOT update', -> ensure 'x', register: {'"': text: originalText} + it 'X NOT update', -> ensure 'X', register: {'"': text: originalText} + it 'y update', -> ensure 'y l', register: {'"': text: 'b'} + it 'Y update', -> ensure 'Y', register: {'"': text: "abc\n"} + it 's update', -> ensure 's', register: {'"': text: 'b'} + it 'S update', -> ensure 'S', register: {'"': text: 'abc\n'} + it 'd NOT update', -> ensure 'd l', register: {'"': text: originalText} + it 'D NOT update', -> ensure 'D', register: {'"': text: originalText}