TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
8.09k stars 1.19k forks source link

Add support for search and replace #3288

Open Jermolene opened 6 years ago

Jermolene commented 6 years ago

The core should directly support search and replace. Desirable features include:

A significant part of the user interface functionality is implemented now that we have the diffing engine. It's also worth noting that a lot of the existing importing mechanism can actually be reused. For example:

  1. Navigate to https://tiddlywiki.com/#%24%3A%2FSearchAndReplace
  2. Open the browser JavaScript console and execute the following snippet:
$tw.wiki.addTiddler({title: "$:/SearchAndReplace", "plugin-type": "import",status: "pending",type: "application/json",text: JSON.stringify({tiddlers:{HelloThere:{title:"HelloThere",text:"Have you never had the feeling that your head is not big enough to hold everything you remember"}}})})
  1. In the $:/SearchAndReplace tiddler, click the disclosure triangle to reveal the preview of the incoming tiddler, and switch the preview type to "Diff"

The result is pretty much what we need for the second part of the search and replace UI: a way for the user to review the proposed changes and to accept or reject them individually. The text still talks of "importing", of course.

screenshot 2018-05-16 18 34 53
pmario commented 6 years ago

That's an insteresting approach.

BurningTreeC commented 6 years ago

That's really cool :+1:

TiddlyTweeter commented 6 years ago

The core should directly support search and replace. Desirable features include:

  • The ability for the user to review the changes as diffs, and individually accept r reject them
  • The ability to restrict the search and replace operation to a specific field, or across all fields

In total agreement. Clearly for something so radical review is necessary before accepting the replace. But the scope covering potentially all fields on all Tiddlers would be very useful. At the moment I use external tools to do it. I would rather not because they lack the intelligent context that TW itself would give more appropriately.

bimlas commented 6 years ago

This would be useful for tiddler renaming - though new users might think it's too techie, but in any case it's better than not having the option to update backlinks. However, in the case of renaming, the text and the fields must also be seen, so in this case the two views should be combined.

I could imagine the apply of replace as clicking on the hunk in diff (red / green text).

As I see, $:/core/modules/widgets/diff-text.js is responsible for comparison (if someone wants to do it, do not have to look for it).

twMat commented 5 years ago

Do I understand right that this is intended for a "stand-alone tool" to post edit tids as opposed to a more integral function for string manipulations? Compare e.g with #3803 which requests a filter operator.

Jermolene commented 5 years ago

Hi @twMat this ticket describes a way to implement some of the UI of a user-facing search and replace feature. #3803 is about the underlying filter operator that performs the search and replace.

Do I understand right that this is intended for a "stand-alone tool" to post edit tids as opposed to a more integral function for string manipulations?

I'm not sure I understand what either of those means. Are you drawing a distinction between search and replace in edit mode for just the current tiddler?

twMat commented 5 years ago

I'm not sure I understand what either of those means. Are you drawing a distinction between search and replace in edit mode for just the current tiddler?

An example of what I mean with a "stand-alone tool" is the preview button; a special tool with a full UI. Contrast this to "integral function for string manipulations" which would typically be filter operators or perhaps widgets. My hesitation to say "filter operators" is because I am unsure how suitable the current implementation of filters are for manipulating strings in full texts because of how filters treats everything as lists. So maybe it Maybe this is a non-issue and I just fail to fully grasp it.

So my question is what your OP is to be used for. Is the intention only as a "stand alone tool" (like the preview tool) or some more general mechanism for hacking in wikitext, like a filter op or a widget?

AnthonyMuscio commented 5 years ago

If search and replace was available for a tiddler name within at a minimum, list fields including custom lists fields, which is already possible with a smart wikitext macro. Designers could then use a combination of renamable tags and and list fields to avoid the impact of a tiddler rename.

The above would go a long way.

All that remains then is the renamed tiddler appearing in the body or text of a tiddler.

I have long believed if we could iterate each line in the text field as if it were a field we could then apply a transformation like rename a detected tiddler title and then append that line to a new temporary tiddler. In the end replace the source tiddlers text field with that of the temporary tiddler.

This would open other features like a log tiddler which you progressively append lines to. Enable the ability to sort lines in a tiddler, or insert lines in a tiddler.

Of note, since such renames could be time consuming on renaming a tiddler the provision of a hack so people can write macros that are available at rename time would help, but providing a "Search" for the old tiddlers names in the wiki, and an optional checkable list of replacements would move this to an interactive process and not result in any surprises in processing time when they choose to have all mentions of the old tiddler updated.