forked from chuyik/brackets-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
81 lines (66 loc) · 2.34 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*jslint indent: 2, maxerr: 50 */
/*global define, $, brackets, window, Mustache */
/**
* JavaScript Snippets for Brackets
*
* Based on:
* JavaScript & NodeJS Snippets for Sublime
*/
define(function (require, exports, module) {
"use strict";
var AppInit = brackets.getModule('utils/AppInit'),
CommandManager = brackets.getModule("command/CommandManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
Menus = brackets.getModule("command/Menus");
var Hinter = require('./lib/Hinter'),
HintWidget = require('./widget/main');
var hinter, hintWidget;
var handlers;
function activeEditorChangeHandler (bracketsEvent, focusedEditor, lostEditor) {
if (lostEditor) {
lostEditor.off = lostEditor.off || $(lostEditor).off;
if(hinter){
lostEditor
.off("keydown", handlers.keydown)
.off("keypress", handlers.keypress)
.off("keyup", handlers.keyup)
.off("change", handlers.change)
.off("cursorActivity", handlers.cursorActivity);
}
}
if (focusedEditor) {
focusedEditor.on = focusedEditor.on || $(focusedEditor).on;
if (!hinter) {
hinter = new Hinter(focusedEditor);
hintWidget = new HintWidget();
hintWidget.init(hinter);
} else {
hinter.init(focusedEditor);
}
handlers = {
keydown: hinter.keyDownHandler.bind(hinter),
keypress: hinter.keyPressHandler.bind(hinter),
keyup: hinter.keyUpHandler.bind(hinter),
change: hinter.changeHandler.bind(hinter),
cursorActivity: hinter.cursorActivityHandler.bind(hinter)
}
focusedEditor
.on("keydown", handlers.keydown)
.on("keypress", handlers.keypress)
.on("keyup", handlers.keyup)
.on("change", handlers.change)
.on("cursorActivity", handlers.cursorActivity);
}
}
AppInit.appReady(function () {
// Instantly initialize extension after being installed.
// Note:
// The editor instance would be null at the moment when Brackets starts
var editor = EditorManager.getCurrentFullEditor();
if(editor){
activeEditorChangeHandler(null, editor, null);
}
EditorManager.on = EditorManager.on || $(EditorManager).on;
EditorManager.on('activeEditorChange', activeEditorChangeHandler);
});
});