Bug 1463674 - Allow sourceeditor consumer to have <kbd>Tab</kbd> handling; r=bgrins. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 05 Jul 2018 16:15:35 +0200
changeset 818818 4d57be89965691948609c9037ef60d8850cea8af
parent 818682 2ed1506d1dc7db3d70a3feed95f1456bce05bbee
child 818819 aa728e3ee3254e2ef7eb1768e3f8621decca0535
push id116354
push userbmo:nchevobbe@mozilla.com
push dateMon, 16 Jul 2018 16:01:04 +0000
reviewersbgrins
bugs1463674
milestone63.0a1
Bug 1463674 - Allow sourceeditor consumer to have <kbd>Tab</kbd> handling; r=bgrins. Since the source editor already defines its own extraKeys.Tab, anything the consumer set was ignored. This patch now also runs consumer extraKeys.Tab if defined. MozReview-Commit-ID: 5FeMXoystAb
devtools/client/sourceeditor/editor.js
--- a/devtools/client/sourceeditor/editor.js
+++ b/devtools/client/sourceeditor/editor.js
@@ -174,16 +174,26 @@ function Editor(config) {
   // Remember the initial value of autoCloseBrackets.
   this.config.autoCloseBracketsSaved = this.config.autoCloseBrackets;
 
   // Overwrite default tab behavior. If something is selected,
   // indent those lines. If nothing is selected and we're
   // indenting with tabs, insert one tab. Otherwise insert N
   // whitespaces where N == indentUnit option.
   this.config.extraKeys.Tab = cm => {
+    if (config.extraKeys && config.extraKeys.Tab) {
+      // If a consumer registers its own extraKeys.Tab, we execute it before doing
+      // anything else. If it returns false, that mean that all the key handling work is
+      // done, so we can do an early return.
+      const res = config.extraKeys.Tab(cm);
+      if (res === false) {
+        return;
+      }
+    }
+
     if (cm.somethingSelected()) {
       cm.indentSelection("add");
       return;
     }
 
     if (this.config.indentWithTabs) {
       cm.replaceSelection("\t", "end", "+input");
       return;