-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a800e3
commit fbf2479
Showing
6 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nodejs 14.9.0 | ||
nodejs 16.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export function registerSymmetricModifiers(context: vscode.ExtensionContext){ | ||
context.subscriptions.push(vscode.commands. | ||
registerCommand('selection-utilities.insertAround', insertAround)); | ||
context.subscriptions.push(vscode.commands. | ||
registerCommand('selection-utilities.deleteAround', deleteAround)); | ||
context.subscriptions.push(vscode.commands. | ||
registerCommand('selection-utilities.adjustSelections', adjustSelections)); | ||
} | ||
|
||
interface InsertAroundArgs{ | ||
before: string, | ||
after: string | ||
} | ||
async function insertAround(args: InsertAroundArgs){ | ||
let editor = vscode.window.activeTextEditor; | ||
if(editor){ | ||
let ed = editor; | ||
let ranges = editor.selections.map(sel => | ||
new vscode.Range(sel.start, sel.end)); | ||
|
||
await editor.edit(builder => { | ||
for(const r of ranges){ | ||
builder.insert(r.start, args.before); | ||
builder.insert(r.end, args.after); | ||
} | ||
}); | ||
|
||
editor.selections = editor.selections.map(sel => { | ||
if(!sel.isReversed){ | ||
return new vscode.Selection( | ||
sel.anchor, | ||
sel.active.translate(0, -1), | ||
); | ||
}else{ | ||
return new vscode.Selection( | ||
sel.anchor.translate(0, -1), | ||
sel.active | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function deleteAround(args: {count?: number }){ | ||
let editor = vscode.window.activeTextEditor; | ||
if(editor){ | ||
let ed = editor; | ||
editor.edit(builder => { | ||
for(const sel of ed.selections){ | ||
builder.delete(new vscode.Range( | ||
sel.start.translate(0, -(args.count || 1)), | ||
sel.start) | ||
); | ||
builder.delete(new vscode.Range( | ||
sel.end, | ||
sel.end.translate(0, (args.count || 1))) | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function adjustSelections(args: {dir: string, count: number}){ | ||
let editor = vscode.window.activeTextEditor; | ||
let step = args.dir === 'forward' ? (args.count || 1) : -(args.count || 1); | ||
if(editor){ | ||
editor.selections = editor.selections.map(sel => { | ||
let sign = sel.isReversed ? -1 : 1; | ||
return new vscode.Selection( | ||
sel.anchor.translate(0, -sign*step), | ||
sel.active.translate(0, sign*step) | ||
); | ||
}); | ||
} | ||
} |