This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
space_mode.js
57 lines (47 loc) · 1.73 KB
/
space_mode.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
/*
* space_mode.js - function implementations unique to space-separated files
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, Mustache, CodeMirror, _showKeywords, _showHubNotice */
define(function (require, exports, module) {
"use strict";
var PreferencesManager = brackets.getModule("preferences/PreferencesManager");
function isSeparator(stream) {
// Return true if the stream is currently in a separator
// (read: tab, or two or more whitespace characters
var match = stream.match(/(\t|\s{2,})/);
return match;
}
function onTab(cm, pos, state) {
var useTabChar = PreferencesManager.get("useTabChar");
var tab = "\t";
if (!useTabChar) {
var spaceUnits = PreferencesManager.get("spaceUnits");
tab = new Array(spaceUnits+1).join(" ");
}
cm.replaceRange(tab, pos);
return;
}
function eatCellContents(stream, state) {
// gobble up characters until the end of the line or we find a separator
var ch;
while ((ch = stream.next()) != null) {
if (ch === "\\") {
// escaped character; gobble up the following character
stream.next();
} else if (ch === "\t") {
stream.backUp(1);
break;
} else if (ch === " ") {
if (stream.match(/\s/, false)) {
stream.backUp(1);
break;
}
}
}
return (stream.current().length > 0);
}
exports.isSeparator = isSeparator;
exports.eatCellContents = eatCellContents;
exports.onTab = onTab;
})