Skip to content

Commit

Permalink
Panes remember their focus.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Atkins-Turkish committed May 19, 2016
1 parent ac2b8c9 commit 9634809
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 9 additions & 1 deletion ide/static/ide/js/fuzzyprompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ CloudPebble.FuzzyPrompt = (function() {
var selected_id = null;
var default_item;
var selection_was_made;
var focus_pane;
var opened = false;
var prompt_kind = null;
var COMMANDS_ENABLED = true;

var focus_pane_selector = '#main-pane'
// While manual is false, always highlight the first item
var manual = false;

Expand Down Expand Up @@ -171,6 +172,8 @@ CloudPebble.FuzzyPrompt = (function() {
selection_was_made = false;
opened = true;
prompt_kind = kind;
focus_pane = $(focus_pane_selector).get()[0];

// Build up the list of files to search through
var id = 0;
_.each(sources, function(source) {
Expand Down Expand Up @@ -237,6 +240,11 @@ CloudPebble.FuzzyPrompt = (function() {
if (opened) {
opened = false;
prompt.modal('hide');
// If we switched page, never refocus
if (focus_pane != $(focus_pane_selector).get()[0]) {
refocus = false;
}
// Otherwise, if we want to refocus, do so
if (refocus) {
setTimeout(function () {
$(previously_active).focus();
Expand Down
16 changes: 13 additions & 3 deletions ide/static/ide/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ CloudPebble.Sidebar = (function() {
var pane = $('#main-pane');

var suspend_function = pane.data('pane-suspend-function');

if(suspend_function) suspend_function();

var list_entry = $('#sidebar-pane-' + pane_id);
if(list_entry) {
list_entry.removeClass('active');
}

suspended_panes[pane_id] = pane;
pane.detach();
// Create a new empty one.
Expand All @@ -40,7 +42,10 @@ CloudPebble.Sidebar = (function() {
};

var refocus_pane = function(pane) {
pane.find('*[autofocus]').first().focus();
setTimeout(function() {
var previous_focus = pane.data('previous-focus');
(previous_focus || pane.find('*[autofocus]').first().focus()).focus();
}, 50);
};

var restore_suspended_pane = function(id) {
Expand All @@ -59,7 +64,7 @@ CloudPebble.Sidebar = (function() {
pane.data('pane-restore-function')();
}

refocus_pane(pane);
refocus_pane($('#main-pane'));

return true;
}
Expand All @@ -68,7 +73,7 @@ CloudPebble.Sidebar = (function() {

var set_main_pane = function(pane, id, restore_function, destroy_function) {
$('#main-pane').append(pane).data('pane-id', id);
refocus_pane(pane);
refocus_pane($('#main-pane'));
if(restore_function) {
$('#main-pane').data('pane-restore-function', restore_function);
}
Expand Down Expand Up @@ -162,6 +167,11 @@ CloudPebble.Sidebar = (function() {
$('#sidebar-pane-github > a').click(CloudPebble.GitHub.Show);
$('#sidebar-pane-timeline > a').click(CloudPebble.Timeline.show);
$('#new-source-file').click(CloudPebble.Editor.Create);

$('#pane-parent').on('focusin', '#main-pane *', _.debounce(function(e) {
$('#main-pane').data('previous-focus', $(e.target));
}, 1));

init();
},
SetPopover: function(pane_id, title, content) {
Expand Down

0 comments on commit 9634809

Please sign in to comment.