From c6e93113ddafc4d53415422ef5cf6298861b2dea Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sat, 17 Sep 2022 11:55:47 +0430 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=92=84=20Include=20both=20``=20a?= =?UTF-8?q?nd=20``=20in=20hover?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- src/services/selectorPrinting.ts | 33 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/services/selectorPrinting.ts b/src/services/selectorPrinting.ts index edc1654b..1851d72c 100644 --- a/src/services/selectorPrinting.ts +++ b/src/services/selectorPrinting.ts @@ -170,32 +170,27 @@ class MarkedStringPrinter { } // the real deal - const content = ['<']; - - // element name if (name) { - content.push(name); - } else { - content.push('element'); + this.writeLine(indent, this.prepareElement(name, element.attributes?.filter(x => x.name !== 'name'))); } + this.writeLine(indent, this.prepareElement('element', element.attributes)); + } - // attributes - if (element.attributes) { - for (const attr of element.attributes) { - if (attr.name !== 'name') { - content.push(' '); - content.push(attr.name); - const value = attr.value; - if (value) { - content.push('='); - content.push(quotes.ensure(value, this.quote)); - } + private prepareElement(name: string, attributes?: Element['attributes']): string { + const content = [`<${name}`]; + if (attributes) { + for (const attr of attributes) { + content.push(' '); + content.push(attr.name); + const value = attr.value; + if (value) { + content.push('='); + content.push(quotes.ensure(value, this.quote)); } } } content.push('>'); - - this.writeLine(indent, content.join('')); + return content.join(''); } } From 0dc8fbd28cca73fc5adc18de9ebf5c4a5487f066 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sat, 17 Sep 2022 11:56:45 +0430 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20Add=20tests=20to=20ver?= =?UTF-8?q?ify=20both=20element=20formats=20in=20hover?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- src/test/css/hover.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/css/hover.test.ts b/src/test/css/hover.test.ts index ca457081..23f33fb3 100644 --- a/src/test/css/hover.test.ts +++ b/src/test/css/hover.test.ts @@ -61,13 +61,25 @@ suite('CSS Hover', () => { // }); }); - test('specificity', () => { + test.only('specificity', () => { assertHover('.|foo {}', { contents: [ { language: 'html', value: '' }, '[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)' ] }); + assertHover('[name="something"] { color: blue; }', { + contents: [ + { language: 'html', value: '\n' }, + '[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)' + ] + }); + assertHover('[attr="something"] { color: blue; }', { + contents: [ + { language: 'html', value: '' }, + '[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)' + ] + }); }); }); From 4a90659dbe7c6682909989db0845c8ea977541f9 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sat, 17 Sep 2022 15:45:44 +0430 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=90=9B=20Remove=20`test.only`=20slipp?= =?UTF-8?q?ed=20through=20debugging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/css/hover.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/css/hover.test.ts b/src/test/css/hover.test.ts index 23f33fb3..dd6eadb0 100644 --- a/src/test/css/hover.test.ts +++ b/src/test/css/hover.test.ts @@ -61,7 +61,7 @@ suite('CSS Hover', () => { // }); }); - test.only('specificity', () => { + test('specificity', () => { assertHover('.|foo {}', { contents: [ { language: 'html', value: '' }, From 88f5c4f2a3e9968036d6b8f369edcae45eb6d2fd Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Mon, 19 Sep 2022 12:15:30 +0430 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=94=A8=20Use?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- src/services/selectorPrinting.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/selectorPrinting.ts b/src/services/selectorPrinting.ts index 1851d72c..ef7c7f20 100644 --- a/src/services/selectorPrinting.ts +++ b/src/services/selectorPrinting.ts @@ -170,10 +170,12 @@ class MarkedStringPrinter { } // the real deal + const content = []; if (name) { - this.writeLine(indent, this.prepareElement(name, element.attributes?.filter(x => x.name !== 'name'))); + content.push(this.prepareElement(name, element.attributes?.filter(x => x.name !== 'name'))); } - this.writeLine(indent, this.prepareElement('element', element.attributes)); + content.push(this.prepareElement('element', element.attributes)); + this.writeLine(indent, content.join('|')); } private prepareElement(name: string, attributes?: Element['attributes']): string { From c59a7c469c538408e588f21cf50719a658965570 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Mon, 19 Sep 2022 12:17:40 +0430 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20Update=20test=20with?= =?UTF-8?q?=20"|"=20joiner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- src/test/css/hover.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/css/hover.test.ts b/src/test/css/hover.test.ts index dd6eadb0..3f299580 100644 --- a/src/test/css/hover.test.ts +++ b/src/test/css/hover.test.ts @@ -70,7 +70,7 @@ suite('CSS Hover', () => { }); assertHover('[name="something"] { color: blue; }', { contents: [ - { language: 'html', value: '\n' }, + { language: 'html', value: '|' }, '[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)' ] });