From e354a4af94c2e212ea6bb71344357cf71330cb0e Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 6 May 2018 13:17:39 +0300 Subject: [PATCH] add indent-fold.js for stylus preprocessor --- edit.html | 1 + install-usercss.html | 1 + vendor/codemirror/addon/fold/indent-fold.js | 48 +++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 vendor/codemirror/addon/fold/indent-fold.js diff --git a/edit.html b/edit.html index 2995dec8..1c940d97 100644 --- a/edit.html +++ b/edit.html @@ -61,6 +61,7 @@ + diff --git a/install-usercss.html b/install-usercss.html index d64a98c4..759c6231 100644 --- a/install-usercss.html +++ b/install-usercss.html @@ -34,6 +34,7 @@ + diff --git a/vendor/codemirror/addon/fold/indent-fold.js b/vendor/codemirror/addon/fold/indent-fold.js new file mode 100644 index 00000000..f93edec2 --- /dev/null +++ b/vendor/codemirror/addon/fold/indent-fold.js @@ -0,0 +1,48 @@ +// CodeMirror, copyright (c) by Marijn Haverbeke and others +// Distributed under an MIT license: http://codemirror.net/LICENSE + +(function(mod) { + if (typeof exports == "object" && typeof module == "object") // CommonJS + mod(require("../../lib/codemirror")); + else if (typeof define == "function" && define.amd) // AMD + define(["../../lib/codemirror"], mod); + else // Plain browser env + mod(CodeMirror); +})(function(CodeMirror) { +"use strict"; + +function lineIndent(cm, lineNo) { + var text = cm.getLine(lineNo) + var spaceTo = text.search(/\S/) + if (spaceTo == -1 || /\bcomment\b/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, spaceTo + 1)))) + return -1 + return CodeMirror.countColumn(text, null, cm.getOption("tabSize")) +} + +CodeMirror.registerHelper("fold", "indent", function(cm, start) { + var myIndent = lineIndent(cm, start.line) + if (myIndent < 0) return + var lastLineInFold = null + + // Go through lines until we find a line that definitely doesn't belong in + // the block we're folding, or to the end. + for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) { + var indent = lineIndent(cm, i) + if (indent == -1) { + } else if (indent > myIndent) { + // Lines with a greater indent are considered part of the block. + lastLineInFold = i; + } else { + // If this line has non-space, non-comment content, and is + // indented less or equal to the start line, it is the start of + // another block. + break; + } + } + if (lastLineInFold) return { + from: CodeMirror.Pos(start.line, cm.getLine(start.line).length), + to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length) + }; +}); + +});