1
0
mirror of https://github.com/adobe/brackets.git synced 2024-11-20 01:42:55 +01:00

Revert "Ensures fold-gutter is always inserted after the line-number gutter (if it exists)"

This commit is contained in:
Pete Nykänen 2016-08-28 18:29:41 +03:00 committed by GitHub
parent 57278636e2
commit 812111e7c4
4 changed files with 18 additions and 87 deletions

View File

@ -20,7 +20,6 @@
"clearTimeout",
"ArrayBuffer",
"MutationObserver",
"XMLHttpRequest",
"Uint32Array",
"WebSocket"

View File

@ -61,7 +61,6 @@
"clearTimeout": false,
"ArrayBuffer": false,
"MutationObserver": false,
"XMLHttpRequest": false,
"Uint32Array": false,
"WebSocket": false

View File

@ -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,9 +70,9 @@ 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
@ -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);

View File

@ -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"