diff --git a/mailnews/base/resources/content/commandglue.js b/mailnews/base/resources/content/commandglue.js index e82bcdbb5533..0b797627cc39 100644 --- a/mailnews/base/resources/content/commandglue.js +++ b/mailnews/base/resources/content/commandglue.js @@ -414,12 +414,66 @@ function FolderTest5000() dump("Time to load is " + timeToLoad + " seconds\n"); } -function SelectNextMessage(messages) +function GetNextMessageAfterDelete(messages) { var count = messages.length; - - var nextMessage = GetNextMessage(messages[0], GoMessage, false) + var curMessage = messages[0]; + var nextMessage = null; + //search forward + while(curMessage) + { + nextMessage = GetNextMessage(curMessage, GoMessage, false); + if(nextMessage) + { + if(!MessageInSelection(nextMessage, messages)) + { + break; + } + } + curMessage = nextMessage; + } + //if no nextmessage then search backwards + if(!nextMessage) + { + + var curMessage = messages[0]; + var nextMessage = null; + //search forward + while(curMessage) + { + nextMessage = GetPreviousMessage(curMessage, GoMessage, false); + if(nextMessage) + { + if(!MessageInSelection(nextMessage, messages)) + { + break; + } + } + curMessage = nextMessage; + } + + + + } + return nextMessage; +} + +function MessageInSelection(message, messages) +{ + var count = messages.length; + + for(var i = 0; i < count; i++) + { + if(message == messages[i]) + return true; + + } + return false; +} + +function SelectNextMessage(nextMessage) +{ var tree = GetThreadTree(); ChangeSelection(tree, nextMessage); diff --git a/mailnews/base/resources/content/msgViewNavigation.js b/mailnews/base/resources/content/msgViewNavigation.js index 1bfe2556e365..ff646c98d556 100644 --- a/mailnews/base/resources/content/msgViewNavigation.js +++ b/mailnews/base/resources/content/msgViewNavigation.js @@ -52,11 +52,7 @@ function GoNextMessage(nextFunction, startFromBeginning) if ( selArray && (selArray.length == 1) ) { var nextMessage = GetNextMessage(selArray[0], nextFunction, startFromBeginning); - if(nextMessage) - { - tree.clearItemSelection(); - tree.selectItem(nextMessage); - } + ChangeSelection(tree, nextMessage); } } @@ -111,11 +107,7 @@ function GoPreviousMessage(previousFunction, startFromEnd) if ( selArray && (selArray.length == 1) ) { var previousMessage = GetPreviousMessage(selArray[0], previousFunction, startFromEnd); - if(previousMessage) - { - tree.clearItemSelection(); - tree.selectItem(previousMessage); - } + ChangeSelection(tree, previousMessage); } } @@ -154,3 +146,11 @@ function GetPreviousMessage(currentMessage, previousFunction, startFromEnd) return previousMessage; } +function ChangeSelection(tree, newMessage) +{ + if(newMessage) + { + tree.clearItemSelection(); + tree.selectItem(newMessage); + } +} diff --git a/mailnews/base/resources/content/widgetglue.js b/mailnews/base/resources/content/widgetglue.js index 73e1ec59fb70..68c986653ad2 100644 --- a/mailnews/base/resources/content/widgetglue.js +++ b/mailnews/base/resources/content/widgetglue.js @@ -82,8 +82,10 @@ function MsgDeleteMessage(fromToolbar) dump("tree is valid\n"); //get the selected elements var messageList = tree.selectedItems; + var nextMessage = GetNextMessageAfterDelete(messageList); //get the current folder messenger.DeleteMessages(tree, srcFolder, messageList); + SelectNextMessage(nextMessage); } }