11export default async function ( { feature, console } ) {
22 const availableWidth = 405 ;
3+ const blankChar = "\u2800" ;
34
45 function getSpaceWidth ( ) {
56 const span = document . createElement ( "span" ) ;
67 span . style . visibility = "hidden" ;
78 span . style . whiteSpace = "pre" ;
8- span . textContent = " " ;
9+ span . textContent = blankChar ;
910 document . body . appendChild ( span ) ;
1011 const spaceWidth = span . getBoundingClientRect ( ) . width ;
1112 document . body . removeChild ( span ) ;
@@ -26,7 +27,7 @@ export default async function ({ feature, console }) {
2627 function clearCenterAlignment ( textarea ) {
2728 const lines = textarea . value . split ( "\n" ) ;
2829 const uncenteredLines = lines . map ( ( line ) => {
29- return line . replace ( / ^ \s + / , "" ) ;
30+ return line . replace ( / ^ [ \s \u2800 ] + / , "" ) ;
3031 } ) ;
3132 textarea . value = uncenteredLines . join ( "\n" ) ;
3233 }
@@ -49,7 +50,7 @@ export default async function ({ feature, console }) {
4950 const textWidth = getTextWidth ( line ) ;
5051 const totalSpaces = ( availableWidth - textWidth ) / spaceWidth / 2 ;
5152 const spaces =
52- totalSpaces > 0 ? " " . repeat ( Math . floor ( totalSpaces ) ) : "" ;
53+ totalSpaces > 0 ? blankChar . repeat ( Math . floor ( totalSpaces ) ) : "" ;
5354 return spaces + line ;
5455 } ) ;
5556 activeElement . value = centeredLines . join ( "\n" ) ;
0 commit comments