Browse Source

fix indent key mappings

Gerald 7 years ago
parent
commit
bd9a79018b
1 changed files with 4 additions and 12 deletions
  1. 4 12
      src/common/ui/code.vue

+ 4 - 12
src/common/ui/code.vue

@@ -71,17 +71,6 @@ function getHandler(key) {
     return handle && handle();
   };
 }
-function indentWithTab(cm) {
-  if (cm.somethingSelected()) {
-    cm.indentSelection('add');
-  } else {
-    cm.replaceSelection(
-      cm.getOption('indentWithTabs') ? '\t' : ' '.repeat(cm.getOption('indentUnit')),
-      'end',
-      '+input',
-    );
-  }
-}
 
 [
   'save', 'cancel', 'close',
@@ -89,6 +78,10 @@ function indentWithTab(cm) {
 ].forEach(key => {
   CodeMirror.commands[key] = getHandler(key);
 });
+Object.assign(CodeMirror.keyMap.default, {
+  Tab: 'indentMore',
+  'Shift-Tab': 'indentLess',
+});
 
 const cmOptions = {
   continueComments: true,
@@ -268,7 +261,6 @@ export default {
       }, this.commands);
       cm.setOption('extraKeys', {
         Esc: 'cancel',
-        Tab: indentWithTab,
       });
       cm.on('keyHandled', (_cm, _name, e) => {
         e.stopPropagation();