Skip to content
This repository

--focusprev option for TabCloseCurrent #24

Merged
merged 4 commits into from over 2 years ago

2 participants

Marcin Kulik Kazunori Kajihiro
Marcin Kulik

It allows closing current tab and focusing the previous one.
Adds "X" key mapping (being twin mapping to "x") with --focusprev option.
It mimics similar functionality from Vrome and Vimperator/Pentadactyl.

sickill added some commits
Marcin Kulik sickill --focusprev option for TabCloseCurrent
It allows closing current tab and focusing the previous one.
Adds "X" key mapping (being twin mapping to "x") with --focusprev option.
fead2a2
Marcin Kulik sickill Switch to tab with index saved before deleting
Sometimes Chrome removes a tab and activates previous one.
This prevents from activating previous-previous tab after removing
current one.
a176b45
Marcin Kulik sickill Improvements for TabCloseCurrent --focusprev
It first activates previous tab and then deletes the old one.
It prevents tab bar "flickering".
c7aa7d6
Kazunori Kajihiro
Owner

Thanks for your request.I think it's a nice option.
one thing I'm concerning about is that currently if this command(TabCloseCurrent --focusprev) is executed when the current tab focus is the leftmost tab(index == 0), the rightmost tab will be focused.
I think tab focus should stay at index 0 in the above situation, which is same as Vimperator.
What do you think?

Marcin Kulik

I wasn't sure how it works in Vimperator in this particular case but it makes sense. I'll make this change today/tomorrow.

Marcin Kulik

Ready, it behaves like in Vimperator now.

Kazunori Kajihiro k2nr merged commit b792b83 into from
Kazunori Kajihiro k2nr closed this
Kazunori Kajihiro
Owner

Merged.
Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Dec 06, 2011
Marcin Kulik sickill --focusprev option for TabCloseCurrent
It allows closing current tab and focusing the previous one.
Adds "X" key mapping (being twin mapping to "x") with --focusprev option.
fead2a2
Dec 07, 2011
Marcin Kulik sickill Switch to tab with index saved before deleting
Sometimes Chrome removes a tab and activates previous one.
This prevents from activating previous-previous tab after removing
current one.
a176b45
Dec 08, 2011
Marcin Kulik sickill Improvements for TabCloseCurrent --focusprev
It first activates previous tab and then deletes the old one.
It prevents tab bar "flickering".
c7aa7d6
Dec 12, 2011
Marcin Kulik sickill Don't switch to last tab if first one was active when closing with --…
…focusprev
b792b83
This page is out of date. Refresh to see the latest.
24 background.js
@@ -7,7 +7,7 @@
7 7
8 8 g.bg = {
9 9 tabHistory: null,
10   - moveTab: function(offset, start) {
  10 + moveTab: function(offset, start, callback) {
11 11 return chrome.tabs.getAllInWindow(null, function(tabs) {
12 12 var nTabs;
13 13 nTabs = tabs.length;
@@ -25,7 +25,7 @@
25 25 }
26 26 return chrome.tabs.update(tabs[idx].id, {
27 27 selected: true
28   - });
  28 + }, callback);
29 29 });
30 30 });
31 31 },
@@ -178,9 +178,25 @@
178 178 }
179 179 return false;
180 180 },
181   - reqTabCloseCurrent: function() {
  181 + reqTabCloseCurrent: function(req) {
  182 + var arg, prev, _i, _len, _ref2;
  183 + var _this = this;
  184 + _ref2 = req.args;
  185 + for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
  186 + arg = _ref2[_i];
  187 + switch (arg) {
  188 + case "--focusprev":
  189 + prev = true;
  190 + }
  191 + }
182 192 chrome.tabs.getSelected(null, function(tab) {
183   - return chrome.tabs.remove(tab.id);
  193 + if (prev && tab.index > 0) {
  194 + return _this.moveTab(-1, tab.index, function() {
  195 + return chrome.tabs.remove(tab.id);
  196 + });
  197 + } else {
  198 + return chrome.tabs.remove(tab.id);
  199 + }
184 200 });
185 201 return false;
186 202 },
16 coffee/background.coffee
@@ -3,7 +3,7 @@ g = this.vichrome
3 3
4 4 g.bg =
5 5 tabHistory : null
6   - moveTab : (offset, start) ->
  6 + moveTab : (offset, start, callback) ->
7 7 chrome.tabs.getAllInWindow( null, (tabs) ->
8 8 nTabs = tabs.length
9 9 chrome.tabs.getSelected(null, (tab) ->
@@ -17,7 +17,7 @@ g.bg =
17 17 else if idx >= nTabs
18 18 idx = idx % nTabs
19 19
20   - chrome.tabs.update( tabs[idx].id, selected:true )
  20 + chrome.tabs.update( tabs[idx].id, selected: true, callback )
21 21 )
22 22 )
23 23
@@ -116,8 +116,16 @@ g.bg =
116 116 chrome.windows.create( url : urls, focused : focus )
117 117 false
118 118
119   - reqTabCloseCurrent : ->
120   - chrome.tabs.getSelected(null, (tab) -> chrome.tabs.remove(tab.id) )
  119 + reqTabCloseCurrent : (req) ->
  120 + for arg in req.args then switch arg
  121 + when "--focusprev" then prev = true
  122 +
  123 + chrome.tabs.getSelected(null, (tab) =>
  124 + if prev and tab.index > 0
  125 + @moveTab(-1, tab.index, -> chrome.tabs.remove(tab.id))
  126 + else
  127 + chrome.tabs.remove(tab.id)
  128 + )
121 129 false
122 130
123 131 reqTabCloseAll : (req) ->
1  coffee/settings.coffee
@@ -84,6 +84,7 @@ pagecmd *.pdf nmap <C-f> <NOP>\n
84 84 "G" : "GoBottom"
85 85 "t" : "TabOpenNew"
86 86 "x" : "TabCloseCurrent"
  87 + "X" : "TabCloseCurrent --focusprev"
87 88 "n" : "NextSearch"
88 89 "N" : "PrevSearch"
89 90 "gt" : "TabFocusNext"
1  settings.js
@@ -47,6 +47,7 @@
47 47 "G": "GoBottom",
48 48 "t": "TabOpenNew",
49 49 "x": "TabCloseCurrent",
  50 + "X": "TabCloseCurrent --focusprev",
50 51 "n": "NextSearch",
51 52 "N": "PrevSearch",
52 53 "gt": "TabFocusNext",

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.