1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-24 22:33:16 +00:00

Fix linkcatcher recursion problem

Using action-navigate within the “actions” attribute of the linkcatcher
widget would otherwise trigger the navigation handler recursively.
This commit is contained in:
Jermolene 2017-07-10 14:43:43 +01:00
parent 7bca39842f
commit 95ef1c4580

View File

@ -48,6 +48,8 @@ LinkCatcherWidget.prototype.execute = function() {
this.catchActions = this.getAttribute("actions");
// Construct the child widgets
this.makeChildWidgets();
// When executing actions we avoid trapping navigate events, so that we don't trigger ourselves recursively
this.executingActions = false;
};
/*
@ -67,6 +69,8 @@ LinkCatcherWidget.prototype.refresh = function(changedTiddlers) {
Handle a tm-navigate event
*/
LinkCatcherWidget.prototype.handleNavigateEvent = function(event) {
if(!this.executingActions) {
// Execute the actions
if(this.catchTo) {
this.wiki.setTextReference(this.catchTo,event.navigateTo,this.getVariable("currentTiddler"));
}
@ -82,7 +86,17 @@ LinkCatcherWidget.prototype.handleNavigateEvent = function(event) {
this.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: this.catchSet, text: this.catchSetTo}));
}
if(this.catchActions) {
this.executingActions = true;
this.invokeActionString(this.catchActions,this,event,{navigateTo: event.navigateTo});
this.executingActions = false;
}
} else {
// This is a navigate event generated by the actions of this linkcatcher, so we don't trap it again, but just pass it to the parent
this.parentWidget.dispatchEvent({
type: "tm-navigate",
param: event.navigateTo,
navigateTo: event.navigateTo
});
}
return false;
};