1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-08-24 02:26:45 +00:00

Make "close tiddler" button in STM go back to the previous tiddler in the history stack

This commit is contained in:
Jermolene 2018-08-27 18:12:54 +01:00
parent 81fda40486
commit 0d40b691e7

View File

@ -127,6 +127,12 @@ NavigatorWidget.prototype.addToStory = function(title,fromTitle) {
}); });
}; };
NavigatorWidget.prototype.removeFromStory = function(title) {
var storyList = this.getStoryList();
this.removeTitleFromStory(storyList,title);
this.saveStoryList(storyList);
};
/* /*
Add a new record to the top of the history stack Add a new record to the top of the history stack
title: a title string or an array of title strings title: a title string or an array of title strings
@ -152,11 +158,34 @@ NavigatorWidget.prototype.handleNavigateEvent = function(event) {
// Close a specified tiddler // Close a specified tiddler
NavigatorWidget.prototype.handleCloseTiddlerEvent = function(event) { NavigatorWidget.prototype.handleCloseTiddlerEvent = function(event) {
var title = event.param || event.tiddlerTitle, var title = event.param || event.tiddlerTitle;
storyList = this.getStoryList(); if(this.singleTiddlerMode) {
// Look for tiddlers with this title to close // Get the history stack and find the topmost occurance of the current tiddler
this.removeTitleFromStory(storyList,title); var history = this.wiki.getTiddlerDataCached(this.historyTitle,[]),
this.saveStoryList(storyList); currPos = history.findIndex(function(historyRecord) {
return historyRecord.title === title;
}),
newTitle;
// Skip over any duplicates
while(currPos > 0 && history[currPos - 1].title === title) {
currPos--;
}
// Get the new title
if(currPos > 0) {
newTitle = history[currPos - 1].title;
}
// Navigate to the new title if we've got one
if(newTitle) {
this.addToStory(newTitle);
this.addToHistory(newTitle);
} else {
// If there's nothing to navigate back to then we really do close the last tiddler
this.removeFromStory(title);
}
} else {
// Look for tiddlers with this title to close
this.removeFromStory(title);
}
return false; return false;
}; };