Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(point): a hyphen starts a new word for capitalize (Foo-Bar)

AdityaUmale49586bfda667
diff --git a/shared/app-frame/point.test.ts b/shared/app-frame/point.test.ts
index cb82f1c266..405b831479 100644
--- a/shared/app-frame/point.test.ts
+++ b/shared/app-frame/point.test.ts
@@ -118,13 +118,13 @@ describe("the page's point script", () => {
expect(posted).toHaveLength(1);
});
- it("keeps a capital after leading punctuation, and names a closed select by its chosen option", () => {
+ it("keeps a capital after leading punctuation and a hyphen, and names a closed select by its chosen option", () => {
const { say } = boot();
- document.body.innerHTML = `<p class="cap" style="text-transform:capitalize">(note) <b>"</b>two</p>
+ document.body.innerHTML = `<p class="cap" style="text-transform:capitalize">(note) <b>"</b>two foo-bar</p>
<select id="plan"><option>Free</option><option selected>Pro</option></select>`;
say(pointMessage(true));
click(document.querySelector(".cap")!);
- expect(posted.at(-1)).toMatchObject({ params: { tag: "p", text: '(Note) "Two' } });
+ expect(posted.at(-1)).toMatchObject({ params: { tag: "p", text: '(Note) "Two Foo-Bar' } });
say(pointMessage(true));
click(document.querySelector("#plan")!);
expect(posted.at(-1)).toMatchObject({ params: { tag: "select", text: "Pro" } });
diff --git a/shared/app-frame/point.ts b/shared/app-frame/point.ts
index c952c88dd9..785d91abc6 100644
--- a/shared/app-frame/point.ts
+++ b/shared/app-frame/point.ts
@@ -121,13 +121,13 @@ export const APP_POINT_SOURCE = `(function () {
}
return parts.join(" > ");
};
- // state.start is true at a word start; punctuation before the first letter keeps it, as CSS capitalize does ("(Note)"),
+ // state.start is true at a word start (after a space or hyphen: "Foo-Bar"); punctuation before the first letter keeps it, as CSS capitalize does ("(Note)"),
// and it carries across inline tags so a word split by them gets one capital.
var cased = function (text, transform, state) {
if (transform === "uppercase") return text.toUpperCase();
if (transform === "lowercase") return text.toLowerCase();
return text.replace(/[\\s\\S]/g, function (letter) {
- if (/\\s/.test(letter)) { state.start = true; return letter; }
+ if (/\\s/.test(letter) || letter === "-") { state.start = true; return letter; }
if (!/[\\p{L}\\p{N}]/u.test(letter)) return letter;
var start = state.start;
state.start = false;