Skip to content

Commit 7ec5559

Browse files
committed
refactor: move to current ES6 standards
1 parent 3c38d64 commit 7ec5559

File tree

3 files changed

+75
-85
lines changed

3 files changed

+75
-85
lines changed

src/extensionsIntegrated/Bookmarks/bookmarksView.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
define(function (require, exports, module) {
2-
var CommandManager = require("command/CommandManager"),
3-
Commands = require("command/Commands"),
4-
ProjectManager = require("project/ProjectManager"),
5-
WorkspaceManager = require("view/WorkspaceManager"),
6-
MainViewManger = require("view/MainViewManager"),
7-
Strings = require("strings"),
8-
bookmarksPanelTemplate = require("text!./htmlContent/bookmarks-panel.html"),
9-
bookmarksListTemplate = require("text!./htmlContent/bookmarks-list.html"),
10-
Mustache = require("thirdparty/mustache/mustache");
2+
const CommandManager = require("command/CommandManager");
3+
const Commands = require("command/Commands");
4+
const ProjectManager = require("project/ProjectManager");
5+
const WorkspaceManager = require("view/WorkspaceManager");
6+
const MainViewManger = require("view/MainViewManager");
7+
const Strings = require("strings");
8+
const Mustache = require("thirdparty/mustache/mustache");
9+
10+
const bookmarksPanelTemplate = require("text!./htmlContent/bookmarks-panel.html");
11+
const bookmarksListTemplate = require("text!./htmlContent/bookmarks-list.html");
1112

1213
/**
13-
* @const
1414
* Debounce time for document changes updating the search results view.
15-
* @type {number}
1615
*/
17-
var UPDATE_TIMEOUT = 400;
16+
const UPDATE_TIMEOUT = 400;
1817

1918
/**
20-
* @const
2119
* MainViewManager events
22-
* @type {string}
2320
*/
24-
var MVM_EVENTS = `workingSetAdd
21+
const MVM_EVENTS = `workingSetAdd
2522
workingSetAddList
2623
workingSetMove
2724
workingSetRemove
@@ -41,7 +38,7 @@ define(function (require, exports, module) {
4138
* @param {function=} beforeRender - function to call before rendering the view
4239
*/
4340
function BookmarksView(model, beforeRender) {
44-
var panelHtml = Mustache.render(bookmarksPanelTemplate, {
41+
const panelHtml = Mustache.render(bookmarksPanelTemplate, {
4542
Strings: Strings
4643
});
4744

@@ -72,7 +69,7 @@ define(function (require, exports, module) {
7269
* Handles when model changes. Updates the view, buffering changes if necessary so as not to churn too much.
7370
*/
7471
BookmarksView.prototype._handleModelChange = function () {
75-
var self = this;
72+
const self = this;
7673
if (self._ignoreModelChangeEvents) {
7774
return;
7875
}
@@ -96,15 +93,15 @@ define(function (require, exports, module) {
9693
* Adds the listeners for close and clicking on a bookmark in the list
9794
*/
9895
BookmarksView.prototype._addPanelListeners = function () {
99-
var self = this;
96+
const self = this;
10097
this._$panel
10198
.off(".bookmarks") // Remove the old events
10299
.on("click.bookmarks", ".close", function () {
103100
self.close();
104101
})
105102
// Add the click event listener directly on the table parent
106103
.on("click.bookmarks .table-container", function (e) {
107-
var $row = $(e.target).closest("tr");
104+
const $row = $(e.target).closest("tr");
108105

109106
if ($row.length) {
110107
if (self._$selectedRow) {
@@ -113,7 +110,7 @@ define(function (require, exports, module) {
113110
$row.addClass("selected");
114111
self._$selectedRow = $row;
115112

116-
var fullPathAndLineNo = $row.find(".bookmark-result").text();
113+
const fullPathAndLineNo = $row.find(".bookmark-result").text();
117114

118115
CommandManager.execute(Commands.FILE_OPEN, { fullPath: fullPathAndLineNo });
119116
}
@@ -147,7 +144,7 @@ define(function (require, exports, module) {
147144
* Shows the current set of results.
148145
*/
149146
BookmarksView.prototype._render = function () {
150-
var self = this,
147+
const self = this,
151148
bookmarks = [];
152149

153150
if (this._beforeRender) {
@@ -196,7 +193,7 @@ define(function (require, exports, module) {
196193
// In general this shouldn't get called if the panel is closed, but in case some
197194
// asynchronous process kicks this (e.g. a debounced model change), we double-check.
198195
if (this._panel.isVisible()) {
199-
var scrollTop = this._$table.scrollTop(),
196+
let scrollTop = this._$table.scrollTop(),
200197
index = this._$selectedRow ? this._$selectedRow.index() : null;
201198
this._render();
202199
this._$table.scrollTop(scrollTop);
@@ -237,6 +234,5 @@ define(function (require, exports, module) {
237234
return this._panel && this._panel.isVisible();
238235
};
239236

240-
// Public API
241237
exports.BookmarksView = BookmarksView;
242238
});

src/extensionsIntegrated/Bookmarks/main.js

Lines changed: 50 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
11
define(function (require, exports, module) {
2-
var PreferencesManager = require("preferences/PreferencesManager"),
3-
CommandManager = require("command/CommandManager"),
4-
Menus = require("command/Menus"),
5-
DocumentManager = require("document/DocumentManager"),
6-
EditorManager = require("editor/EditorManager"),
7-
_ = require("thirdparty/lodash");
8-
92
const AppInit = require("utils/AppInit");
3+
const PreferencesManager = require("preferences/PreferencesManager");
4+
const CommandManager = require("command/CommandManager");
5+
const Menus = require("command/Menus");
6+
const DocumentManager = require("document/DocumentManager");
7+
const EditorManager = require("editor/EditorManager");
8+
const Strings = require("strings");
9+
const _ = require("thirdparty/lodash");
1010

11-
var BookmarksView = require("./bookmarksView").BookmarksView;
12-
13-
/** @const {string} Extension Command ID */
14-
var MY_MODULENAME = "bracketsEditorBookmarks";
15-
var CMD_TOGGLE_BOOKMARK = "bracketsEditorBookmarks.toggleBookmark",
16-
CMD_GOTO_NEXT_BOOKMARK = "bracketsEditorBookmarks.gotoNextBookmark",
17-
CMD_GOTO_PREV_BOOKMARK = "bracketsEditorBookmarks.gotoPrevBookmark",
18-
CMD_TOGGLE_BOOKKMARK_VIEW = "bracketsEditorBookmarks.toggleBookmarksPanel";
11+
const BookmarksView = require("./bookmarksView").BookmarksView;
1912

20-
const ExtensionStrings = {
21-
TOGGLE_BOOKMARK: "Toggle Bookmark",
22-
GOTO_PREV_BOOKMARK: "Go to previous Bookmark",
23-
GOTO_NEXT_BOOKMARK: "Go to next Bookmark",
24-
TOGGLE_BOOKMARKS_PANEL: "Toggle Bookmarks panel"
25-
};
13+
// command IDs
14+
const MY_MODULENAME = "bracketsEditorBookmarks";
15+
const CMD_TOGGLE_BOOKMARK = "bracketsEditorBookmarks.toggleBookmark";
16+
const CMD_GOTO_NEXT_BOOKMARK = "bracketsEditorBookmarks.gotoNextBookmark";
17+
const CMD_GOTO_PREV_BOOKMARK = "bracketsEditorBookmarks.gotoPrevBookmark";
18+
const CMD_TOGGLE_BOOKKMARK_VIEW = "bracketsEditorBookmarks.toggleBookmarksPanel";
2619

27-
/* Our extension's preferences */
28-
var prefs = PreferencesManager.getExtensionPrefs(MY_MODULENAME);
20+
const prefs = PreferencesManager.getExtensionPrefs(MY_MODULENAME);
2921

3022
// Bookmarks Data Model
31-
var _bookmarks = {};
32-
23+
const _bookmarks = {};
3324
// Bookmarks Panel
34-
var _bookmarksPanel = null;
25+
let _bookmarksPanel = null;
3526

3627
/**
3728
* Saves bookmarks to the data model for the specified editor instance
38-
* @param {Editor=} editor - brackets editor instance. current editor if null
29+
*
30+
* @param {Editor} editor - the editor instance
3931
* @return {?Array.<Number>} array of cached bookmarked line numbers
4032
*/
4133
function saveBookmarks(editor) {
4234
if (!editor) {
4335
editor = EditorManager.getCurrentFullEditor();
4436
}
4537
if (editor) {
46-
var i,
38+
let i,
4739
fullPath = editor.document.file.fullPath,
4840
cm = editor._codeMirror,
4941
lineCount = cm.doc.lineCount(),
5042
bookmarkedLines = [];
5143

5244
for (i = 0; i < lineCount; i++) {
53-
var lineInfo = cm.lineInfo(i);
45+
let lineInfo = cm.lineInfo(i);
5446

5547
if (lineInfo.wrapClass && lineInfo.wrapClass.indexOf("bookmark") >= 0) {
5648
bookmarkedLines.push(i);
@@ -75,14 +67,15 @@ define(function (require, exports, module) {
7567

7668
/**
7769
* Updates bookmarks for the current editor if necessary
78-
* @param {Editor=} editor - brackets editor instance. current editor if null
70+
*
71+
* @param {Editor} editor - the editor instance
7972
* @return {Boolean} true if there are bookmarks for the current editor, false if not
8073
*/
8174
function updateBookmarksForCurrentEditor() {
82-
var result = false,
75+
let result = false,
8376
editor = EditorManager.getCurrentFullEditor();
8477
if (editor) {
85-
var fullPath = editor.document.file.fullPath,
78+
let fullPath = editor.document.file.fullPath,
8679
bm = _bookmarks[fullPath];
8780

8881
// if there was already data then we
@@ -106,7 +99,8 @@ define(function (require, exports, module) {
10699
* (for traversal or to update the bookmarks panel),
107100
* updateBookmarksForCurrentEditor is called which updates
108101
* incrementally the bookmarks for the current file
109-
* @param {!Editor} editor - brackets editor instance
102+
*
103+
* @param {!Editor} editor - the editor instance
110104
*/
111105
function resetBookmarks(editor) {
112106
if (editor) {
@@ -117,14 +111,15 @@ define(function (require, exports, module) {
117111

118112
/**
119113
* Loads the cached bookmarks into the specified editor instance
120-
* @param {Editor=} editor - brackets editor instance. current editor if null
114+
*
115+
* @param {Editor} editor - brackets editor instance. current editor if null
121116
*/
122117
function loadBookmarks(editor) {
123118
if (!editor) {
124119
editor = EditorManager.getCurrentFullEditor();
125120
}
126121
if (editor) {
127-
var cm = editor._codeMirror,
122+
let cm = editor._codeMirror,
128123
bm = _bookmarks[editor.document.file.fullPath];
129124

130125
if (bm) {
@@ -139,10 +134,11 @@ define(function (require, exports, module) {
139134

140135
/**
141136
* Removes all bookmarks from the editor
137+
*
142138
* @param {!Editor} editor - brackets editor instance.
143139
*/
144140
function clearBookmarks(editor) {
145-
var i,
141+
let i,
146142
cm = editor._codeMirror,
147143
lineCount = cm.doc.lineCount();
148144

@@ -170,6 +166,7 @@ define(function (require, exports, module) {
170166

171167
/**
172168
* Reloads the bookmark model, clearing the current bookmarks
169+
*
173170
* @param {!Editor} editor - brackets editor instance.
174171
*/
175172
function reloadModel() {
@@ -193,26 +190,27 @@ define(function (require, exports, module) {
193190

194191
/**
195192
* Moves the cursor position of the current editor to the next bookmark
193+
*
196194
* @param {!Editor} editor - brackets editor instance
197195
*/
198196
function gotoNextBookmark(forward) {
199197
if (updateBookmarksForCurrentEditor()) {
200-
var editor = EditorManager.getCurrentFullEditor(),
198+
let editor = EditorManager.getCurrentFullEditor(),
201199
cursor = editor.getCursorPos(),
202200
bm = _bookmarks[editor.document.file.fullPath];
203201

204-
var doJump = function (lineNo) {
202+
let doJump = function (lineNo) {
205203
editor.setCursorPos(lineNo, 0);
206204

207-
var cm = editor._codeMirror;
205+
let cm = editor._codeMirror;
208206
cm.addLineClass(lineNo, "wrap", "bookmark-notify");
209207
setTimeout(function () {
210208
cm.removeLineClass(lineNo, "wrap", "bookmark-notify");
211209
}, 100);
212210
};
213211

214212
// find next bookmark
215-
var index;
213+
let index;
216214
for (
217215
index = forward ? 0 : bm.length - 1;
218216
forward ? index < bm.length : index >= 0;
@@ -251,9 +249,9 @@ define(function (require, exports, module) {
251249
* Toogles the bookmarked state of the current line of the current editor
252250
*/
253251
function toggleBookmark() {
254-
var editor = EditorManager.getCurrentFullEditor();
252+
let editor = EditorManager.getCurrentFullEditor();
255253
if (editor) {
256-
var cursor = editor.getCursorPos(),
254+
let cursor = editor.getCursorPos(),
257255
lineNo = cursor.line,
258256
cm = editor._codeMirror,
259257
lineInfo = cm.lineInfo(cursor.line);
@@ -269,6 +267,7 @@ define(function (require, exports, module) {
269267

270268
/**
271269
* Creates the bookmarks panel if it's truly needed
270+
*
272271
* @param {Boolean} panelRequired - true if panel is required. False if not
273272
*/
274273
function createBookmarksPanelIfNecessary(panelRequired) {
@@ -283,6 +282,7 @@ define(function (require, exports, module) {
283282

284283
/**
285284
* Shows the bookmarks panel
285+
*
286286
* @param {Boolean} show - true to show the panel, false to hide it
287287
* @param {{show:string=}=} options - undefined, {show: undefined|"opened"|"project"|"all"}, defaults to "opened"
288288
*/
@@ -333,32 +333,20 @@ define(function (require, exports, module) {
333333

334334
AppInit.appReady(function () {
335335
// register our commands
336-
CommandManager.register(ExtensionStrings.TOGGLE_BOOKMARK, CMD_TOGGLE_BOOKMARK, toggleBookmark);
337-
CommandManager.register(
338-
ExtensionStrings.GOTO_PREV_BOOKMARK,
339-
CMD_GOTO_PREV_BOOKMARK,
340-
_.partial(gotoNextBookmark, false)
341-
);
342-
CommandManager.register(
343-
ExtensionStrings.GOTO_NEXT_BOOKMARK,
344-
CMD_GOTO_NEXT_BOOKMARK,
345-
_.partial(gotoNextBookmark, true)
346-
);
336+
CommandManager.register(Strings.TOGGLE_BOOKMARK, CMD_TOGGLE_BOOKMARK, toggleBookmark);
337+
CommandManager.register(Strings.GOTO_PREV_BOOKMARK, CMD_GOTO_PREV_BOOKMARK, _.partial(gotoNextBookmark, false));
338+
CommandManager.register(Strings.GOTO_NEXT_BOOKMARK, CMD_GOTO_NEXT_BOOKMARK, _.partial(gotoNextBookmark, true));
347339

348340
// add our menu items
349-
var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU);
341+
let menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU);
350342

351343
menu.addMenuDivider();
352-
menu.addMenuItem(CMD_TOGGLE_BOOKMARK, "Ctrl-Shift-K");
353-
menu.addMenuItem(CMD_GOTO_NEXT_BOOKMARK, "Ctrl-P");
354-
menu.addMenuItem(CMD_GOTO_PREV_BOOKMARK, "Ctrl-Shift-P");
344+
menu.addMenuItem(CMD_TOGGLE_BOOKMARK, "Ctrl-Alt-B");
345+
menu.addMenuItem(CMD_GOTO_NEXT_BOOKMARK, "Ctrl-Alt-N");
346+
menu.addMenuItem(CMD_GOTO_PREV_BOOKMARK, "Ctrl-Alt-P");
355347

356348
menu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);
357-
CommandManager.register(
358-
ExtensionStrings.TOGGLE_BOOKMARKS_PANEL,
359-
CMD_TOGGLE_BOOKKMARK_VIEW,
360-
toggleBookmarksPanel
361-
);
349+
CommandManager.register(Strings.TOGGLE_BOOKMARKS_PANEL, CMD_TOGGLE_BOOKKMARK_VIEW, toggleBookmarksPanel);
362350
menu.addMenuDivider();
363351
menu.addMenuItem(CMD_TOGGLE_BOOKKMARK_VIEW);
364352

src/nls/root/strings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ define({
434434
"CLOSE_UNMODIFIED_TABS": "Close Unmodified Tabs",
435435
"REOPEN_CLOSED_FILE": "Reopen Closed File",
436436

437+
// Bookmarks extension strings
438+
"TOGGLE_BOOKMARK": "Toggle Bookmark",
439+
"GOTO_PREV_BOOKMARK": "Go to Previous Bookmark",
440+
"GOTO_NEXT_BOOKMARK": "Go to Next Bookmark",
441+
"TOGGLE_BOOKMARKS_PANEL": "Toggle Bookmarks panel",
442+
437443
// CodeInspection: errors/warnings
438444
"ERRORS_NO_FILE": "No File Open",
439445
"ERRORS_PANEL_TITLE_MULTIPLE": "{0} Problems - {1}",

0 commit comments

Comments
 (0)