Support for lower case and Sentence case in preserve-case replace.
Distinguish between titleize and capitalize for lower case and Sentence
case support.
Change them to return strict cases. (Don't keep other uppercase
letters.)
Add a clearer test.
MODIFY
lib/project/util.coffee
lib/project/util.coffee
@@ -36,16 +36,25 @@ showIf = (condition) ->
else
{display: 'none'}
-capitalize = (str) -> str.replace(/(?:^|\s)\S/g, (capital) -> capital.toUpperCase())
+capitalize = (str) -> str[0].toUpperCase() + str.toLowerCase().slice(1)
+titleize = (str) -> str.toLowerCase().replace(/(?:^|\s)\S/g, (capital) -> capital.toUpperCase())
preserveCase = (text, reference) ->
- # If replaced text is capitalized (strict), capitalize replacement
+ # If replaced text is capitalized (strict) like a sentence, capitalize replacement
if reference is capitalize(reference.toLowerCase())
capitalize(text)
+ # If replaced text is titleized (i.e., each word start with an uppercase), titleize replacement
+ else if reference is titleize(reference.toLowerCase())
+ titleize(text)
+
# If replaced text is uppercase, uppercase replacement
else if reference is reference.toUpperCase()
text.toUpperCase()
+
+ # If replaced text is lowercase, lowercase replacement
+ else if reference is reference.toLowerCase()
+ text.toLowerCase()
else
text

MODIFY
spec/buffer-search-spec.js
spec/buffer-search-spec.js
@@ -621,12 +621,12 @@ describe("BufferSearch", () => {
expect(editor.getText()).toBe(dedent`
-----------
foo bar bbb ccc
- ddd Foo Bar bbb
+ ddd Foo bar bbb
CCC DDD foo bar
-----------
FOO BAR Bbb cCc
- Ddd Foo Bar Bbb
- ccc DDD Foo Bar
+ Ddd Foo bar Bbb
+ ccc DDD Foo bar
-----------
`);
});
@@ -645,7 +645,7 @@ describe("BufferSearch", () => {
expect(editor.getText()).toBe(dedent`
-----------
foo ccc
- ddd foo
+ ddd Foo
CCC DDD aaa
-----------
foo cCc
@@ -690,15 +690,49 @@ describe("BufferSearch", () => {
expect(editor.getText()).toBe(dedent`
-----------
- FoO bbb ccc
- ddd FoO bbb
- CCC DDD FoO
+ foo bbb ccc
+ ddd Foo bbb
+ CCC DDD foo
-----------
FOO Bbb cCc
- Ddd FoO Bbb
- ccc DDD FoO
+ Ddd Foo Bbb
+ ccc DDD Foo
-----------
`);
});
+ it("preserves case of sentence, title, upper and lower case.", () => {
+ editor.setText(dedent`
+ x aaa bbb x
+ x Aaa bbb x
+ x aaa Bbb x
+ x Aaa Bbb x
+ x AAA BBB x
+ x aaA bbb x
+ x aaa bbB x
+ x aaA bbB x
+ `);
+ advanceClock(editor.buffer.stoppedChangingDelay);
+
+ model.search("aAa bBb", {
+ caseSensitive: false,
+ useRegex: false,
+ wholeWord: false
+ });
+ const markers = markersListener.mostRecentCall.args[0];
+ markersListener.reset();
+
+ model.replace(markers, "xxX yYy");
+
+ expect(editor.getText()).toBe(dedent`
+ x xxx yyy x
+ x Xxx yyy x
+ x xxX yYy x
+ x Xxx Yyy x
+ x XXX YYY x
+ x xxX yYy x
+ x xxX yYy x
+ x xxX yYy x
+ `);
+ });
});
});

Support for lower case and Sentence case in preserve-case replace.
Distinguish between titleize and capitalize for lower case and Sentence
case support.
Change them to return strict cases. (Don't keep other uppercase
letters.)
Add a clearer test.