adding transformations (capitalization, mark add/remove) on the replaced text #2

Closed
opened 2024-06-14 17:34:00 +02:00 by massifrg · 1 comment
massifrg commented 2024-06-14 17:34:00 +02:00 (Migrated from github.com)

This is a feature request.

In my editor I already implemented a search/replace, but now I'm converging to prosemirror-search, because it's better code and it's better working on a common ground.

In my implementation, I added the possibility to modify the replaced text in these ways:

  • changing the capitalization (lower and upper case, upper case the first letter of every word)

  • adding or removing one or more Mark

The replaceCommand() could have a third optional argument, or an options object, specifying a list of changes (see ReplacedChange below) to be done to the replaced text.

Something like this:

type ReplacedChangeType = "capitalize" | "add-mark" | "remove-mark"

interface ReplacedChange {
  type: ReplacedChangeType,
}

interface ReplacedCapitalize extends ReplacedChange {
  type: "capitalize";
  capitalize: "lower" | "upper" | "upper-first";
}

interface ReplacedAddMark extends ReplacedChange {
  type: "add-mark";
  markType: MarkType;
  attrs: Attrs;
}

interface ReplacedRemoveMark extends ReplacedChange {
  type: "remove-mark";
  mark: Mark |MarkType;
}

Just tell me if it makes sense, and I'll make a PR.

This is a feature request. In my editor I already implemented a search/replace, but now I'm converging to prosemirror-search, because it's better code and it's better working on a common ground. In my implementation, I added the possibility to modify the replaced text in these ways: - changing the capitalization (lower and upper case, upper case the first letter of every word) - adding or removing one or more `Mark` The [replaceCommand()](https://github.com/ProseMirror/prosemirror-search/blob/e27d19fdb7a4a809a8bb1daf45a179c13358bbd4/src/search.ts#L125) could have a third optional argument, or an `options` object, specifying a list of changes (see `ReplacedChange` below) to be done to the replaced text. Something like this: ```ts type ReplacedChangeType = "capitalize" | "add-mark" | "remove-mark" interface ReplacedChange { type: ReplacedChangeType, } interface ReplacedCapitalize extends ReplacedChange { type: "capitalize"; capitalize: "lower" | "upper" | "upper-first"; } interface ReplacedAddMark extends ReplacedChange { type: "add-mark"; markType: MarkType; attrs: Attrs; } interface ReplacedRemoveMark extends ReplacedChange { type: "remove-mark"; mark: Mark |MarkType; } ``` Just tell me if it makes sense, and I'll make a PR.
marijnh commented 2024-06-15 18:20:30 +02:00 (Migrated from github.com)

This seems too specific for this package. I'd recommend you implement your own custom replace command for it.

This seems too specific for this package. I'd recommend you implement your own custom replace command for it.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-search#2
No description provided.