-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain copy.js
148 lines (110 loc) · 4.88 KB
/
main copy.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window */
define(function (require, exports, module) {
'use strict';
var Commands = brackets.getModule("command/Commands"),
CommandManager = brackets.getModule("command/CommandManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
Menus = brackets.getModule("command/Menus");
var dict;
require("bjspell/BJSpell");
//commands
var VIEW_HIDE_SPELLCHECK = "spellcheck.run";
function _handleSpellcheck() {
console.log("Running spellcheck");
/*
console.log(dict.suggest("spl"));
dict.replace("This is how I spl words I dn't know hoe to spelll.", function(word) {
console.log("for spl got "+word);
});
*/
var editor = EditorManager.getCurrentFullEditor();
var cm = editor._codeMirror;
if (!editor) {
_handleShowSpellcheck();
return;
}
var text = editor.document.getText();
//Taken from BSpell doc
//text = text.replace(/</g, String.fromCharCode(0));
console.log("TO SPELL: "+text);
var modded = dict.replace(text, function(word) {
console.log("word="+word);
return "<span class='underline'>"+word+"</span>";
});
//console.log(modded);
console.dir(editor);
cm.markText({line:1,ch:1},{line:1,ch:3}, "underline");
return;
results = CSSLint.verify(text);
messages = results.messages;
if (results.messages.length) {
var $csslintTable = $("<table class='zebra-striped condensed-table' style='table-layout: fixed; width: 100%'>").append("<tbody>");
$("<tr><th>Line</th><th>Declaration</th><th>Type</th><th>Message</th></tr>").appendTo($csslintTable);
var $selectedRow;
results.messages.forEach(function (item) {
var makeCell = function (content) {
return $("<td style='word-wrap: break-word' />").text(content);
};
//sometimes line is blank, as is evidence
if (!item.line) { item.line = ""; }
if (!item.evidence) { item.evidence = ""; }
var $row = $("<tr/>")
.append(makeCell(item.line))
.append(makeCell(item.evidence))
.append(makeCell(item.type))
.append(makeCell(item.message))
.appendTo($csslintTable);
$row.click(function () {
if ($selectedRow) {
$selectedRow.removeClass("selected");
}
$row.addClass("selected");
$selectedRow = $row;
var editor = EditorManager.getCurrentFullEditor();
editor.setCursorPos(item.line - 1, item.col - 1);
EditorManager.focusEditor();
});
});
$("#csslint .table-container")
.empty()
.append($csslintTable);
} else {
//todo - tell the user no issues
$("#csslint .table-container")
.empty()
.append("<p>No issues.</p>");
}
}
function _handleShowSpellcheck() {
var $panel = $("#spellcheckpanel");
//lazy load the init for the dictionary
if(!dict) {
console.log("Loading dictionary.");
dict = new BJSpell(require.toUrl("./BJSpell/en_US.js"), function() {
if ($panel.css("display") !== "none") {
_handleSpellcheck();
}
});
}
if ($panel.css("display") === "none") {
$panel.show();
CommandManager.get(VIEW_HIDE_SPELLCHECK).setChecked(true);
$(DocumentManager).on("currentDocumentChange documentSaved", _handleSpellcheck);
} else {
$panel.hide();
CommandManager.get(VIEW_HIDE_SPELLCHECK).setChecked(false);
$(DocumentManager).off("currentDocumentChange documentSaved", null, _handleSpellcheck);
}
EditorManager.resizeEditor();
}
CommandManager.register("Run Spellcheck", VIEW_HIDE_SPELLCHECK, _handleShowSpellcheck);
function init() {
ExtensionUtils.loadStyleSheet(module, "styles.css");
var menu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);
menu.addMenuItem(VIEW_HIDE_SPELLCHECK, "", Menus.AFTER, "menu-view-sidebar");
}
init();
});