Skip to content
Merged
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
16 changes: 9 additions & 7 deletions src/extensions/default/CSSCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ define(function (require, exports, module) {
* Emmet API:
* This provides a function to expand abbreviations into full CSS properties.
*/
const EXPAND_ABBR = Phoenix.libs.Emmet.expand;
const expandAbbr = Phoenix.libs.Emmet.expand;
let enabled = true; // whether Emmet is enabled or not in preferences

require("./css-lint");
Expand Down Expand Up @@ -408,15 +408,15 @@ define(function (require, exports, module) {
// wrapped in try catch block because EXPAND_ABBR might throw error when it gets unexpected
// characters such as `, =, etc
try {
let expandedAbbr = EXPAND_ABBR(needle, { syntax: "css", type: "stylesheet" });
if(expandedAbbr && isEmmetExpandable(needle, expandedAbbr)) {
let expandedAbbr = expandAbbr(needle, { syntax: "css", type: "stylesheet" });
if(expandedAbbr && _isEmmetExpandable(needle, expandedAbbr)) {

// if the expandedAbbr doesn't have any numbers, we should split the expandedAbbr to,
// get its first word before `:`.
// For instance, `m` expands to `margin: ;`. Here the `: ;` is unnecessary.
// Also, `bgc` expands to `background-color: #fff;`. Here we don't need the `: #fff;`
// as we have cssIntelligence to display hints based on the property
if(!isEmmetAbbrNumeric(expandedAbbr)) {
if(!_isEmmetAbbrNumeric(expandedAbbr)) {
expandedAbbr = expandedAbbr.split(':')[0];
}

Expand All @@ -436,7 +436,8 @@ define(function (require, exports, module) {

const $emmetHintObj = $("<span>")
.addClass("brackets-css-hints brackets-hints")
.attr("data-val", expandedAbbr);
.attr("data-val", expandedAbbr)
.attr("data-isEmmet", true);

// for highlighting the already-typed characters
if (token.stringRanges) {
Expand Down Expand Up @@ -498,7 +499,7 @@ define(function (require, exports, module) {
* @param {String} expandedAbbr the expanded abbr returned by EXPAND_ABBR emmet api
* @returns {boolean} true if emmet should be expanded, otherwise false
*/
function isEmmetExpandable(needle, expandedAbbr) {
function _isEmmetExpandable(needle, expandedAbbr) {
return needle + ': ;' !== expandedAbbr;
}

Expand All @@ -511,7 +512,7 @@ define(function (require, exports, module) {
* @param {String} expandedAbbr the expanded abbr returned by EXPAND_ABBR emmet api
* @returns {boolean} true if expandedAbbr has numbers (and doesn't include '#') otherwise false.
*/
function isEmmetAbbrNumeric(expandedAbbr) {
function _isEmmetAbbrNumeric(expandedAbbr) {
return expandedAbbr.match(/\d/) !== null && !expandedAbbr.includes('#') && !expandedAbbr.includes(',');
}

Expand Down Expand Up @@ -597,6 +598,7 @@ define(function (require, exports, module) {
ctx;

if (hint.jquery) {
hint.data("isEmmet") && Metrics.countEvent(Metrics.EVENT_TYPE.CODE_HINTS, "emmet", "cssInsert");
hint = hint.data("val") + ""; // font-weight: 400, 400 is returned as number so,
}

Expand Down
3 changes: 2 additions & 1 deletion src/extensions/default/DefaultExtensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"note": "This is only to for legacy extensions that havent been updated for a long time, remove flag unconditionally if instructed by the extension author, but inform of the issues in extension.",
"extensionIDs": [
"brackets-beautify", "beautify.io", "hirse.beautify", "jsbeautifier", "sizuhiko.brackets.prettier", "pretty_json",
"bib-locked-live-preview", "brackets-display-shortcuts", "changing-tags", "brackets-indent-guides"
"bib-locked-live-preview", "brackets-display-shortcuts", "changing-tags", "brackets-indent-guides", "brackets-emmet",
"github-Pluto-custom-line-height"
]
}
}
45 changes: 22 additions & 23 deletions src/extensions/default/HTMLCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ define(function (require, exports, module) {
/**
* The Emmet api's
*/
const EXPAND_ABBR = Phoenix.libs.Emmet.expand;
const expandAbbr = Phoenix.libs.Emmet.expand;

/**
* A list of all the markup snippets that can be expanded.
Expand Down Expand Up @@ -98,7 +98,7 @@ define(function (require, exports, module) {
// make sure we donot have empty spaces
if (wordObj.word.trim()) {

const expandedAbbr = isExpandable(editor, wordObj.word);
const expandedAbbr = _isExpandable(editor, wordObj.word);
if (expandedAbbr) {
return true;
}
Expand All @@ -119,7 +119,7 @@ define(function (require, exports, module) {
const wordObj = getWordBeforeCursor(this.editor);

// Check if the abbreviation is expandable
const expandedAbbr = isExpandable(this.editor, wordObj.word);
const expandedAbbr = _isExpandable(this.editor, wordObj.word);
if (!expandedAbbr) {
return null;
}
Expand Down Expand Up @@ -166,8 +166,9 @@ define(function (require, exports, module) {
*/
EmmetMarkupHints.prototype.insertHint = function () {
const wordObj = getWordBeforeCursor(this.editor);
const expandedAbbr = isExpandable(this.editor, wordObj.word);
updateAbbrInEditor(this.editor, wordObj, expandedAbbr);
const expandedAbbr = _isExpandable(this.editor, wordObj.word);
_updateAbbrInEditor(this.editor, wordObj, expandedAbbr);
Metrics.countEvent(Metrics.EVENT_TYPE.CODE_HINTS, "emmet", "htmlInsert");
return false;
};

Expand All @@ -179,7 +180,7 @@ define(function (require, exports, module) {
* @param {Boolean} insideBraces - Flag indicating if we are inside braces (e.g. {} or [])
* @returns True if the character is valid for an abbreviation
*/
function isEmmetChar(char, insideBraces) {
function _isEmmetChar(char, insideBraces) {
// Valid abbreviation characters: letters, digits, and some punctuation
// Adjust this regex or the list as needed for your implementation
const validPattern = /[a-zA-Z0-9:+*<>()/!$\-@#}{]/;
Expand All @@ -195,7 +196,7 @@ define(function (require, exports, module) {
* @param {Number} cursorCh - The cursor's character (column) position on that line
* @returns The index (column) where the abbreviation starts
*/
function findAbbreviationStart(line, cursorCh) {
function _findAbbreviationStart(line, cursorCh) {
let start = cursorCh;
let insideBraces = false;

Expand All @@ -217,7 +218,7 @@ define(function (require, exports, module) {
}

// If the character is valid as part of an Emmet abbreviation, continue scanning backwards
if (isEmmetChar(char, insideBraces)) {
if (_isEmmetChar(char, insideBraces)) {
start--;
} else {
break;
Expand Down Expand Up @@ -245,7 +246,7 @@ define(function (require, exports, module) {
const lineText = editor.document.getLine(pos.line);

// to determine where the abbreviation starts on the line
const abbreviationStart = findAbbreviationStart(lineText, pos.ch);
const abbreviationStart = _findAbbreviationStart(lineText, pos.ch);

// Optionally, adjust the end position if the cursor is immediately before a closing brace.
let abbreviationEnd = pos.ch;
Expand Down Expand Up @@ -401,7 +402,7 @@ define(function (require, exports, module) {
* }
* @param {String} expandedAbbr - the expanded version of abbr that will replace the abbr
*/
function updateAbbrInEditor(editor, wordObj, expandedAbbr) {
function _updateAbbrInEditor(editor, wordObj, expandedAbbr) {
// Get the current line's indentation
const baseIndent = getLineIndentation(editor, wordObj.start);

Expand Down Expand Up @@ -456,30 +457,30 @@ define(function (require, exports, module) {
*
* @param {Editor} editor - the editor instance
* @param {String} word - the abbr
* @returns {String | false} - returns the expanded abbr, and if cannot be expanded, returns false
* @returns {String | null} - returns the expanded abbr, and if cannot be expanded, returns null
*/
function isExpandable(editor, word) {
function _isExpandable(editor, word) {
const pos = editor.getCursorPos();
const line = editor.document.getLine(pos.line);

// to prevent hints from appearing in <!DOCTYPE html> line. Also to prevent hints from appearing in comments
if(line.includes('<!')) {
return false;
return null;
}

// to show emmet hint when either a single or three exclamation mark(s) is present
if (line.includes('!!') && !line.includes('!!!')) {
return false;
return null;
}

// if more than three, then don't show emmet hint
if(line.includes('!!!!')) {
return false;
return null;
}

// make sure that word doesn't contain any negativeSymbols
if (negativeSymbols.some(symbol => word.includes(symbol))) {
return false;
return null;
}

// the word must be either in markupSnippetsList, htmlList or it must have a positive symbol
Expand All @@ -491,8 +492,7 @@ define(function (require, exports, module) {
positiveSymbols.some(symbol => word.includes(symbol))) {

try {
const expanded = EXPAND_ABBR(word, { syntax: "html", type: "markup" });
return expanded;
return expandAbbr(word, { syntax: "html", type: "markup" }); // expanded
} catch (error) {

// emmet api throws an error when abbr contains unclosed quotes, handling that case
Expand All @@ -504,21 +504,20 @@ define(function (require, exports, module) {
const modifiedWord = word + nextChar;

try {
const expandedModified = EXPAND_ABBR(modifiedWord, { syntax: "html", type: "markup" });
return expandedModified;
return expandAbbr(modifiedWord, { syntax: "html", type: "markup" }); //expandedModified
} catch (innerError) {
// If it still fails, return false
return false;
return null;
}
}
}

// If no quote is found or expansion fails, return false
return false;
return null;
}
}

return false;
return null;
}


Expand Down
Loading