From 346660ffab1bb3e1e213d04f71859af2d77537e4 Mon Sep 17 00:00:00 2001 From: Evan Schiavone-Jacobson Date: Mon, 15 Feb 2016 10:18:23 -0600 Subject: [PATCH 1/2] Refactoring QuickOpen extensions, separating reused code into a new file. --- src/brackets.js | 1 + src/extensions/default/QuickOpenCSS/main.js | 11 +-- src/extensions/default/QuickOpenHTML/main.js | 39 ++--------- .../default/QuickOpenJavaScript/main.js | 40 ++--------- src/search/QuickOpenHelper.js | 70 +++++++++++++++++++ 5 files changed, 81 insertions(+), 80 deletions(-) create mode 100644 src/search/QuickOpenHelper.js diff --git a/src/brackets.js b/src/brackets.js index a362e8d2d43..cee3b56c686 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -91,6 +91,7 @@ define(function (require, exports, module) { require("editor/CSSInlineEditor"); require("project/WorkingSetSort"); require("search/QuickOpen"); + require("search/QuickOpenHelper"); require("file/FileUtils"); require("project/SidebarView"); require("utils/Resizer"); diff --git a/src/extensions/default/QuickOpenCSS/main.js b/src/extensions/default/QuickOpenCSS/main.js index 06b64be1c28..8526a8b1738 100644 --- a/src/extensions/default/QuickOpenCSS/main.js +++ b/src/extensions/default/QuickOpenCSS/main.js @@ -31,6 +31,7 @@ define(function (require, exports, module) { var EditorManager = brackets.getModule("editor/EditorManager"), QuickOpen = brackets.getModule("search/QuickOpen"), + QuickOpenHelper = brackets.getModule("search/QuickOpenHelper"), CSSUtils = brackets.getModule("language/CSSUtils"), DocumentManager = brackets.getModule("document/DocumentManager"), StringMatch = brackets.getModule("utils/StringMatch"); @@ -79,14 +80,6 @@ define(function (require, exports, module) { return filteredList; } - /** - * @param {string} query what the user is searching for - * @param {boolean} returns true if this plugin wants to provide results for this query - */ - function match(query) { - return (query[0] === "@"); - } - /** * Scroll to the selected item in the current document (unless no query string entered yet, * in which case the topmost list item is irrelevant) @@ -116,7 +109,7 @@ define(function (require, exports, module) { name: "CSS Selectors", languageIds: ["css", "less", "scss"], search: search, - match: match, + match: QuickOpenHelper.match, itemFocus: itemFocus, itemSelect: itemSelect } diff --git a/src/extensions/default/QuickOpenHTML/main.js b/src/extensions/default/QuickOpenHTML/main.js index 49ab747dbaf..f3fb4f91e14 100644 --- a/src/extensions/default/QuickOpenHTML/main.js +++ b/src/extensions/default/QuickOpenHTML/main.js @@ -31,6 +31,7 @@ define(function (require, exports, module) { var EditorManager = brackets.getModule("editor/EditorManager"), QuickOpen = brackets.getModule("search/QuickOpen"), + QuickOpenHelper = brackets.getModule("search/QuickOpenHelper"), DocumentManager = brackets.getModule("document/DocumentManager"), StringMatch = brackets.getModule("utils/StringMatch"); @@ -113,46 +114,14 @@ define(function (require, exports, module) { return filteredList; } - /** - * @param {string} query what the user is searching for - * @param {boolean} returns true if this plug-in wants to provide results for this query - */ - function match(query) { - return (query[0] === "@"); - } - - - /** - * Scroll to the selected item in the current document (unless no query string entered yet, - * in which case the topmost list item is irrelevant) - * @param {?SearchResult} selectedItem - * @param {string} query - * @param {boolean} explicit False if this is only highlighted due to being at top of list after search() - */ - function itemFocus(selectedItem, query, explicit) { - if (!selectedItem || (query.length < 2 && !explicit)) { - return; - } - var fileLocation = selectedItem.fileLocation; - - var from = {line: fileLocation.line, ch: fileLocation.chFrom}; - var to = {line: fileLocation.line, ch: fileLocation.chTo}; - EditorManager.getCurrentFullEditor().setSelection(from, to, true); - } - - function itemSelect(selectedItem, query) { - itemFocus(selectedItem, query, true); - } - - QuickOpen.addQuickOpenPlugin( { name: "html ids", languageIds: ["html"], search: search, - match: match, - itemFocus: itemFocus, - itemSelect: itemSelect + match: QuickOpenHelper.match, + itemFocus: QuickOpenHelper.itemFocus, + itemSelect: QuickOpenHelper.itemSelect } ); diff --git a/src/extensions/default/QuickOpenJavaScript/main.js b/src/extensions/default/QuickOpenJavaScript/main.js index eb1f8aff5b8..b699e095e70 100644 --- a/src/extensions/default/QuickOpenJavaScript/main.js +++ b/src/extensions/default/QuickOpenJavaScript/main.js @@ -31,6 +31,7 @@ define(function (require, exports, module) { var EditorManager = brackets.getModule("editor/EditorManager"), QuickOpen = brackets.getModule("search/QuickOpen"), + QuickOpenHelper = brackets.getModule("search/QuickOpenHelper"), JSUtils = brackets.getModule("language/JSUtils"), DocumentManager = brackets.getModule("document/DocumentManager"), StringMatch = brackets.getModule("utils/StringMatch"); @@ -106,47 +107,14 @@ define(function (require, exports, module) { return filteredList; } - /** - * @param {string} query what the user is searching for - * @param {boolean} returns true if this plug-in wants to provide results for this query - */ - function match(query) { - // only match @ at beginning of query for now - return (query[0] === "@"); - } - - /** - * Scroll to the selected item in the current document (unless no query string entered yet, - * in which case the topmost list item is irrelevant) - * @param {?SearchResult} selectedItem - * @param {string} query - * @param {boolean} explicit False if this is only highlighted due to being at top of list after search() - */ - function itemFocus(selectedItem, query, explicit) { - if (!selectedItem || (query.length < 2 && !explicit)) { - return; - } - var fileLocation = selectedItem.fileLocation; - - var from = {line: fileLocation.line, ch: fileLocation.chFrom}; - var to = {line: fileLocation.line, ch: fileLocation.chTo}; - EditorManager.getCurrentFullEditor().setSelection(from, to, true); - } - - function itemSelect(selectedItem, query) { - itemFocus(selectedItem, query, true); - } - - - QuickOpen.addQuickOpenPlugin( { name: "JavaScript functions", languageIds: ["javascript"], search: search, - match: match, - itemFocus: itemFocus, - itemSelect: itemSelect + match: QuickOpenHelper.match, + itemFocus: QuickOpenHelper.itemFocus, + itemSelect: QuickOpenHelper.itemSelect } ); diff --git a/src/search/QuickOpenHelper.js b/src/search/QuickOpenHelper.js new file mode 100644 index 00000000000..99010351a03 --- /dev/null +++ b/src/search/QuickOpenHelper.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ +/*global define, $ */ + + + +define(function (require, exports, module) { + "use strict"; + + var EditorManager = require("editor/EditorManager"), + QuickOpen = require("search/QuickOpen"), + DocumentManager = require("document/DocumentManager"), + StringMatch = require("utils/StringMatch"); + + /** + * @param {string} query what the user is searching for + * @param {boolean} returns true if this plug-in wants to provide results for this query + */ + function match(query) { + return (query[0] === "@"); + } + + /** + * Scroll to the selected item in the current document (unless no query string entered yet, + * in which case the topmost list item is irrelevant) + * @param {?SearchResult} selectedItem + * @param {string} query + * @param {boolean} explicit False if this is only highlighted due to being at top of list after search() + */ + function itemFocus(selectedItem, query, explicit) { + if (!selectedItem || (query.length < 2 && !explicit)) { + return; + } + var fileLocation = selectedItem.fileLocation; + + var from = {line: fileLocation.line, ch: fileLocation.chFrom}; + var to = {line: fileLocation.line, ch: fileLocation.chTo}; + EditorManager.getCurrentFullEditor().setSelection(from, to, true); + } + + function itemSelect(selectedItem, query) { + itemFocus(selectedItem, query, true); + } + + exports.match = match; + exports.itemFocus = itemFocus; + exports.itemSelect = itemSelect; +}); From 25df24c86a9f383a5b825acf5be19d52d39aa30e Mon Sep 17 00:00:00 2001 From: Evan Schiavone-Jacobson Date: Mon, 2 May 2016 13:05:45 -0500 Subject: [PATCH 2/2] Fixed indentation, copyright notice, and JsDoc --- src/brackets.js | 2 +- src/search/QuickOpenHelper.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index cee3b56c686..83830a22fba 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -91,7 +91,7 @@ define(function (require, exports, module) { require("editor/CSSInlineEditor"); require("project/WorkingSetSort"); require("search/QuickOpen"); - require("search/QuickOpenHelper"); + require("search/QuickOpenHelper"); require("file/FileUtils"); require("project/SidebarView"); require("utils/Resizer"); diff --git a/src/search/QuickOpenHelper.js b/src/search/QuickOpenHelper.js index 99010351a03..237798a91ce 100644 --- a/src/search/QuickOpenHelper.js +++ b/src/search/QuickOpenHelper.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. + * Copyright (c) 2016-present Adobe Systems Incorporated. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -60,6 +60,12 @@ define(function (require, exports, module) { EditorManager.getCurrentFullEditor().setSelection(from, to, true); } + /** + * Scroll to the selected item in the current document (unless no query string entered yet, + * in which case the topmost list item is irrelevant) + * @param {?SearchResult} selectedItem + * @param {string} query + */ function itemSelect(selectedItem, query) { itemFocus(selectedItem, query, true); }