0

私は基本的に現在の行の値を取得して解析し、pxをremに変換するビジュアルスタジオコード拡張を作成しようとしています(後でこれらの変数を作成しましたVisual Studio Code Extensionを作成しようとすると、3つの質問

私はMicrosoft APIサイトで強調表示されている値を取得する方法を知ることができたので、最初に関数を取得したいと思ったので、これを最初に実行しました。

はその後、私のコードで私は、ラインが1つの以上の値などであれば、最終的な値としてそれを返す方法についてはわからないよ

マージン:22px 32PX 0 32PX;

以下はコードです。あなたはこのように、選択オブジェクトを使用することができ

'use strict'; 
import * as vscode from 'vscode'; 
export function activate(context: vscode.ExtensionContext) { 
    let disposable = vscode.commands.registerCommand('extension.pxToEm',() => { 
     var base, editor, initBase, original, selection, text, unit, values, totalBase, position; 
     editor = vscode.window.activeTextEditor; 
     selection = editor.selection; 
     text = editor.document.getText(selection); 
     base = <any>16; 
     unit = 'rem'; 
     values = text.match(/([0-9]+)px/gi); 
     var returnValue = function(text) { 
      if (values !== null) { 
       values.forEach(function(val, key) { 
        text = text.replace(val, parseInt(val)/base + unit); 
        if (key > values.length - 1) { 
         totalBase = '/' + base.replace(/(\r\n|\n|\r)/gi, ''); 
         text = text.replace(totalBase, ' ').replace(/(\r\n|\n|\r)/gi, ''); 
         text = text + '\n'; 
        } 
       }); 
      } 
      return text; 
     }; 
     vscode.window.showInformationMessage(returnValue(text)); 
    }); 
    context.subscriptions.push(disposable); 
    } 
+0

私はちょうどカーソルで現在の行を、それを使用したいが、それは正しく動作するようになりました..私はありません持っていますアイディア。任意のヘルプが評価されます(したがって、選択の代わりに現在の行からコンテンツを取得し、返品時にそれを置き換えます –

答えて

1

:私は自分のコードを更新しました

editor = vscode.window.activeTextEditor; 
selection = editor.selection; 
if(selection.isEmpty) 
{ 
    // the Position object gives you the line and character where the cursor is 
     const position = editor.selection.active; 
     var newPosition = position.with(position.line, 0); 
     var newSelection = new vscode.Selection(newPosition, newPosition); 
     editor.selection = newSelection; 
} 
text = editor.document.getText(selection); 
関連する問題