Search-Replace in Tiddler: Show differences before apply

103 views
Skip to first unread message

Mohammad

unread,
Feb 26, 2019, 3:12:54 AM2/26/19
to tiddl...@googlegroups.com
This is an attempt to search and replace in tiddler fields including text field.

Code and Demo


It works great and it shows the differences before you apply the changes

It can distinguish a whole word(s) by using a white-space as delimiter, but the small issue is it only
works in case-sensitive mode!

The ultimate purpose is to integrate this in Tiddler Commander.

I would appreciate if you kindly
  1. Give me your feedback
  2. Give me your solution if any to revise the code to work in case-insensitive mode
This script is co-authored with BTC.


--Mohammad

@TiddlyTweeter

unread,
Feb 26, 2019, 7:06:33 AM2/26/19
to TiddlyWiki
Ciao Mohammad

Great that you get to see what is going on in search and replace! Makes is much more viable to use!

Couple of issues ...

-- Is there anyway that the FIRST or LAST word in a paragraph could be changed with "whole words" switched on?
    At the moment you have to switch off whole words for that to work.

-- Test on repeated SINGLE CHARACTERS can give unexpected results...
    Set: whole words off. Search value="[". Replace value="BRACKET". You get this which shows the issue ...
    The first result is wrong. The second is correct.
 

{3415454F-95C0-4683-826B-BB6E4F893465}.png.jpg

 
Very best wishes
Josiah 

Mohammad wrote:
This is an attempt to search and replace in tiddler text.
  1. Give me your feedback

@TiddlyTweeter

unread,
Feb 26, 2019, 7:17:21 AM2/26/19
to TiddlyWiki
Mohammad wrote:
This is an attempt to search and replace in tiddler text
  1. Give me your solution if any to revise the code to work in case-insensitive mode
I don't have skill to know how to do this. Were you thinking case-insensitive regular expression applied for the initial search value? 

Best wishes
Josiah

Mohammad

unread,
Feb 26, 2019, 9:41:31 AM2/26/19
to TiddlyWiki
Hello Josiah!
 I think it is a bug in split operator. Test this on 

<$vars x="this at at best">
<$list filter="[<x>split[at]]">

</$list>
</$vars>

Split operator cannot distinguish the repeated word!

Hope Jeremy have a look at it!

--Mohammad


Mohammad

unread,
Feb 26, 2019, 9:45:21 AM2/26/19
to tiddl...@googlegroups.com
Josiah,
 Yes, you are right the split is a case-sensitive operator and also can not distinguish punctuation!

So, as expected, it makes a difference between for example these two words: "desk" and "desk."

I think the best way is to add the JS replace function into TW String operation, this makes a much simpler search-replace.

I still stick to Tiddlywiki filters and try to not use Javascript.


--Mohammad

@TiddlyTweeter

unread,
Feb 26, 2019, 2:44:39 PM2/26/19
to tiddl...@googlegroups.com
As far as I can see the "splitter" is fully consumed if there is no string (or only whitespace) between intervening split points.

So string:  "c, d, , ,f " splitting on "," consumes the splits between d and f? In some ways it's understandable to dump null values. But it is  problematic in the current case. And its problematic more generally for arrays where you need to preserve null entries?

Just amateur thoughts
Josiah

Mohammad

unread,
Feb 26, 2019, 2:53:28 PM2/26/19
to TiddlyWiki
Hello Josiah,
 That is correct. I am thinking how I can find another solution to this. I submitted  a request to GitHub asking for addition of replace (e.g searchreplace) 
to the new string operation filter. I am not sure if Jeremy accept this.

--Mohammad

On Tuesday, February 26, 2019 at 11:14:39 PM UTC+3:30, @TiddlyTweeter wrote:
As far as I can see the "splitter" is fully consumed if there is no non-whitespace string between intervening split points.

Mohammad

unread,
Feb 28, 2019, 1:59:16 AM2/28/19
to TiddlyWiki
This thread is closed here!

The search-n-replace (SNR) script has got critical changes and the new code is announced here



--Mohammad
Reply all
Reply to author
Forward
0 new messages