Skip to content

Commit

Permalink
Initial commit!
Browse files Browse the repository at this point in the history
(Welcome to the world, little buddy.)
  • Loading branch information
AdamMaras committed Dec 16, 2016
0 parents commit 1c73719
Show file tree
Hide file tree
Showing 17 changed files with 3,555 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Visual Studio Code
.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/settings.json
!.vscode/tasks.json

# Node.js
.eslintcache
.grunt
.lock-wscript
.node_repl_history
.npm
.nyc_output
.yarn-integrity
*.log
*.pid
*.pid.lock
*.seed
*.tgz
build/Release
coverage
jspm_packages
lib-cov
logs
node_modules
npm-debug.log*
pids

# Windows
$RECYCLE.BIN/
Desktop.ini
ehthumbs_vista.db
ehthumbs.db
Thumbs.db

# macOS
._*
.apdisk
.AppleDB
.AppleDesktop
.AppleDouble
.com.apple.timemachine.donotpresent
.DocumentRevisions-V100
.fseventsd
.LSOverride
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
*.DS_Store
Network Trash Folder
Temporary Items
Icon

# Linux
.directory
.nfs*
.Trash-*
*~

# Project
node_modules
out
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.exclude": {
"node_modules": true,
"out": true
},
"search.exclude": {
"node_modules": true,
"out": true
},
"typescript.tsdk": "./node_modules/typescript/lib"
}
9 changes: 9 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "silent",
"args": ["run", "compile", "--loglevel", "silent"],
"isWatching": true,
"problemMatcher": "$tsc-watch"
}
7 changes: 7 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/*
!images/icon.svg
!out/**/*
!CHANGELOG.md
!LICENSE
!package.json
!README.md
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

Notable and interesting changes will go in this file whenever a new release goes out. Boring changes will probably go in here too. Really, all changes are welcome.

## 0.1.0

Initial release of `vscode-overtype`. I take no responsibility if it formats your hard drive or punches you in the nose. (But if it does, please open an issue.)
10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Copyright (c) 2016, Adam Maras
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Overtype for Visual Studio Code

