This repository has been archived by the owner on Mar 26, 2020. It is now read-only.
/
zenCoding.js
74 lines (74 loc) · 3.24 KB
/
zenCoding.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
68
69
70
71
72
73
74
(function() {
var SUBLANGUAGE_EXTRA_LIST, SUBLANGUAGE_SUPPORTED_LIST, root;
root = (typeof $toolkit !== "undefined" && $toolkit !== null) ? $toolkit : this;
root.include('editor');
root.include('external');
SUBLANGUAGE_SUPPORTED_LIST = ['HTML', 'HTML5', 'XML', 'XBL', 'PHP'];
SUBLANGUAGE_EXTRA_LIST = ['CSS', 'Haml'];
$self.provider = function() {
var providerName, providerOrdering;
root.command.abbreviation.provider.apply(this, [(providerName = 'zenCoding'), (providerOrdering = 6200)]);
this.getAllowedCharacters = function() {
return [[], ['a-z', 'A-Z', '0-9', '#', '\\.', '>', '\\+', '\\*', '\\:', '\\$', '\\-', '_', '\\!', '@', '\\[', '\\]', '\\(', '\\)', '\\|']];
};
this.canExecute = function(view) {
var isEnabled, isInstalled, isLanguageSupported, lineStartPosition, rangeEnd, rangeStart, rangeText, scimoz;
isEnabled = root.pref('tagComplete.zenCodingEnabled') === 'true';
isInstalled = (typeof zen_editor !== "undefined" && zen_editor !== null) && (typeof zen_coding !== "undefined" && zen_coding !== null);
isLanguageSupported = SUBLANGUAGE_SUPPORTED_LIST.indexOf(view.document.subLanguage) >= 0 && root.editor.isHtmlBuffer(view);
isLanguageSupported = isLanguageSupported || SUBLANGUAGE_EXTRA_LIST.indexOf(view.document.subLanguage) >= 0;
if (isEnabled && isInstalled && isLanguageSupported) {
scimoz = view.scimoz;
if (scimoz.anchor === scimoz.currentPos) {
lineStartPosition = scimoz.positionFromLine(scimoz.lineFromPosition(scimoz.currentPos));
rangeStart = scimoz.anchor - 1;
rangeEnd = scimoz.currentPos;
rangeText = '';
while (rangeStart >= 0) {
rangeText = scimoz.getTextRange(rangeStart, rangeEnd);
if (!this.getAllowedRegExp().test(rangeText)) {
break;
} else if (rangeStart === lineStartPosition) {
rangeText = (" " + rangeText);
break;
}
rangeStart -= 1;
}
return /^\s+/.test(rangeText);
}
return true;
}
return false;
};
this.findSnippet = function(view, abbreviation) {
var content, length, snippet, tabstop;
length = abbreviation.length;
if ('<' === abbreviation.charAt(0)) {
abbreviation = abbreviation.substr(1);
}
snippet = null;
zen_editor.setContext(view);
content = zen_coding.expandAbbreviation(abbreviation, zen_editor.getSyntax(), zen_editor.getProfileName());
if (typeof content === "undefined" || content == undefined ? undefined : content.length) {
tabstop = 0;
content = content.replace(zen_coding.getCaretPlaceholder(), (function() {
return "[[%tabstop" + (tabstop += 1) + "]]";
}), 'g');
content = content.replace(("[[%tabstop" + (tabstop - 1) + "]]"), "[[%tabstop0]]");
snippet = $toolkit.library.createSnippet(content, abbreviation);
snippet.parent = {
name: 'Zen Coding',
parent: {
name: '*internal*'
}
};
}
return snippet;
};
return this;
};
$self.registerAll = function() {
root.external.zenCoding = new $self.provider();
return root.external.zenCoding.register();
};
})();