Skip to content

Commit 9afe410

Browse files
committed
Offer "Remove it" beside "Ghost it", and on ghosted text
The owner asked for an option to remove a word alongside ghosting it, and to keep it for text already ghosted. - An adverb, qualifier, intensifier, or filler offers "Ghost it" and "Remove it". Where a ghost can't go, inside part of an alternative, it offers "Remove it" and says why there's no ghost. - After "Ghost it" the popover stays on the ghost, with "Remove it" and "Revive it". A click on any ghost while Review is open does the same, and ⌥↩ in a ghost removes it. Ghosted text isn't marked, so a click there means the ghost, not a mark around it. - A writing issue Claude says to cut offers "Remove it". - Removing tidies around the words: one space between words, no space before punctuation, no comma left alone ("It is, basically, done." → "It is done."), and a capital where a sentence now starts ("Basically, it is done." → "It is done."). ⌘Z brings them back. "Make the cuts" keeps its own, simpler delete. Tests: layers.test.ts covers the tidy delete; popover.test.ts covers each action, the ghost popover, ⌥↩ in a ghost, and undo. Each failed first, and breaking each of 12 rules failed a test. Checked in the browser preview: ghost, then remove, with ⌥↩ and the buttons, and undo. Not yet tried in the macOS app.
1 parent 45841f7 commit 9afe410

8 files changed

Lines changed: 205 additions & 45 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ update as you type.
151151

152152
**Click a highlight** to see why it's marked and what to do. A suggestion, in the form and case of
153153
your words, becomes an alternative, and ⌥K brings yours back. An adverb, qualifier, intensifier, or
154-
filler can be ghosted, so you read the sentence without it. Passive voice, hard sentences, and
154+
filler can be ghosted, so you read the sentence without it, or removed. A click on ghosted text
155+
offers "Remove it" and "Revive it". Removing tidies the spaces, commas, and capital around the
156+
words, and ⌘Z brings them back. Passive voice, hard sentences, and
155157
hidden actions with no suggestion offer "Rewrite with Claude": Claude rewrites the sentence to fix
156158
it, and the rewrites that the checks no longer mark join it as alternatives. Ask again for more.
157159
Only that button, ⌥↩ on such a mark, or its ⌘K entry sends the paragraph to Claude. ⌥↩ does the first action at

‎docs/layout-plan.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,11 @@ Phases 4 and 5 don't need the checker, so either can come next.
249249
- The popover belongs to the caret: it opens on a click or a row's jump, and closes when you type,
250250
move off the mark, select, press Esc, or close Review. So it never points at text that changed,
251251
as Hemingway's can.
252-
- Each action keeps a way back. A suggestion becomes an alternative. A word to cut gets ghosted,
253-
not deleted. Passive voice, hard sentences, and hidden actions with no suggestion get "Rewrite
252+
- Each action keeps a way back. A suggestion becomes an alternative. A word to cut can be ghosted
253+
or removed; after "Ghost it" the popover stays on the ghost, with "Remove it" and "Revive it",
254+
and a click on any ghost while Review is open offers the same. Removing tidies the spaces,
255+
commas, and capital around the words, and undo brings them back. A writing issue Claude says to
256+
cut offers "Remove it". Passive voice, hard sentences, and hidden actions with no suggestion get "Rewrite
254257
with Claude". Its prompt names the goal,
255258
such as the active voice, and the live checks drop any rewrite they would still mark. The first
256259
version reused ⌘⇧G, whose drop-in prompt kept 4 of 6 rewrites passive. The prompt names the words

‎src/editor/commands.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,30 @@ export function deleteSpans(state: EditorState, spans: Span[]): ChangeSpec[] {
492492
});
493493
}
494494

