--- lang: ja-jp breaks: true --- # `VSIX` による、エディタの操作 `IEditorOperationsFactoryService` 2022-01-26 ## `IEditorOperationsFactoryService` をインポートする定義を記述 ```csharp= [Import] internal IEditorOperationsFactoryService EditorOperations = null; ``` ## `IWpfTextView` から `IEditorOperations` を取得 ```csharp= public IEditorOperations GetEditorOperations(IWpfTextView textView) { if (EditorOperations != null && textView != null) { return EditorOperations.GetEditorOperations(textView); } return null; } ``` ## `IEditorOperations` を使ってエディタの操作を記述 ```csharp= if (EditorOperations != null) { bool extendSelection = false; if (textView.Selection.IsEmpty == false) { extendSelection = true; } // カーソルを一行下に移動 EditorOperations.MoveLineDown(extendSelection: extendSelection); } ``` ###### tags: `VSIX` `IEditorOperationsFactoryService` `IEditorOperations` `IWpfTextView`