diff --git a/README.md b/README.md index 1f9e39f..e1ada0a 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ [![Build Status](https://travis-ci.org/markvincze/vscode-codeFragments.svg?branch=master)](https://travis-ci.org/markvincze/vscode-codeFragments) -With this extension you can save static code fragments for later use, and easily insert them into source files whenever needed. +With this extension you can save static code fragments for later use, and easily insert them into source files whenever needed. It can be specifically useful when doing coding demos during presentations. ## Features -After installing the extension, a new section called `CODE FRAGMENTS` is added to the Explorer, which shows a list of the previously saved fragments. -You can save a piece of code by selecting it in the editor, and then executing the "Save selection as Code Fragment" from the Command Palette (brought up with `Ctrl+Shift+P`) or in the context menu. +After installing the extension, a new section called `CODE FRAGMENTS` is added to the Explorer, which shows a list of the previously saved fragments. +You can save a piece of code by selecting it in the editor, and then executing the "Save selection as Code Fragment" from the Command Palette (brought up with `Ctrl+Shift+P`) or in the context menu. Clicking on an existing fragment in the list inserts its content into the editor at the current cursor position. Saving a selection as a Code Fragment: @@ -19,8 +19,16 @@ Inserting a Code Fragment to the current cursor position: ![Inserting Code Fragments.](images/codefragments-insert.gif) +Inserting a Code Fragment with typewriter effect: +![Typewriter Effect](images/typewriter-effect.gif) + +![Typewriter Effect Settings](images/typewriter-settings.png) + ## Release Notes +### 1.3.0? + +Add the capability to always ask for the name of the fragment on save (controlled by the `codeFragments.enableTypewriterEffect` setting). ### 1.2.0 Add the capability to always ask for the name of the fragment on save (controlled by the `codeFragments.askForNameOnCreate` setting) (#5). @@ -44,5 +52,5 @@ The icons are licensed under Freepik - Kirill Kazachek - Icon Works - + Downloaded from www.flaticon.com. \ No newline at end of file diff --git a/images/typewriter-effect.gif b/images/typewriter-effect.gif new file mode 100644 index 0000000..fca1c51 Binary files /dev/null and b/images/typewriter-effect.gif differ diff --git a/images/typewriter-settings.png b/images/typewriter-settings.png new file mode 100644 index 0000000..e216be2 Binary files /dev/null and b/images/typewriter-settings.png differ diff --git a/package.json b/package.json index d83498c..31fb223 100644 --- a/package.json +++ b/package.json @@ -119,6 +119,11 @@ "type": "boolean", "default": false, "description": "Prompt for specifying a name when creating a new fragment." + }, + "codeFragments.enableTypewriterEffect": { + "type": "boolean", + "default": false, + "description": "Enable/disable typewriter effect" } } } @@ -203,4 +208,4 @@ "typescript": "^2.6.1", "vscode": "^1.1.8" } -} +} \ No newline at end of file diff --git a/src/exporter.ts b/src/exporter.ts index 601aea2..012ccf3 100644 --- a/src/exporter.ts +++ b/src/exporter.ts @@ -108,8 +108,7 @@ export class Exporter { if (err) { reject(err); } - - resolve(); + resolve(null); }); }); } diff --git a/src/extension.ts b/src/extension.ts index 8aff8c3..d45c68d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,10 @@ import { CodeFragmentProvider, CodeFragmentTreeItem } from './codeFragmentsTreeI import { Exporter, ImportResult } from './exporter'; import { FragmentManager } from './fragmentManager'; +function wait(milliseconds: number) { + return new Promise(resolve => setTimeout(resolve, milliseconds)) +} + export async function activate(context: vscode.ExtensionContext) { const fragmentManager = new FragmentManager(context); const codeFragmentProvider = new CodeFragmentProvider(fragmentManager); @@ -63,9 +67,20 @@ export async function activate(context: vscode.ExtensionContext) { const content = fragmentManager.getFragmentContent(fragmentId); if (content) { - editor.edit(builder => { - builder.insert(editor.selection.start, content.content); - }); + const config = vscode.workspace.getConfiguration('codeFragments'); + if (!config.get('enableTypewriterEffect')) { + editor.edit(builder => { + builder.insert(editor.selection.start, content.content); + }); + } else { + let line = editor.selection.start.line; + let start = editor.selection.start.character; + [...content.content].reduce((promise: Promise, character: string, index: number) => + promise.then((_: any) => editor.edit(editBuilder => editBuilder.insert(new vscode.Position(line, start + index), character)) + .then(_ => { if (character === '\n') { line++ } }) + .then(_ => { return wait(100) }) + ), Promise.resolve()); + } } };