1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 02:19:55 +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,23 +69,35 @@ LinkCatcherWidget.prototype.refresh = function(changedTiddlers) {
Handle a tm-navigate event
*/
LinkCatcherWidget.prototype.handleNavigateEvent = function(event) {
if(this.catchTo) {
this.wiki.setTextReference(this.catchTo,event.navigateTo,this.getVariable("currentTiddler"));
}
if(this.catchMessage && this.parentWidget) {
if(!this.executingActions) {
// Execute the actions
if(this.catchTo) {
this.wiki.setTextReference(this.catchTo,event.navigateTo,this.getVariable("currentTiddler"));
}
if(this.catchMessage && this.parentWidget) {
this.parentWidget.dispatchEvent({
type: this.catchMessage,
param: event.navigateTo,
navigateTo: event.navigateTo
});
}
if(this.catchSet) {
var tiddler = this.wiki.getTiddler(this.catchSet);
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: this.catchMessage,
type: "tm-navigate",
param: event.navigateTo,
navigateTo: event.navigateTo
});
}
if(this.catchSet) {
var tiddler = this.wiki.getTiddler(this.catchSet);
this.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: this.catchSet, text: this.catchSetTo}));
}
if(this.catchActions) {
this.invokeActionString(this.catchActions,this,event,{navigateTo: event.navigateTo});
}
return false;
};