Skip to content

Commit c168331

Browse files
committed
chore: add emmet icon at the side of emmet hint
1 parent 9f14cb3 commit c168331

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

src/extensions/default/CSSCodeHints/main.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -384,40 +384,54 @@ define(function (require, exports, module) {
384384
}
385385

386386
// pushedHints stores all the hints that will be displayed to the user
387-
// up until this much is the normal working of css code hints
388387
let pushedHints = formatHints(result);
389388

390389
// needle gives the current word before cursor, make sure that it exists
391390
// also needle shouldn't contain `-`, because for example if user typed:
392391
// `box-siz` then in that case it is very obvious that user wants to type `box-sizing`
393392
// but emmet expands it `box: siz;`. So we prevent calling emmet when needle has `-`.
394393
if(needle && !needle.includes('-')) {
395-
let expandedAbbr = EXPAND_ABBR(needle, { syntax: "css", type: "stylesheet" });
396-
if(expandedAbbr && isEmmetExpandable(needle, expandedAbbr)) {
397-
398-
// if the expandedAbbr doesn't have any numbers, we should split the expandedAbbr to,
399-
// get its first word before `:`.
400-
// For instance, `m` expands to `margin: ;`. Here the `: ;` is unnecessary.
401-
// Also, `bgc` expands to `background-color: #fff;`. Here we don't need the `: #fff;`
402-
// as we have cssIntelligence to display hints based on the property
403-
if(!isEmmetAbbrNumeric(expandedAbbr)) {
404-
expandedAbbr = expandedAbbr.split(':')[0];
405-
}
406394

407-
if(pushedHints) {
395+
// wrapped in try catch block because EXPAND_ABBR might throw error when it gets unexpected
396+
// characters such as `, =, etc
397+
try {
398+
let expandedAbbr = EXPAND_ABBR(needle, { syntax: "css", type: "stylesheet" });
399+
if(expandedAbbr && isEmmetExpandable(needle, expandedAbbr)) {
400+
401+
// if the expandedAbbr doesn't have any numbers, we should split the expandedAbbr to,
402+
// get its first word before `:`.
403+
// For instance, `m` expands to `margin: ;`. Here the `: ;` is unnecessary.
404+
// Also, `bgc` expands to `background-color: #fff;`. Here we don't need the `: #fff;`
405+
// as we have cssIntelligence to display hints based on the property
406+
if(!isEmmetAbbrNumeric(expandedAbbr)) {
407+
expandedAbbr = expandedAbbr.split(':')[0];
408+
}
409+
410+
// this displays an emmet icon at the side of the hint
411+
// this gives an idea to the user that the hint is coming from Emmet
412+
let $icon = $(`<span class="emmet-css-code-hint">Emmet</span>`);
408413

409-
// to remove duplicate hints. one comes from emmet and other from default css hints.
410-
// we remove the default css hints and push emmet hint at the beginning.
411-
for(let i = 0; i < pushedHints.length; i++) {
412-
if(pushedHints[i][0].getAttribute('data-val') === expandedAbbr) {
413-
pushedHints.splice(i, 1);
414-
break;
414+
const $emmetHintObj = $(`<span data-val='${expandedAbbr}'></span>`).addClass("brackets-css-hints brackets-hints");
415+
$emmetHintObj.text(expandedAbbr);
416+
$emmetHintObj.append($icon);
417+
418+
if(pushedHints) {
419+
420+
// to remove duplicate hints. one comes from emmet and other from default css hints.
421+
// we remove the default css hints and push emmet hint at the beginning.
422+
for(let i = 0; i < pushedHints.length; i++) {
423+
if(pushedHints[i][0].getAttribute('data-val') === expandedAbbr) {
424+
pushedHints.splice(i, 1);
425+
break;
426+
}
415427
}
428+
pushedHints.unshift($emmetHintObj);
429+
} else {
430+
pushedHints = $emmetHintObj;
416431
}
417-
pushedHints.unshift(expandedAbbr);
418-
} else {
419-
pushedHints = expandedAbbr;
420432
}
433+
} catch (e) {
434+
// pass
421435
}
422436
}
423437

src/styles/brackets_patterns_override.less

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,24 @@ a:focus {
709709
}
710710
}
711711

712+
.emmet-css-code-hint {
713+
visibility: hidden;
714+
}
715+
716+
.highlight .emmet-css-code-hint {
717+
visibility: visible;
718+
position: absolute;
719+
right: 8px;
720+
font-size: 0.7em;
721+
font-weight: bold;
722+
margin-top: 2px;
723+
letter-spacing: 0.3px;
724+
color: #2ea56c !important;
725+
.dark& {
726+
color: #146a41 !important;
727+
}
728+
}
729+
712730
#codehint-desc {
713731
background: @bc-codehint-desc;
714732
position: absolute;

0 commit comments

Comments
 (0)