[![Visual Studio Marketplace](http://vsmarketplacebadge.apphb.com/version/adammaras.overtype.svg)](https://marketplace.visualstudio.com/items?itemName=adammaras.overtype)
[![GitHub release](https://img.shields.io/github/release/AdamMaras/vscode-overtype.svg)](https://github.com/AdamMaras/vscode-overtype/releases)
[![GitHub issues](https://img.shields.io/github/issues/AdamMaras/vscode-overtype.svg)](https://github.com/AdamMaras/vscode-overtype/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/AdamMaras/vscode-overtype.svg)](https://github.com/AdamMaras/vscode-overtype/pulls)
![README badges](https://img.shields.io/badge/readme_badges-5-green.svg)

Because some people actually press the Insert key on purpose.

## Features

Adds an overtype mode to Visual Studio Code, plus a couple of bells and whistles.

### Basic usage

The aptly named **overtype mode** allows one to type over and replace existing characters in one's text editor. The most common scenario for overtype mode is when it's activated by accident by an unsuspecting user who can't figure out why the computer is eating all the words they already typed.

To toggle overtype mode, press the `Insert` key. If you don't have an `Insert` key, you can press `Ctrl+Shift+I` (on Windows and Linux) or `Cmd+Shift+I` (on Mac). If you don't care for either of those keybindings, you can customize them in your Keyboard Shortcuts preferences—just set your own binding for the `overtype.toggle` command.

### Global or per-editor

It's bad enough that you have to keep track of that damn overtype indicator at the bottom of the window... but you want to have a separate overtype setting for *each editor?*

Fine.

```json
"overtype.perEditor": true
```

> Sets the insert/overtype mode per editor.
### Paste behavior

If you want to enable Hard Mode, you can turn on overtype paste mode. This setting applies overtype behavior to when you paste text into your editor. Here are the rules:

- If you paste part of a line of text into another line of text, the clipboard contents will overwrite characters until it's done pasting, unless it hits the end of the line first, in which case it'll just extend that line.
- If you already have some text selected when you paste, that text will *always* be overwritten, even if the contents of the clipboard are smaller.
- If you paste some multiline text into a line of text, everything left on that line will be overwritten with the first line of the pasted text, and the remaining pasted lines will be inserted below that line.
- If you cut or copy using Visual Studio Code's feature that grabs the entire line when you don't have anything selected, pasting that line will overwrite the *entire* line that you're pasting on.

Some additional tips for using overtype paste:

- Don't forget your Undo shortcut(s).
- I know this doesn't work like [insert editor here]. Every single freaking editor handles overtype paste differently. It's not my fault.
- If you think you have a saner way to handle this, for the love of everything warm and cuddly, [MAKE A PULL REQUEST](https://github.com/AdamMaras/vscode-overtype/pulls).

Without further ado...

```json
"overtype.paste": true
```

> Shows an abbreviated overtype status (`INS`/`OVR`) in the status line.
### Abbreviated indicators

Horizontal screen space at a premium? Have too many things in your status bar already? Turned your monitor sideways because somebody told you it would increase your productivity by at least 23%? Don't worry, we've got just the setting for you!

```json
"overtype.abbreviatedStatus": true
```

> When in overtype mode, uses overtype behavior when pasting text.
## Contributing

How can you contribute?

- [**Open an issue**](https://github.com/AdamMaras/vscode-overtype/issues) if you found a problem.
- [**Make a pull request**](https://github.com/AdamMaras/vscode-overtype/pulls) if you fixed a problem!
- [**Complain on Twitter**](https://twitter.com/AdamMaras) if *I'm* the problem.

## Release notes

There's a [`CHANGELOG.md`](https://github.com/AdamMaras/vscode-overtype/blob/master/CHANGELOG.md) file.

## License

There's a [`LICENSE`](https://github.com/AdamMaras/vscode-overtype/blob/master/LICENSE) file. It's the [BSD 2-Clause](https://opensource.org/licenses/BSD-2-Clause) license.
2,938 changes: 2,938 additions & 0 deletions images/icon.ai

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions images/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"name": "overtype",
"version": "0.1.0",
"displayName": "Overtype",
"description": "Provides insert/overtype mode.",
"publisher": "adammaras",
"categories": [
"Other"
],
"keywords": [
"overtype",
"overwrite",
"insert"
],
"icon": "images/icon.svg",
"galleryBanner": {
"color": "#1e1e1e",
"theme": "dark"
},
"license": "BSD-2-Clause",
"homepage": "https://github.com/AdamMaras/vscode-overtype",
"bugs": "https://github.com/AdamMaras/vscode-overtype/issues",
"repository": {
"type": "git",
"url": "https://github.com/AdamMaras/vscode-overtype.git"
},
"main": "./out/extension",
"engines": {
"vscode": "^1.0.0"
},
"activationEvents": [
"*"
],
"contributes": {
"configuration": {
"type": "object",
"title": "Overtype configuration",
"properties": {
"overtype.abbreviatedStatus": {
"type": "boolean",
"default": false,
"description": "Shows an abbreviated overtype status (INS/OVR) in the status line."
},
"overtype.paste": {
"type": "boolean",
"default": false,
"description": "When in overtype mode, uses overtype behavior when pasting text."
},
"overtype.perEditor": {
"type": "boolean",
"default": false,
"description": "Sets the insert/overtype mode per editor."
}
}
},
"commands": [
{
"command": "overtype.toggle",
"title": "Toggle Insert/Overtype"
}
],
"keybindings": [
{
"command": "overtype.toggle",
"key": "insert",
"when": "editorFocus"
},
{
"command": "overtype.toggle",
"key": "ctrl+shift+i",
"mac": "cmd+shift+i",
"when": "editorFocus"
}
]
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^2.1.0",
"vscode": "^1.0.0"
}
}
54 changes: 54 additions & 0 deletions src/behavior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as vscode from "vscode";

export function overtypeBeforeType(editor: vscode.TextEditor, text: string) {
// skip overtype behavior when enter is pressed
if (text == "\r" || text == "\n" || text == "\r\n") {
return;
}

editor.selections = editor.selections.map(selection => {
const cursorPosition = selection.start;
const lineEndPosition = editor.document.lineAt(cursorPosition).range.end;

if (selection.isEmpty && cursorPosition.character !== lineEndPosition.character) {
const replaceEnd = cursorPosition.with(cursorPosition.line, cursorPosition.character + 1);
const replaceSelection = new vscode.Selection(cursorPosition, replaceEnd);

return replaceSelection;
} else {
return selection;
}
});
}

export function overtypeBeforePaste(editor: vscode.TextEditor, text: string, pasteOnNewLine: boolean) {
editor.selections = editor.selections.map(selection => {
if (pasteOnNewLine) {
// highlight and replace all the selected lines

const startPosition = editor.document.lineAt(selection.start).rangeIncludingLineBreak.start;
let endPosition = editor.document.lineAt(selection.end).rangeIncludingLineBreak.end;

if (startPosition.isEqual(endPosition)) {
endPosition = endPosition.translate(1);
}

return new vscode.Selection(startPosition, endPosition);
} else {
// highlight the paste length or the end of the line, whichever's smaller

const selectionStartOffset = editor.document.offsetAt(selection.start);
const selectionEndOffset = editor.document.offsetAt(selection.end);
const selectionLength = selectionEndOffset - selectionStartOffset;

const lineEndOffset = editor.document.offsetAt(editor.document.lineAt(selection.end).range.end);
const lineEndLength = lineEndOffset - selectionStartOffset;

const hasNewLine = text.indexOf("\r") != -1 || text.indexOf("\n") != -1;
const newSelectionLength = Math.max(hasNewLine ? lineEndLength : Math.min(lineEndLength, text.length), selectionLength);
const newSelectionEndPosition = editor.document.positionAt(selectionStartOffset + newSelectionLength);

return new vscode.Selection(selection.start, newSelectionEndPosition);
}
});
}
Loading

0 comments on commit 1c73719

Please sign in to comment.