File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# react-toolkit
22
33Refactor React Native source code extracting inline styles from the VSCode menu
4+
5+ ![ demo] ( assets/demo.gif )
Original file line number Diff line number Diff line change 5858 },
5959 "devDependencies" : {
6060 "@types/glob" : " ^7.1.1" ,
61- "@types/line-column" : " ^1.0.0" ,
6261 "@types/mocha" : " ^7.0.1" ,
6362 "@types/node" : " ^12.11.7" ,
6463 "@types/vscode" : " ^1.42.0" ,
7069 "typescript" : " ^3.7.5" ,
7170 "vscode-test" : " ^1.3.0"
7271 },
73- "dependencies" : {
74- "line-column" : " ^1.0.2"
75- }
72+ "dependencies" : {}
7673}
Original file line number Diff line number Diff line change 11import * as vscode from 'vscode' ;
2- import lineColumn from 'line-column' ;
32import { editorContext , showInputBox , camelCase } from './utils' ;
43
54const { Position } = vscode ;
@@ -19,18 +18,19 @@ export async function extractStyle() {
1918 . edit ( ( edit ) => {
2019 const defaultLine = editor . document . lineCount + 1 ;
2120 let stylesText ;
22- let row = undefined ;
21+ let row = null ;
2322
2423 if ( text && ! ! ~ text . indexOf ( 'StyleSheet.create' ) ) {
25- row = lineColumn ( text ) . fromIndex ( text . indexOf ( 'StyleSheet.create' ) ) ;
24+ editor . document . getText ( selection ) ;
25+ row = editor . document . positionAt ( text . indexOf ( 'StyleSheet.create' ) ) . line ;
2626 stylesText = `${ styleName } : ${ selectedText } ,\n` ;
2727 } else {
28- stylesText = `\n\ nconst styles = StyleSheet.create({\n${ styleName } : ${ selectedText } ,\n})` ;
28+ stylesText = `\nconst styles = StyleSheet.create({\n${ styleName } : ${ selectedText } ,\n}); ` ;
2929 }
3030
3131 edit . replace ( selection , `styles.${ styleName } ` ) ;
3232
33- edit . insert ( new Position ( row ? row . line : defaultLine , 0 ) , stylesText ) ;
33+ edit . insert ( new Position ( row ? row + 1 : defaultLine , 0 ) , stylesText ) ;
3434 } )
3535 . then ( ( ) => {
3636 return vscode . commands . executeCommand ( 'editor.action.formatDocument' ) ;
Original file line number Diff line number Diff line change 4242 resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
4343 integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==
4444
45- " @types/line-column@^1.0.0 " :
46- version "1.0.0"
47- resolved "https://registry.yarnpkg.com/@types/line-column/-/line-column-1.0.0.tgz#fa5a59c21e885fef3739a273b43dacf55b63437f"
48- integrity sha512-wbw+IDRw/xY/RGy+BL6f4Eey4jsUgHQrMuA4Qj0CSG3x/7C2Oc57pmRoM2z3M4DkylWRz+G1pfX06sCXQm0J+w==
49-
5045" @types/minimatch@* " :
5146 version "3.0.3"
5247 resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -822,23 +817,11 @@ is-symbol@^1.0.2:
822817 dependencies :
823818 has-symbols "^1.0.1"
824819
825- isarray@1.0.0, isarray@^1.0.0 :
826- version "1.0.0"
827- resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
828- integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
829-
830820isexe@^2.0.0 :
831821 version "2.0.0"
832822 resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
833823 integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
834824
835- isobject@^2.0.0 :
836- version "2.1.0"
837- resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89"
838- integrity sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk=
839- dependencies :
840- isarray "1.0.0"
841-
842825js-tokens@^4.0.0 :
843826 version "4.0.0"
844827 resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -870,14 +853,6 @@ levn@^0.3.0, levn@~0.3.0:
870853 prelude-ls "~1.1.2"
871854 type-check "~0.3.2"
872855
873- line-column@^1.0.2 :
874- version "1.0.2"
875- resolved "https://registry.yarnpkg.com/line-column/-/line-column-1.0.2.tgz#d25af2936b6f4849172b312e4792d1d987bc34a2"
876- integrity sha1-0lryk2tvSEkXKzEuR5LR2Ye8NKI=
877- dependencies :
878- isarray "^1.0.0"
879- isobject "^2.0.0"
880-
881856locate-path@^3.0.0 :
882857 version "3.0.0"
883858 resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
You can’t perform that action at this time.
0 commit comments