Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Emmet option inside Edit menu #2142

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/extensions/default/CSSCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define(function (require, exports, module) {
// the Emmet icon serves as a clickable link that redirects to the MDN page for the property (if available).
// This object follows the structure:
// { PROPERTY_NAME: MDN_URL }
const MDN_PROPERTIES_URLS = {};
const mdnPropertiesUrls = {};

PreferencesManager.definePreference("codehint.CssPropHints", "boolean", true, {
description: Strings.DESCRIPTION_CSS_PROP_HINTS
Expand Down Expand Up @@ -389,7 +389,7 @@ define(function (require, exports, module) {
const propertyKey = computedPropertyKeys[resultItem.sourceIndex];
if(properties[propertyKey] && properties[propertyKey].MDN_URL){
resultItem.MDN_URL = properties[propertyKey].MDN_URL;
MDN_PROPERTIES_URLS[propertyKey] = resultItem.MDN_URL;
mdnPropertiesUrls[propertyKey] = resultItem.MDN_URL;
}
}

Expand Down Expand Up @@ -429,8 +429,8 @@ define(function (require, exports, module) {
let $icon = $(`<a class="emmet-css-code-hint" style="text-decoration: none">Emmet</a>`);

// if MDN_URL is available for the property, add the href attribute to redirect to mdn
if(MDN_PROPERTIES_URLS[expandedAbbr]) {
$icon.attr("href", MDN_PROPERTIES_URLS[expandedAbbr]);
if(mdnPropertiesUrls[expandedAbbr]) {
$icon.attr("href", mdnPropertiesUrls[expandedAbbr]);
$icon.attr("title", Strings.DOCS_MORE_LINK_MDN_TITLE);
}

Expand Down
4 changes: 2 additions & 2 deletions src/extensions/default/HTMLCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ define(function (require, exports, module) {
return false;
}

// to show emmet hint when either a single or three exclamation mark(s) is present
// not to show emmet hint when either a single or three exclamation mark(s) is present
if (line.includes('!!') && !line.includes('!!!')) {
return false;
}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ define(function (require, exports, module) {
preferenceChanged();

var emmetMarkupHints = new EmmetMarkupHints();
CodeHintManager.registerHintProvider(emmetMarkupHints, ["html", "php", "jsp"], 0);
CodeHintManager.registerHintProvider(emmetMarkupHints, ["html", "php"], 0);

// For unit testing
exports.emmetHintProvider = emmetMarkupHints;
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ define({
"CMD_BEAUTIFY_CODE": "Beautify Code",
"CMD_BEAUTIFY_CODE_ON_SAVE": "Beautify Code After Save",
"CMD_AUTO_RENAME_TAGS": "Auto Rename HTML Tags",
"CMD_TOGGLE_EMMET": "Emmet",

// Search menu commands
"FIND_MENU": "Find",
Expand Down
32 changes: 30 additions & 2 deletions src/preferences/AllPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,48 @@
* PreferencesManager.on("change", AllPreferences.EMMET, preferenceChanged);
preferenceChanged();
* ```
* NB: JSDOC/Comments marked with * are required for adding the option to Menu
*/

define(function (require, exports, module) {
define(function (require, exports, module) {
const PreferencesManager = require("preferences/PreferencesManager");
const Strings = require("strings");
const Menus = require("command/Menus");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this command registration to DocumentCommandHandlers.js and menu addition to DefaultMenus.js. thats where we usually add shared code preferences.

const AppInit = require("utils/AppInit");
const CommandManager = require("command/CommandManager");
const Commands = require("command/Commands");

// * list of all the commands
const EMMET_COMMAND_ID = "edit.emmet";
const emmetCommand = CommandManager.register(Strings.CMD_TOGGLE_EMMET, EMMET_COMMAND_ID, toggleEmmet);


// list of all the preferences
const PREFERENCES_LIST = {
EMMET: "emmet"
};


// define Emmet in preferences file
PreferencesManager.definePreference(PREFERENCES_LIST.EMMET, "boolean", true, {
description: Strings.DESCRIPTION_EMMET
});


// * emmet helper function to toggle emmet preferences
function toggleEmmet() {
PreferencesManager.set(PREFERENCES_LIST.EMMET, !PreferencesManager.get(PREFERENCES_LIST.EMMET));
emmetCommand.setChecked(PreferencesManager.get(PREFERENCES_LIST.EMMET));
}


AppInit.appReady(function () {
// * Register the command and add it to Menu bar
emmetCommand.setChecked(PreferencesManager.get(PREFERENCES_LIST.EMMET));
var menu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);

menu.addMenuItem(EMMET_COMMAND_ID);
});

module.exports = PREFERENCES_LIST;
});
});
Loading