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 Sep 6, 2016
1 parent a987a78 commit 54a2f30
Show file tree
Hide file tree
Showing 2 changed files with 20 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,9 +8,10 @@ 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 focus_pane_selector = '#main-pane'
// While manual is false, always highlight the first item
var manual = false;

Expand Down Expand Up @@ -184,6 +185,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 @@ -253,6 +256,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
14 changes: 11 additions & 3 deletions ide/static/ide/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CloudPebble.Sidebar = (function() {
if (list_entry) {
list_entry.removeClass('active');
}

suspended_panes[pane_id] = pane;
pane.detach();
// Create a new empty one.
Expand All @@ -38,7 +39,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 @@ -57,7 +61,7 @@ CloudPebble.Sidebar = (function() {
pane.data('pane-restore-function')();
}

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

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

var set_main_pane = function(pane, options) {
$('#main-pane').append(pane).data('pane-id', options.id);
refocus_pane(pane);
refocus_pane($('#main-pane'));
if (options.onRestore) {
$('#main-pane').data('pane-restore-function', options.onRestore);
}
Expand Down Expand Up @@ -176,6 +180,10 @@ CloudPebble.Sidebar = (function() {
$('#sidebar-pane-github > a').click(CloudPebble.GitHub.Show);
$('#sidebar-pane-timeline > a').click(CloudPebble.Timeline.show);
create_initial_sections(CloudPebble.ProjectInfo.type);

$('#pane-parent').on('focusin', '#main-pane *', _.debounce(function(e) {
$('#main-pane').data('previous-focus', $(e.target));
}, 1));
},
SetPopover: function(pane_id, title, content) {
$('#sidebar-pane-' + pane_id).find('a').popover('destroy').popover({
Expand Down

0 comments on commit 54a2f30

Please sign in to comment.