495+
/**
496+
* Deletes a word or phrase and tidies around it: one space between words, no space before
497+
* punctuation, no comma left alone, and a capital where a sentence now starts.
498+
*/
499+
export function removeSpan(state: EditorState, span: Span): TransactionSpec {
500+
const line = state.doc.lineAt(span.from);
501+
const text = line.text;
502+
let a = span.from - line.from;
503+
let b = span.to - line.from;
504+
const starts = /(?:^|[.!?]["'”’)]*\s+)$/u.test(text.slice(0, a).replace(/^[ \t]*(?:>\s*|[-*+]\s+|\d+[.)]\s+)*/u, ""));
505+
if (text.slice(a - 2, a) === ", " && text[b] === ",") [a, b] = [a - 2, b + 1]; // "It is, basically, done."
506+
else if (starts && text.slice(b, b + 2) === ", ") b += 1; // "Basically, it is done."
507+
if (text[a - 1] === " " && (text[b] === " " || b === text.length || /[.,;:!?)\]]/.test(text[b]))) a -= 1;
508+
else if (text[b] === " " && (a === 0 || starts)) b += 1;
509+
const changes: ChangeSpec[] = [{ from: line.from + a, to: line.from + b }];
510+
// The next word starts the sentence now.
511+
const next = text.slice(b).match(/^\s*(\p{Ll})/u);
512+
if (starts && next) {
513+
const at = line.from + b + next[0].length - 1;
514+
changes.push({ from: at, to: at + 1, insert: next[1].toUpperCase() });
515+
}
516+
return { changes };
517+
}
518+
495519
/** Deletes all ghosted text: "make the cuts". */
496520
export function deleteGhosts(state: EditorState): TransactionSpec | null {
497521
const { ghosts } = layersOf(state);

‎src/editor/highlights.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export function writingIssues(state: EditorState): WritingIssue[] | null {
117117
return state.field(highlightsField, false)?.writing ?? null;
118118
}
119119

120+
/** Whether Review is open, so its marks and the popover show. */
121+
export const reviewOpen = (state: EditorState) => state.field(highlightsField, false)?.on ?? false;
122+
120123
/** The marks on the page while Review is open, writing issues first, without hidden kinds. */
121124
export function shownIssues(state: EditorState): Issue[] {
122125
const h = state.field(highlightsField, false);

‎src/editor/layers.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
setVersionActive,
1616
startsWithVowelSound,
1717
ghostBlocked,
18+
removeSpan,
1819
toggleGhost,
1920
versionedItems,
2021
} from "./commands";
@@ -193,6 +194,20 @@ describe("undo", () => {
193194
expect(layersOf(run(state, toggleGhost)).ghosts).toEqual([]);
194195
});
195196

197+
it("removes words and tidies the spaces, commas, and capital around them", () => {
198+
const remove = (text: string, word: string) => {
199+
const state = stateFor(`${text}\n`);
200+
const from = at(state, word);
201+
return state.update(removeSpan(state, { from, to: from + word.length })).state.doc.toString();
202+
};
203+
expect(remove("She left quickly.", "quickly")).toBe("She left.");
204+
expect(remove("It is really done.", "really")).toBe("It is done.");
205+
expect(remove("Basically, it is done.", "Basically")).toBe("It is done.");
206+
expect(remove("It is, basically, done.", "basically")).toBe("It is done.");
207+
expect(remove("Done. Perhaps we left.", "Perhaps")).toBe("Done. We left.");
208+
expect(remove("Really", "Really")).toBe("");
209+
});
210+
196211
it("undoes a ghost toggle", () => {
197212
let state = select(stateFor("one two three\n"), 4, 7);
198213
state = run(state, toggleGhost);

‎src/editor/popover.test.ts‎

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ describe("popover actions", () => {
193193
const issue = popoverAt(click(state, pos))!;
194194
return [issue.kind, actionsFor(state, issue).map((a) => a.kind)];
195195
};
196-
expect(first("She left quickly.\n", 11)).toEqual(["adverb", ["ghost"]]);
197-
expect(first("It is basically done.\n", 8)).toEqual(["filler", ["ghost"]]);
198-
expect(first("It is perhaps done.\n", 8)).toEqual(["qualifier", ["ghost"]]);
196+
expect(first("She left quickly.\n", 11)).toEqual(["adverb", ["ghost", "remove"]]);
197+
expect(first("It is basically done.\n", 8)).toEqual(["filler", ["ghost", "remove"]]);
198+
expect(first("It is perhaps done.\n", 8)).toEqual(["qualifier", ["ghost", "remove"]]);
199199
expect(first("He will be able to swim.\n", 10)).toEqual(["hidden", ["rewrite"]]);
200200
// 20 words, grade 12: hard. 19 long words, grade 29: very hard.
201201
expect(
@@ -229,12 +229,60 @@ describe("popover actions", () => {
229229
expect(undoRedo(state)).toEqual(["It was an initial test.\n", "It was a {{initial|>~first}} test.\n"]);
230230
});
231231

232+
it("offer to remove a word you might cut, beside ghosting it", () => {
233+
let state = stateFor("She left quickly.\n");
234+
const issue = popoverAt(click(state, 12))!;
235+
expect(actionsFor(state, issue)).toEqual([
236+
{ kind: "ghost", label: "Ghost it" },
237+
{ kind: "remove", label: "Remove it" },
238+
]);
239+
state = state.update(runAction(state, issue, actionsFor(state, issue)[1])!).state;
240+
expect(pageMarkdown(state, "")).toBe("She left.\n");
241+
expect(undoRedo(state)).toEqual(["She left quickly.\n", "She left.\n"]);
242+
});
243+
244+
it("keep the popover on the ghost after ghosting, to remove or revive it", () => {
245+
let state = click(stateFor("It is really done.\n"), 8);
246+
state = state.update(runAction(state, popoverAt(state)!, { kind: "ghost", label: "Ghost it" })!).state;
247+
const ghost = popoverAt(state)!;
248+
expect(ghost).toMatchObject({ kind: "ghost", from: 6, to: 12 });
249+
expect(popoverAt(state.update({}).state)).toMatchObject({ kind: "ghost", from: 6, to: 12 });
250+
expect(actionsFor(state, ghost)).toEqual([
251+
{ kind: "remove", label: "Remove it" },
252+
{ kind: "revive", label: "Revive it" },
253+
]);
254+
expect(popoverContent(state, ghost)).toMatchObject({ title: "Ghosted", hint: "⌥↩ removes it · esc closes" });
255+
const removed = state.update(runAction(state, ghost, actionsFor(state, ghost)[0])!).state;
256+
expect(pageMarkdown(removed, "")).toBe("It is done.\n");
257+
const revived = state.update(runAction(state, ghost, actionsFor(state, ghost)[1])!).state;
258+
expect(pageMarkdown(revived, "")).toBe("It is really done.\n");
259+
});
260+
261+
it("open on a ghost you click while Review is open, and remove it with ⌥↩", () => {
262+
// "really" at 6–12 is ghosted, so it isn't marked.
263+
const state = click(stateFor("It is {-really-} done.\n"), 8);
264+
expect(shown(state)).toEqual(["ghost", "really"]);
265+
expect(openPopover(caret(stateFor("It is {-really-} done.\n", false), 8))).toBeNull();
266+
expect(state.update(firstAction(state)!.spec!).state.doc.toString()).toBe("It is done.");
267+
// ⌥↩ works with the caret in a ghost, with no popover open.
268+
const unopened = caret(stateFor("It is {-really-} done.\n"), 8);
269+
expect(unopened.update(firstAction(unopened)!.spec!).state.doc.toString()).toBe("It is done.");
270+
});
271+
272+
it("offer to remove what Claude says to cut", () => {
273+
// The second "It works." at 10–19.
274+
const issue: WritingIssue = { from: 10, to: 19, kind: "grammar", note: "Said twice.", fix: "" };
275+
const state = stateFor("It works. It works.\n").update(setWritingIssues([issue])).state;
276+
expect(actionsFor(state, issue)).toEqual([{ kind: "remove", label: "Remove it" }]);
277+
expect(state.update(runAction(state, issue, actionsFor(state, issue)[0])!).state.doc.toString()).toBe("It works.");
278+
});
279+
232280
it("ghost a word you might cut", () => {
233281
// "really" at 6–12 is an intensifier and an adverb; the popover shows the first.
234282
let state = stateFor("It is really done.\n");
235283
const issue = popoverAt(click(state, 8))!;
236284
expect(issue).toMatchObject({ kind: "intensifier", from: 6, to: 12 });
237-
expect(actionsFor(state, issue)).toEqual([{ kind: "ghost", label: "Ghost it" }]);
285+
expect(actionsFor(state, issue)[0]).toEqual({ kind: "ghost", label: "Ghost it" });
238286
state = state.update(runAction(state, issue, actionsFor(state, issue)[0])!).state;
239287
expect(state.doc.toString()).toBe("It is really done.");
240288
expect(pageMarkdown(state, "")).toBe("It is {-really-} done.\n");
@@ -287,9 +335,10 @@ describe("popover actions", () => {
287335
expect(why("**She left. The door was closed.**\n", 23)).toEqual(["passive", 0, "It cuts through bold or italic text."]);
288336
expect(why("She {{walked slowly|ran}} home.\n", 6)).toEqual(["weakVerb", 0, "It's an alternative already. ⌥J and ⌥K switch its versions."]);
289337
expect(why("She {{walked|ran}} slowly home.\n", 6)).toEqual(["weakVerb", 0, "Part of it already has alternatives."]);
338+
// "Remove it" still fits there; ghosting doesn't, and the reason says why.
290339
expect(why("{{It is really done.|It is done.}}\n", 8)).toEqual([
291340
"intensifier",
292-
0,
341+
1,
293342
"It's inside an alternative, where a ghost isn't saved. Select the whole alternative and press ⌘/.",
294343
]);
295344
expect(why("She walked slowly home.\n", 6)).toEqual(["weakVerb", 1, null]);
@@ -311,7 +360,7 @@ describe("popover actions", () => {
311360
it("ghost a word that is a whole alternative, which saves", () => {
312361
let state = stateFor("It is {{really|truly}} done.\n");
313362
const issue = popoverAt(click(state, 8))!;
314-
expect(actionsFor(state, issue)).toEqual([{ kind: "ghost", label: "Ghost it" }]);
363+
expect(actionsFor(state, issue).map((a) => a.kind)).toEqual(["ghost", "remove"]);
315364
state = state.update(runAction(state, issue, actionsFor(state, issue)[0])!).state;
316365
const saved = pageMarkdown(state, "");
317366
expect(saved).toBe("It is {-{{really|truly}}-} done.\n");

0 commit comments

Comments
 (0)