From 784fd7b97a11a9b418eaf79f590018960a7d0866 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 19 Feb 2017 19:01:52 +0400 Subject: [PATCH] add more tab commands to emacs mode --- node_modules/ace/lib/ace/keyboard/emacs.js | 4 +- plugins/c9.ide.ace.keymaps/emacs/keymap.js | 21 +++++++- plugins/c9.ide.ace.keymaps/keymaps.js | 5 +- plugins/c9.ide.behaviors/tabs.js | 56 ++++++++++------------ 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/node_modules/ace/lib/ace/keyboard/emacs.js b/node_modules/ace/lib/ace/keyboard/emacs.js index f3f4ed63..841706e7 100644 --- a/node_modules/ace/lib/ace/keyboard/emacs.js +++ b/node_modules/ace/lib/ace/keyboard/emacs.js @@ -406,8 +406,8 @@ exports.emacsKeys = { "Return|C-m": {command: "insertstring", args: "\n"}, // "newline" "C-o": "splitline", - "M-d|C-Delete": {command: "killWord", args: "right"}, - "C-Backspace|M-Backspace|M-Delete": {command: "killWord", args: "left"}, + "M-d|C-Delete|Esc d": {command: "killWord", args: "right"}, + "C-Backspace|M-Backspace|M-Delete|Esc Backspace": {command: "killWord", args: "left"}, "C-k": "killLine", "C-y|S-Delete": "yank", diff --git a/plugins/c9.ide.ace.keymaps/emacs/keymap.js b/plugins/c9.ide.ace.keymaps/emacs/keymap.js index ee64da2b..09935bc0 100644 --- a/plugins/c9.ide.ace.keymaps/emacs/keymap.js +++ b/plugins/c9.ide.ace.keymaps/emacs/keymap.js @@ -6,7 +6,22 @@ exports.aceKeyboardHandler = require("ace/keyboard/emacs").handler; var keys = [{ bindKey: "C-x C-f", + name: "newfile" +}, { + bindKey: "C-x d", name: "navigate" +}, { + bindKey: "C-x Left", + name: "nexttab", + exec: function() { + exports.tabbehavior.nexttab(1, true); + } +}, { + bindKey: "C-x Right", + name: "previoustab", + exec: function() { + exports.tabbehavior.nexttab(-1, true); + } }, { bindKey: "C-x C-s", name: "save" @@ -16,16 +31,20 @@ var keys = [{ }, { bindKey: "C-x C-w", name: "saveas" +}, { + bindKey: "C-x k", + name: "closetab" }]; keys.forEach(function(item) { exports.aceKeyboardHandler.bindKey(item.bindKey, { name: item.name, - exec: ideCommand + exec: item.exec || item.ideCommand }); }); // todo find a way to integrate ide commands with vim and emacs modes exports.execIdeCommand = null; +exports.tabbehavior = null; function ideCommand() { exports.execIdeCommand(this.name); } diff --git a/plugins/c9.ide.ace.keymaps/keymaps.js b/plugins/c9.ide.ace.keymaps/keymaps.js index fc0330f0..f8f3ca88 100644 --- a/plugins/c9.ide.ace.keymaps/keymaps.js +++ b/plugins/c9.ide.ace.keymaps/keymaps.js @@ -1,7 +1,7 @@ define(function(require, exports, module) { main.consumes = [ "Plugin", "ui", "ace", "menus", "settings", "vim.cli", "tabManager", - "commands", "c9", "tree", "dialog.error" + "commands", "c9", "tree", "dialog.error", "tabbehavior" ]; main.provides = ["keymaps"]; return main; @@ -18,6 +18,7 @@ define(function(require, exports, module) { var c9 = imports.c9; var tree = imports.tree; // TODO: find a way to make dependency on tree optional var showError = imports["dialog.error"].show; + var tabbehavior = imports.tabbehavior; /***** Initialization *****/ @@ -138,6 +139,8 @@ define(function(require, exports, module) { var kb = path ? require(path) : {}; if ("execIdeCommand" in kb) kb.execIdeCommand = commands.exec; + if ("tabbehavior" in kb) + kb.tabbehavior = tabbehavior; if (kb.ideCommands) { kb.ideCommands.forEach(function(x) { diff --git a/plugins/c9.ide.behaviors/tabs.js b/plugins/c9.ide.behaviors/tabs.js index 298ab9ab..066f7d81 100644 --- a/plugins/c9.ide.behaviors/tabs.js +++ b/plugins/c9.ide.behaviors/tabs.js @@ -32,8 +32,6 @@ define(function(require, exports, module) { var mnuContext, mnuEditors, mnuTabs; var menuItems = [], menuClosedItems = []; - var accessedTab = 0; - var paneList = []; var accessedPane = 0; @@ -432,7 +430,7 @@ define(function(require, exports, module) { menus.addItemByPath("View/Layout/Split 1:2", new ui.item({ command: "threeright" - }), 400, mnuContext, plugin); + }), 400, mnuContext, plugin); menus.addItemByPath("View/Layout/Split 2:1", new ui.item({ command: "threeleft" @@ -618,11 +616,9 @@ define(function(require, exports, module) { cycleKeyPressed = false; if (dirtyNextTab) { - accessedTab = 0; - var tab = tabs.focussedTab; var accessList = tab.pane.meta.accessList; - if (accessList[accessedTab] != tab) { + if (accessList[0] != tab) { accessList.remove(tab); accessList.unshift(tab); accessList.changed = true; @@ -643,7 +639,7 @@ define(function(require, exports, module) { settings.save(); } - dirtyNextTab = false; + dirtyNextPane = false; } } }); @@ -825,40 +821,36 @@ define(function(require, exports, module) { closeallbutme(tab, pages.slice(0, currIdx)); } - function nexttab() { + function nexttab(dir, keepOrder) { if (tabs.getTabs().length === 1) return; var tab = tabs.focussedTab; var accessList = tab.pane.meta.accessList; - if (++accessedTab >= accessList.length) - accessedTab = 0; - - var next = accessList[accessedTab]; + var index = accessList.indexOf(tab); + index += dir || 1; + + if (index >= accessList.length) + index = 0; + else if (index < 0) + index = accessList.length - 1; + + var next = accessList[index]; if (typeof next != "object" || !next.pane.visible) - return nexttab(); - tabs.focusTab(next, null, true); - - dirtyNextTab = true; + return nexttab(dir, keepOrder); + if (keepOrder && cycleKeyPressed == false) { + cycleKeyPressed = true; + tabs.focusTab(next, null, true); + cycleKeyPressed = false; + } else { + tabs.focusTab(next, null, true); + } + dirtyNextTab = !keepOrder; } - function previoustab() { - if (tabs.getTabs().length === 1) - return; - - var tab = tabs.focussedTab; - var accessList = tab.pane.meta.accessList; - - if (--accessedTab < 0) - accessedTab = accessList.length - 1; - - var next = accessList[accessedTab]; - if (typeof next != "object" || !next.pane.visible) - return previoustab(); - tabs.focusTab(next, null, true); - - dirtyNextTab = true; + function previoustab(dir, keepOrder) { + nexttab(dir || -1, keepOrder) } function nextpane() {