This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
executable file
·67 lines (59 loc) · 2.25 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
define(function (require, exports, module) {
"use strict";
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
AppInit = brackets.getModule("utils/AppInit"),
EditorManager = brackets.getModule("editor/EditorManager"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager");
ExtensionUtils.loadStyleSheet(module, "main.css");
var DEFAULT_GUTTER_WIDTH = 15;
function indentSoftWraps(editor) {
if (!editor) return;
editor._codeMirror.on("renderLine", function (cm, line, elt) {
var firstNonSpace = line.text.search(/\S/);
if (firstNonSpace > -1) {
var whitespace = line.text.substr(0, firstNonSpace),
offset = countSpaces(whitespace, cm.getOption("tabSize")) * cm.defaultCharWidth(),
eltPadLeft = parseInt(window.getComputedStyle(elt).paddingLeft, 10) || 0, // This does not work
noGutter = !PreferencesManager.get("showLineNumbers");
elt.style.textIndent = -(offset + eltPadLeft) + "px";
elt.style.paddingLeft = (noGutter ? DEFAULT_GUTTER_WIDTH : 0) + offset + eltPadLeft + "px";
}
addClass(elt, "softwraps-indented");
});
editor.refresh();
}
function countSpaces(ws, tabSize) {
var fullTabs = 0, remainderSpaces = 0;
for (var i = 0; i < ws.length; i++) {
if (ws[i] === "\t") {
fullTabs++;
remainderSpaces = 0;
} else { // Assuming all other whitespace chars are just spaces
remainderSpaces++;
if (remainderSpaces === tabSize) {
fullTabs++;
remainderSpaces = 0;
}
}
}
return fullTabs * tabSize + remainderSpaces;
}
function hasClass(elt, className) {
return (new RegExp("\\b" + className + "\\b")).test(elt.className);
}
function addClass(elt, newClassName) {
if (!hasClass(elt, newClassName)) {
if (elt.className.trim() === "") {
elt.className = newClassName;
} else {
elt.className += " " + newClassName;
}
}
}
AppInit.appReady(function () {
indentSoftWraps(EditorManager.getCurrentFullEditor());
$(EditorManager).on("activeEditorChange", function (event, focusedEditor, lostEditor) {
indentSoftWraps(focusedEditor);
});
});
});