1
- const stream = require ( 'node:stream' ) ;
2
1
const htmlparser2 = require ( 'htmlparser2' ) ;
3
2
const vscode = require ( 'vscode' ) ;
4
3
@@ -15,13 +14,13 @@ class Client {
15
14
this . #document = this . #editor. document ;
16
15
}
17
16
18
- async * #highlighted( ) {
19
- // to rewrite
17
+ #highlighted( ) {
20
18
const highlighted = this . #editor. selection ;
21
- const selectionRange = new vscode . Range ( highlighted . start . line , 0 , highlighted . end . line , 999 ) ;
22
- const selected = this . #document. getText ( selectionRange ) ;
23
- if ( selected . length === 0 ) yield this . #document. getText ( ) ;
24
- yield selected ;
19
+ const start = highlighted . start . line ;
20
+ const end = highlighted . end . line ;
21
+ if ( start === end ) return this . #document. getText ( ) ;
22
+ const selectionRange = new vscode . Range ( start , 0 , end , 1000 ) ;
23
+ return this . #document. getText ( selectionRange ) ;
25
24
}
26
25
27
26
/** @param {string } message */
@@ -48,7 +47,9 @@ class Client {
48
47
// }
49
48
50
49
convert ( ) {
51
- const readable = stream . Readable . from ( this . #highlighted( ) ) ;
50
+ const highlighted = this . #highlighted( ) ;
51
+ console . log ( highlighted ) ;
52
+ // const readable = stream.Readable.from(this.#highlighted());
52
53
const classes = new Set ( ) ;
53
54
const parser = new htmlparser2 . Parser ( {
54
55
onattribute ( attribute , value ) {
@@ -61,20 +62,9 @@ class Client {
61
62
}
62
63
} ,
63
64
} ) ;
64
- const createTransformStream = ( ) => {
65
- const options = {
66
- async transform ( chunk , encoding , next ) {
67
- parser . write ( chunk . toString ( ) ) ;
68
- next ( ) ;
69
- } ,
70
- } ;
71
- return new stream . Transform ( options ) ;
72
- } ;
73
- return readable . pipe ( createTransformStream ( ) ) . on ( 'finish' , ( ) => {
74
- createTransformStream ( ) . destroy ( ) ;
75
- vscode . env . clipboard . writeText ( [ ...classes . values ( ) ] . join ( '\n' ) ) ;
76
- this . print ( 'done' ) ;
77
- } ) ;
65
+ parser . write ( highlighted ) ;
66
+ vscode . env . clipboard . writeText ( [ ...classes . values ( ) ] . join ( '\n' ) ) ;
67
+ this . print ( 'Classes are copied to the clipboard' ) ;
78
68
}
79
69
}
80
70
0 commit comments