Add more tab commands

This commit is contained in:
William Osler 2019-03-04 10:24:18 -08:00
parent 30ad82671b
commit 5116bf6906
3 changed files with 67 additions and 20 deletions

View file

@ -36,26 +36,28 @@ This is the baseline list of commands supported in `ex-mode`.
| Command | Operation | | Command | Operation |
| --------------------------------------- | ---------------------------------- | | --------------------------------------- | ---------------------------------- |
| `q/quit/tabc/tabclose` | Close active tab | | `q/quit/tabc/tabclose` | Close active tab |
| `qall/quitall` | Close all tabs | | `qall/quitall` | Close all tabs |
| `tabe/tabedit/tabnew` | Open new tab | | `tabe/tabedit/tabnew` | Open new tab |
| `e/edit/tabe/tabedit/tabnew <file>` | Edit given file | | `e/edit/tabe/tabedit/tabnew <file>` | Edit given file |
| `tabn/tabnext` | Go to next tab | | `tabn/tabnext` | Go to next tab |
| `tabp/tabprevious` | Go to previous tab | | `tabp/tabprevious` | Go to previous tab |
| `tabo/tabonly` | Close other tabs | | `tabfir/tabfirst/tabr/tabrewind` | Go to the first tab |
| `w/write` | Save active tab | | `tabl/tablast` | Go to the last tab |
| `w/write/saveas <file>` | Save as | | `tabo/tabonly` | Close other tabs |
| `wall/wa` | Save all tabs | | `w/write` | Save active tab |
| `sp/split` | Split window | | `w/write/saveas <file>` | Save as |
| `sp/split <file>` | Open file in split window | | `wall/wa` | Save all tabs |
| `s/substitute` | Substitute regular expression in active line | | `sp/split` | Split window |
| `vsp/vsplit` | Vertical split window | | `sp/split <file>` | Open file in split window |
| `vsp/vsplit <file>` | Open file in vertical split window | | `s/substitute` | Substitute regular expression in active line |
| `delete` | Cut active line | | `vsp/vsplit` | Vertical split window |
| `yank` | Copy active line | | `vsp/vsplit <file>` | Open file in vertical split window |
| `set <options>` | Set options | | `delete` | Cut active line |
| `sort` | Sort all lines in file | | `yank` | Copy active line |
| `sort <line range>` | Sort lines in line range | | `set <options>` | Set options |
| `sort` | Sort all lines in file |
| `sort <line range>` | Sort lines in line range |
See `lib/ex.coffee` for the implementations of these commands. Contributions are very welcome! See `lib/ex.coffee` for the implementations of these commands. Contributions are very welcome!

View file

@ -173,6 +173,23 @@ class Ex
tabp: => @tabprevious() tabp: => @tabprevious()
tabrewind: ->
pane = atom.workspace.getActivePane()
pane.activateItemAtIndex(0)
tabr: => @tabrewind()
tabfirst: => @tabrewind()
tabfir: => @tabrewind()
tablast: ->
pane = atom.workspace.getActivePane()
index = pane.getItems().length - 1
pane.activateItemAtIndex(index)
tabl: => @tablast()
tabonly: -> tabonly: ->
tabBar = atom.workspace.getPanes()[0] tabBar = atom.workspace.getPanes()[0]
tabBarElement = atom.views.getView(tabBar).querySelector(".tab-bar") tabBarElement = atom.views.getView(tabBar).querySelector(".tab-bar")

View file

@ -444,6 +444,34 @@ describe "the commands", ->
submitNormalModeInputText('tabprevious') submitNormalModeInputText('tabprevious')
expect(pane.getActiveItemIndex()).toBe(pane.getItems().length - 1) expect(pane.getActiveItemIndex()).toBe(pane.getItems().length - 1)
describe ":tabfirst", ->
pane = null
beforeEach ->
waitsForPromise ->
pane = atom.workspace.getActivePane()
atom.workspace.open().then -> atom.workspace.open()
.then -> atom.workspace.open()
it "switches to the first tab", ->
pane.activateItemAtIndex(2)
openEx()
submitNormalModeInputText('tabfirst')
expect(pane.getActiveItemIndex()).toBe(0)
describe ":tablast", ->
pane = null
beforeEach ->
waitsForPromise ->
pane = atom.workspace.getActivePane()
atom.workspace.open().then -> atom.workspace.open()
.then -> atom.workspace.open()
it "switches to the last tab", ->
pane.activateItemAtIndex(0)
openEx()
submitNormalModeInputText('tablast')
expect(pane.getActiveItemIndex()).toBe(2)
describe ":wq", -> describe ":wq", ->
beforeEach -> beforeEach ->
spyOn(Ex, 'write').andCallThrough() spyOn(Ex, 'write').andCallThrough()