From 812111e7c4670eef5d90c705c293fe2ae89c599d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pete=20Nyk=C3=A4nen?= Date: Sun, 28 Aug 2016 18:29:41 +0300 Subject: [PATCH] Revert "Ensures fold-gutter is always inserted after the line-number gutter (if it exists)" --- .brackets.json | 1 - .eslintrc.json | 1 - src/extensions/default/CodeFolding/main.js | 85 +++++--------------- src/extensions/default/CodeFolding/main.less | 18 ----- 4 files changed, 18 insertions(+), 87 deletions(-) diff --git a/.brackets.json b/.brackets.json index a80154a32..02e9bc8fa 100644 --- a/.brackets.json +++ b/.brackets.json @@ -20,7 +20,6 @@ "clearTimeout", "ArrayBuffer", - "MutationObserver", "XMLHttpRequest", "Uint32Array", "WebSocket" diff --git a/.eslintrc.json b/.eslintrc.json index 8606e3b78..4e9117a04 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -61,7 +61,6 @@ "clearTimeout": false, "ArrayBuffer": false, - "MutationObserver": false, "XMLHttpRequest": false, "Uint32Array": false, "WebSocket": false diff --git a/src/extensions/default/CodeFolding/main.js b/src/extensions/default/CodeFolding/main.js index e6d346af6..161f5932e 100644 --- a/src/extensions/default/CodeFolding/main.js +++ b/src/extensions/default/CodeFolding/main.js @@ -25,6 +25,7 @@ * @author Patrick Oladimeji * @date 10/24/13 9:35:26 AM */ + define(function (require, exports, module) { "use strict"; @@ -52,12 +53,7 @@ define(function (require, exports, module) { collapseAllKey = "Alt-1", expandAllKey = "Shift-Alt-1", collapseAllKeyMac = "Cmd-1", - expandAllKeyMac = "Cmd-Shift-1", - SAVE_FOLD_STATES = "saveFoldStates", - HIDE_UNTIL_MOUSE_OVER = "hideUntilMouseover", - MAKE_SELECTION_FOLDABLE = "makeSelectionFoldable", - ALWAYS_USE_INDENT_FOLD = "alwaysUseIndentFold", - LINE_NUMBER_GUTTER = "CodeMirror-linenumbers"; + expandAllKeyMac = "Cmd-Shift-1"; ExtensionUtils.loadStyleSheet(module, "main.less"); @@ -74,10 +70,10 @@ define(function (require, exports, module) { indentFold = require("foldhelpers/indentFold"), selectionFold = require("foldhelpers/foldSelected"); + /** Set to true when init() has run; set back to false after deinit() has run */ - var _isInitialized = false, - gutterObservers = {}; - + var _isInitialized = false; + /** * Restores the linefolds in the editor using values fetched from the preference store * Checks the document to ensure that changes have not been made (e.g., in a different editor) @@ -116,7 +112,7 @@ define(function (require, exports, module) { }); } - var saveFolds = prefs.getSetting(SAVE_FOLD_STATES); + var saveFolds = prefs.getSetting("saveFoldStates"); if (!editor || !saveFolds) { return; } @@ -151,7 +147,7 @@ define(function (require, exports, module) { * @param {Editor} editor the editor whose line folds should be saved */ function saveLineFolds(editor) { - var saveFolds = prefs.getSetting(SAVE_FOLD_STATES); + var saveFolds = prefs.getSetting("saveFoldStates"); if (!editor || !saveFolds) { return; } @@ -267,7 +263,6 @@ define(function (require, exports, module) { */ function createGutter(editor) { var cm = editor._codeMirror; - var rootElement = editor.getRootElement(); var path = editor.document.file.fullPath, _lineFolds = prefs.getFolds(path); _lineFolds = _lineFolds || {}; cm._lineFolds = _lineFolds; @@ -275,12 +270,9 @@ define(function (require, exports, module) { // Reuse any existing fold gutter if (gutters.indexOf(GUTTER_NAME) < 0) { - var lineNumberIndex = gutters.indexOf(LINE_NUMBER_GUTTER); - if (lineNumberIndex < 0) { - $(rootElement).addClass("linenumber-disabled"); - } - $(rootElement).addClass("folding-enabled"); - gutters.splice(lineNumberIndex + 1, 0, GUTTER_NAME); + var lnIndex = gutters.indexOf("CodeMirror-linenumbers"); + $(editor.getRootElement()).addClass("folding-enabled"); + gutters.splice(lnIndex + 1, 0, GUTTER_NAME); cm.setOption("gutters", gutters); cm.refresh(); // force recomputing gutter width - .folding-enabled class affects linenumbers gutter which has existing cached width } @@ -288,17 +280,17 @@ define(function (require, exports, module) { $(cm.getGutterElement()).on({ mouseenter: function () { - if (prefs.getSetting(HIDE_UNTIL_MOUSE_OVER)) { + if (prefs.getSetting("hideUntilMouseover")) { foldGutter.updateInViewport(cm); } else { - $(rootElement).addClass("over-gutter"); + $(editor.getRootElement()).addClass("over-gutter"); } }, mouseleave: function () { - if (prefs.getSetting(HIDE_UNTIL_MOUSE_OVER)) { + if (prefs.getSetting("hideUntilMouseover")) { foldGutter.clearGutter(cm); } else { - $(rootElement).removeClass("over-gutter"); + $(editor.getRootElement()).removeClass("over-gutter"); } } }); @@ -312,12 +304,10 @@ define(function (require, exports, module) { var cm = editor._codeMirror; var gutters = cm.getOption("gutters").slice(0); var index = gutters.indexOf(GUTTER_NAME); - var rootElement = editor.getRootElement(); - $(rootElement).removeClass("folding-enabled"); + $(editor.getRootElement()).removeClass("folding-enabled"); gutters.splice(index, 1); cm.setOption("gutters", gutters); - // Force recomputing gutter width - .folding-enabled class affected linenumbers gutter - cm.refresh(); + cm.refresh(); // force recomputing gutter width - .folding-enabled class affected linenumbers gutter CodeMirror.defineOption("foldGutter", false, null); } @@ -326,39 +316,6 @@ define(function (require, exports, module) { if (editor._codeMirror.getOption("gutters").indexOf(GUTTER_NAME) === -1) { createGutter(editor); restoreLineFolds(editor); - // Watch mutations on code mirror gutters and ensure line numbers are added before fold gutter. - var config = {childList: true}; - var gutters, - lineNumberIndex, - foldGutterIndex, - cm = editor._codeMirror, - rootElement = editor.getRootElement(), - guttersContainer = $(".CodeMirror-gutters", rootElement), - observer = new MutationObserver(function (mutations) { - observer.disconnect(); - // Ensure fold-gutter appears after line numbers. - gutters = cm.getOption("gutters").slice(0); - lineNumberIndex = gutters.indexOf(LINE_NUMBER_GUTTER); - foldGutterIndex = gutters.indexOf(GUTTER_NAME); - if (lineNumberIndex > -1 && foldGutterIndex < lineNumberIndex) { - gutters.splice(foldGutterIndex, 1); - lineNumberIndex = gutters.indexOf(LINE_NUMBER_GUTTER); - gutters.splice(lineNumberIndex + 1, 0, GUTTER_NAME); - } - if (lineNumberIndex < 0) { - $(rootElement).addClass("linenumber-disabled"); - } else { - $(rootElement).removeClass("linenumber-disabled"); - } - $(rootElement).addClass("folding-enabled"); - cm.setOption("gutters", gutters); - cm.refresh(); - createGutter(editor); - // Reconnect the observer. - observer.observe(guttersContainer[0], config); - }); - observer.observe(guttersContainer[0], config); - gutterObservers[editor.document.file.fullPath] = observer; } } @@ -414,12 +371,6 @@ define(function (require, exports, module) { Editor.forEveryEditor(function (editor) { CodeMirror.commands.unfoldAll(editor._codeMirror); removeGutter(editor); - //disconnect any mutation observers on the gutter - var gutterObserver = gutterObservers[editor.document.file.fullPath]; - if (gutterObserver) { - gutterObserver.disconnect(); - delete gutterObservers[editor.document.file.fullPath]; - } }); } @@ -436,10 +387,10 @@ define(function (require, exports, module) { // don't, we register helpers explicitly here. We also register a global helper for generic indent-based // folding, which cuts across all languages if enabled via preference. CodeMirror.registerGlobalHelper("fold", "selectionFold", function (mode, cm) { - return prefs.getSetting(MAKE_SELECTION_FOLDABLE); + return prefs.getSetting("makeSelectionsFoldable"); }, selectionFold); CodeMirror.registerGlobalHelper("fold", "indent", function (mode, cm) { - return prefs.getSetting(ALWAYS_USE_INDENT_FOLD); + return prefs.getSetting("alwaysUseIndentFold"); }, indentFold); CodeMirror.registerHelper("fold", "django", CodeMirror.helpers.fold.brace); diff --git a/src/extensions/default/CodeFolding/main.less b/src/extensions/default/CodeFolding/main.less index a31b00751..7e8509380 100644 --- a/src/extensions/default/CodeFolding/main.less +++ b/src/extensions/default/CodeFolding/main.less @@ -49,24 +49,6 @@ padding-right: 5px; } -// If line numbers are not shown and codefolding is enabled we remove the left padding. - // We add the same padding below to the fold gutter - .show-line-padding { - .folding-enabled.linenumber-disabled pre { - padding-left: 0; - } - } - - .CodeMirror.linenumber-disabled { - // When there are no line numbers, .show-line-padding class adds 15px left padding to line numbers. - // Here we compensate for that gap by adding the same padding to the folding gutter. - .CodeMirror-foldgutter, - .CodeMirror-foldgutter-open, - .CodeMirror-foldgutter-folded, - .CodeMirror-foldgutter-blank { - padding-left: 15px; - } - } .CodeMirror-foldmarker { // Re-enabling the pointer events for the fold marker. As pointer events are disabled for "CodeMirror-lines"