<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -20,3 +20,4 @@ stamp-h1
 *.[oa]
 src/gphpedit
 autom4te.cache
+patches</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -801,7 +801,7 @@ void set_active_tab(page_num)
 
 	if (new_current_editor) {
 		//page_num = gtk_notebook_page_num(GTK_NOTEBOOK(main_window.notebook_editor),(new_current_editor-&gt;scintilla));
-		gtk_notebook_set_current_page(GTK_NOTEBOOK(main_window.notebook_editor),page_num);
+		gtk_notebook_set_current_page(GTK_NOTEBOOK(main_window.notebook_editor), page_num);
 	}
 
 	main_window.current_editor = new_current_editor;
@@ -809,11 +809,20 @@ void set_active_tab(page_num)
 	update_app_title();
 }
 
+/**
+ * Close a tab in the Editor. Removes the notebook page, frees the editor object,
+ * and sets the active tab correcty
+ * 
+ * @param editor - The editor object corresponding to the tab that is going to be closed.
+ * @return void
+ * 
+ */
 
 void close_page(Editor *editor)
 {
 	gint page_num;
 	gint page_num_closing;
+	gint current_active_tab;
 
 	if (GTK_IS_SCINTILLA(editor-&gt;scintilla)) {
 		page_num_closing = gtk_notebook_page_num(GTK_NOTEBOOK(main_window.notebook_editor),editor-&gt;scintilla);
@@ -822,16 +831,24 @@ void close_page(Editor *editor)
 	else {
 		page_num_closing = gtk_notebook_page_num(GTK_NOTEBOOK(main_window.notebook_editor),editor-&gt;help_scrolled_window);
 	}
-
-	page_num = page_num_closing-1;
-	if (page_num&lt;0) {
-		page_num=0;
+	current_active_tab = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_window.notebook_editor));
+	
+	if (page_num_closing != current_active_tab) {
+		page_num = current_active_tab;
+	}
+	else {
+	    // If there is a tab before the current one then set it as the active tab.
+		page_num = page_num_closing - 1;
+	    // If the current tab is the 0th tab then set the current tab as 0 itself.
+	    // If there are are subsequent tabs, then this will set the next tab as active.
+		if (page_num &lt; 0) {
+			page_num = 0;
+		}	
 	}
 	set_active_tab(page_num);
-
 	g_string_free(editor-&gt;filename, TRUE);
 	g_free(editor);
-	gtk_notebook_remove_page(GTK_NOTEBOOK(main_window.notebook_editor),page_num_closing);
+	gtk_notebook_remove_page(GTK_NOTEBOOK(main_window.notebook_editor), page_num_closing);
 }
 
 </diff>
      <filename>src/main_window_callbacks.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>13f2ac353a980aa9af89605819588b705550293f</id>
    </parent>
  </parents>
  <author>
    <name>Anoop John</name>
    <email>anoopjohn@zyxware09.z2.zyxware.net</email>
  </author>
  <url>http://github.com/anoopjohn/gphpedit/commit/0070a042f7e44b59f357c93bf88a31d967db8076</url>
  <id>0070a042f7e44b59f357c93bf88a31d967db8076</id>
  <committed-date>2009-11-01T08:43:54-08:00</committed-date>
  <authored-date>2009-11-01T08:43:54-08:00</authored-date>
  <message>Merged with aneeshnl's fix for tab focus on tab close</message>
  <tree>75e7ec844df7e6059ad137ca41f73d388e644c3b</tree>
  <committer>
    <name>Anoop John</name>
    <email>anoopjohn@zyxware09.z2.zyxware.net</email>
  </committer>
</commit>
