mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Add Document Editing Sample
This commit is contained in:
22
documentediting-sample/.vscode/launch.json
vendored
Normal file
22
documentediting-sample/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "npm: watch"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
documentediting-sample/.vscode/settings.json
vendored
Normal file
3
documentediting-sample/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"editor.insertSpaces": false
|
||||
}
|
||||
20
documentediting-sample/.vscode/tasks.json
vendored
Normal file
20
documentediting-sample/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
5
documentediting-sample/README.md
Normal file
5
documentediting-sample/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Document Editing Sample
|
||||
|
||||
This sample shows
|
||||
|
||||
- How to update document in current active editor through commands.
|
||||
2608
documentediting-sample/package-lock.json
generated
Normal file
2608
documentediting-sample/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
documentediting-sample/package.json
Normal file
39
documentediting-sample/package.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "reverseword",
|
||||
"displayName": "ReverseWord",
|
||||
"description": "Reverse a word",
|
||||
"version": "0.0.1",
|
||||
"publisher": "rebornix",
|
||||
"engines": {
|
||||
"vscode": "^1.29.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:extension.reverseWord"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.reverseWord",
|
||||
"title": "Reverse Word"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"lint": "tslint ./src/*.ts",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install",
|
||||
"test": "npm run compile && node ./node_modules/vscode/bin/test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^6.0.40",
|
||||
"tslint": "^5.11.0",
|
||||
"typescript": "^2.0.3",
|
||||
"vscode": "^1.1.22"
|
||||
}
|
||||
}
|
||||
24
documentediting-sample/src/extension.ts
Normal file
24
documentediting-sample/src/extension.ts
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
let disposable = vscode.commands.registerCommand('extension.reverseWord', function () {
|
||||
// Get the active text editor
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (editor) {
|
||||
let document = editor.document;
|
||||
let selection = editor.selection;
|
||||
|
||||
// Get the word within the selection
|
||||
let word = document.getText(selection);
|
||||
let reversed = word.split('').reverse().join('');
|
||||
editor.edit(editBuilder => {
|
||||
editBuilder.replace(selection, reversed);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
11
documentediting-sample/tsconfig.json
Normal file
11
documentediting-sample/tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": ["es6"],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src"
|
||||
},
|
||||
"exclude": ["node_modules", ".vscode-test"]
|
||||
}
|
||||
6
documentediting-sample/tslint.json
Normal file
6
documentediting-sample/tslint.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"rules": {
|
||||
"indent": [true, "tabs"],
|
||||
"semicolon": [true, "always"]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user