SearchAndReplace problem
Submitted by Wednesday, 15 March, 2006 - 18:57
on
I am writing a Macro that enables a simple kind of Wiki link in any text file. Basically if I run my macro, it finds the nearest words in [brackets] and uses that as a file name to open. It works well, but I added the feature to jump to an anchor [filename#anchor] and I cannot figure out how to get it to jump to text in a document. Here is what I have:
newbuffer=jEdit.openFile( view, WikiWord);
if (hasAnchor) {
SearchAndReplace.setSearchString(anchor);
SearchAndReplace.find( view, newbuffer, 0, true, false);
}
It behaves very erratically. It always opens the new file ok. But then it sometimes finds the anchor text, but usually does not. I've tried resetting the cursor to the top of the file to make sure it isn't past the anchor text:
view.getTextArea.setCaretPosition(0);
But that didn't help.
Strangely, if I add this:
Macros.message(view, "finding " + anchor);
before the find, it works! I suspect the popup window causes the interface to 'refresh' in some way bringing the newly opened file to some displayed state, as opposed to some open-but-not-yet-displayed-state... but I'm just guessing here...
Any help?
newbuffer=jEdit.openFile( view, WikiWord);
if (hasAnchor) {
SearchAndReplace.setSearchString(anchor);
SearchAndReplace.find( view, newbuffer, 0, true, false);
}
It behaves very erratically. It always opens the new file ok. But then it sometimes finds the anchor text, but usually does not. I've tried resetting the cursor to the top of the file to make sure it isn't past the anchor text:
view.getTextArea.setCaretPosition(0);
But that didn't help.
Strangely, if I add this:
Macros.message(view, "finding " + anchor);
before the find, it works! I suspect the popup window causes the interface to 'refresh' in some way bringing the newly opened file to some displayed state, as opposed to some open-but-not-yet-displayed-state... but I'm just guessing here...
Any help?