Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all selections shrinkable #493

Merged
merged 3 commits into from Dec 2, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -2,6 +2,8 @@
Changes to Calva.

## [Unreleased]
- [Make all Paredit selection commands shrinkable](https://www.reddit.com/r/Clojure/comments/e3zni2/a_paredit_visual_guide_calvas_paredit_docs/f9e7ujq/)
- Fix: [Raise Sexp/Form needs updated doc and shortcut keys](https://github.com/BetterThanTomorrow/calva/issues/495)

## [2.0.64] - 2019-12-01
- [Add Paredit commands **Push Form Left/right**](https://www.reddit.com/r/Clojure/comments/e3zni2/a_paredit_visual_guide_calvas_paredit_docs/f95v24w/)
Binary file not shown.
Binary file not shown.
@@ -61,11 +61,11 @@ Default keybinding | Action | Description
Default keybinding | Action | Description
------------------ | ------ | -----------
`ctrl+w` | **Expand Selection** | Starts from the cursor and selects the current form. Then will keep expanding to enclosing forms.<br> ![](_static/images/paredit/grow-selection.gif)
`ctrl+shift+w` | **Shrink Selection** | Contracts back from an expanded selection.<br> ![](_static/images/paredit/shrink-selection.gif)
`ctrl+alt+w space` | **Select Current Top Level Form** | Top level in a structural sence. Typically where your`(def ...)`/`(defn ...)` type forms. Please note that`(comment ...)` forms create a new top level.<br> ![](_static/images/paredit/select-top-level-form.gif)
`ctrl+shift+w` | **Shrink Selection** | Contracts back from an expanded selection performed by any Paredit selection command.<br> ![](_static/images/paredit/shrink-selection.gif)<br>(In the animation the selection is first grown using a combination of **Grow Selection** and some lateral selection commands, then shrunk all the way back down to no selection.)
`ctrl+alt+w space` | **Select Top Level Form** | Top level in a structural sence. Typically where your`(def ...)`/`(defn ...)` type forms. Please note that`(comment ...)` forms create a new top level. <br> ![](_static/images/paredit/select-top-level-form.gif)


The selecting ”versions” of the navigation commands above:
The selecting ”versions” of the navigation commands above. They will all grow whatever current selection as far as the **Shrink Selection** command is concerned.

Default keybinding | Action | Description
------------------ | ------ | --------------
@@ -88,15 +88,15 @@ Default keybinding | Action | Description
`ctrl+left` | **Barf Forward** | Moves the _closing_ bracket _backward_, _towards_ the cursor, past the preceding form. <br> ![](_static/images/paredit/barf-forward.gif)
`ctrl+shift+left` | **Slurp Backward** | Moves the _opening_ bracket _backward_, _away_ from the cursor, past the preceding form, if any. <br> ![](_static/images/paredit/slurp-backward.gif)
`ctrl+shift+right` | **Barf Backward** | Moves the _opening_ bracket _forward_, _towards_ the cursor, past the following form. <br> ![](_static/images/paredit/barf-backward.gif)
`ctrl+alt+s` | **Splice Current Sexp/Form** | Remove enclosing brackets. <br> ![](_static/images/paredit/splice.gif)
`ctrl+shift+s` | **Split Current Sexp/Form** | Splits a string, or a list, into two strings, or lists of the same type as the current. <br> ![](_static/images/paredit/split.gif)
`ctrl+alt+s` | **Splice Sexp** | Remove enclosing brackets. <br> ![](_static/images/paredit/splice.gif)
`ctrl+shift+s` | **Split Sexp** | Splits a string, or a list, into two strings, or lists of the same type as the current. <br> ![](_static/images/paredit/split.gif)
`ctrl+shift+j` | **Join Sexps/Forms** | Joins two strings, or two lists of the same type, into one form (string/list). <br> ![](_static/images/paredit/join.gif)
`ctrl+alt+p ctrl+alt+r` | **Raise Current Sexp/Form** | Replaces the enclosing list with the current form. <br> ![](_static/images/paredit/raise.gif)
`ctrl+alt+p ctrl+alt+r` | **Raise Sexp** | Replaces the enclosing list with the current form. <br> ![](_static/images/paredit/raise.gif)
`ctrl+alt+t` | **Transpose Sexps/Forms** | Swaps place of the two forms surrounding the cursor. <br> ![](_static/images/paredit/transpose.gif)
`ctrl+alt+shift` `l`<br> `ctrl+alt+shift` `r` | **Push Sexp/Form Left/Right** | Moves the current form to the left/right of the previous/next one. <br> ![](_static/images/paredit/left-right.gif)
`ctrl+shift+c` | **Convolute Current Sexp/Form** | ¯\\\_(ツ)_/¯ <br> ![](_static/images/paredit/convolute.gif)
`ctrl+shift+delete` | **Kill Sexp/Form Forward** | Deletes the next form in the same enclosing form as the cursor.<br> ![](_static/images/paredit/kill-forward-sexp.gif)
`ctrl+alt+backspace` | **Kill Sexp/Form Backward** | Deletes the previous form in the same enclosing form as the cursor.<br> ![](_static/images/paredit/kill-backward-sexp.gif)
`ctrl+alt+shift` `l`<br> `ctrl+alt+shift` `r` | **Push Sexp Left/Right** | Moves the current form to the left/right of the previous/next one. <br> ![](_static/images/paredit/left-right.gif)
`ctrl+shift+c` | **Convolute** | ¯\\\_(ツ)_/¯ <br> ![](_static/images/paredit/convolute.gif)
`ctrl+shift+delete` | **Kill Sexp Forward** | Deletes the next form in the same enclosing form as the cursor.<br> ![](_static/images/paredit/kill-forward-sexp.gif)
`ctrl+alt+backspace` | **Kill Sexp Backward** | Deletes the previous form in the same enclosing form as the cursor.<br> ![](_static/images/paredit/kill-backward-sexp.gif)
`ctrl+delete` | **Kill List Forward** | Deletes everything from the cursor to the closing of the current enclosing form.<br> ![](_static/images/paredit/kill-close-list.gif)
`ctrl+backspace` | **Kill List Backward** | Deletes everything from the cursor to the opening of the current enclosing form.<br> ![](_static/images/paredit/kill-open-list.gif)
`ctrl+alt+shift+delete` | **Splice Killing Forward** | Delete forward to end of the list, then Splice. <br> ![](_static/images/paredit/splice-killing-forward.gif)
@@ -105,7 +105,7 @@ Default keybinding | Action | Description
`ctrl+alt+shift+s` | **Wrap Around []** | Wraps the current form, or selection, with square brackets. <br> ![](_static/images/paredit/wrap-around-brackets.gif)
`ctrl+alt+shift+c` | **Wrap Around {}** | Wraps the current form, or selection, with curlies. <br> ![](_static/images/paredit/wrap-around-curlies.gif)
`ctrl+alt+shift+q` | **Wrap Around ""** | Wraps the current form, or selection, with double quotes. Inside strings it will quote the quotes. <br> ![](_static/images/paredit/wrap-around-quotes.gif)
`ctrl+alt+r`<br>`p`/`s`/`c`/`q` | **Rewrap** | Changes enclosing brackets of the current form to parens/square brackets/curlies/double quotes.. <br> ![](_static/images/paredit/rewrap.gif)
`ctrl+alt+r`<br>`ctrl+alt+p`/`s`/`c`/`q` | **Rewrap** | Changes enclosing brackets of the current form to parens/square brackets/curlies/double quotes.. <br> ![](_static/images/paredit/rewrap.gif)
## About the Keyboard Shortcuts
@@ -812,32 +812,32 @@
{
"category": "Calva Paredit",
"command": "paredit.forwardSexp",
"title": "Forward Sexp/Form"
"title": "Forward Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.backwardSexp",
"title": "Backward Sexp/Form"
"title": "Backward Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.forwardDownSexp",
"title": "Forward Down Sexp/Form"
"title": "Forward Down Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.backwardDownSexp",
"title": "Backward Down Sexp/Form"
"title": "Backward Down Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.backwardUpSexp",
"title": "Backward Up Sexp/Form"
"title": "Backward Up Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.forwardUpSexp",
"title": "Forward Up Sexp/Form"
"title": "Forward Up Sexp"
},
{
"category": "Calva Paredit",
@@ -852,32 +852,32 @@
{
"category": "Calva Paredit",
"command": "paredit.selectForwardSexp",
"title": "Select Forward Sexp/Form"
"title": "Select Forward Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.selectBackwardSexp",
"title": "Select Backward Sexp/Form"
"title": "Select Backward Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.selectForwardDownSexp",
"title": "Select Forward Down Sexp/Form"
"title": "Select Forward Down Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.selectBackwardDownSexp",
"title": "Select Backward Down Sexp/Form"
"title": "Select Backward Down Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.selectBackwardUpSexp",
"title": "Select Backward Up Sexp/Form"
"title": "Select Backward Up Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.selectForwardUpSexp",
"title": "Select Forward Up Sexp/Form"
"title": "Select Forward Up Sexp"
},
{
"category": "Calva Paredit",
@@ -907,72 +907,72 @@
{
"category": "Calva Paredit",
"command": "paredit.slurpSexpForward",
"title": "Slurp Sexp/Form Forward"
"title": "Slurp Sexp Forward"
},
{
"category": "Calva Paredit",
"command": "paredit.slurpSexpBackward",
"title": "Slurp Sexp/Form Backward"
"title": "Slurp Sexp Backward"
},
{
"category": "Calva Paredit",
"command": "paredit.barfSexpForward",
"title": "Barf Sexp/Form Forward"
"title": "Barf Sexp Forward"
},
{
"category": "Calva Paredit",
"command": "paredit.barfSexpBackward",
"title": "Barf Sexp/Form Backward"
"title": "Barf Sexp Backward"
},
{
"category": "Calva Paredit",
"command": "paredit.spliceSexp",
"title": "Splice Sexp/Form"
"title": "Splice Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.splitSexp",
"title": "Split Sexp/Form"
"title": "Split Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.joinSexp",
"title": "Join Sexp/Form"
"title": "Join Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.raiseSexp",
"title": "Raise Sexp/Form"
"title": "Raise Sexp"
},
{
"category": "Calva Paredit",
"command": "paredit.transpose",
"title": "Transpose (Swap) the two Sexp/Forms Around the Cursor"
"title": "Transpose (Swap) the two Sexps Around the Cursor"
},
{
"category": "Calva Paredit",
"command": "paredit.pushSexprLeft",
"title": "Push Sexp/Form Left"
"title": "Push Sexp Left"
},
{
"category": "Calva Paredit",
"command": "paredit.pushSexprRight",
"title": "Push Sexp/Form Right"
"title": "Push Sexp Right"
},
{
"category": "Calva Paredit",
"command": "paredit.convolute",
"title": "Convolute Sexp/Form ¯\\_(ツ)_/¯"
"title": "Convolute Sexp ¯\\_(ツ)_/¯"
},
{
"category": "Calva Paredit",
"command": "paredit.killSexpForward",
"title": "Kill/Delete Sexp/Form Forward"
"title": "Kill/Delete Sexp Forward"
},
{
"category": "Calva Paredit",
"command": "paredit.killSexpBackward",
"title": "Kill/Delete Sexp/Form Backward"
"title": "Kill/Delete Sexp Backward"
},
{
"category": "Calva Paredit",
@@ -1457,7 +1457,7 @@
},
{
"command": "calva-fmt.inferParens",
"key": "ctrl+alt+p",
"key": "ctrl+alt+f ctrl+alt+p",
"when": "editorLangId == clojure && editorTextFocus && !editorReadOnly && !suggestWidgetVisible && !hasOtherSuggestions"
},
{
@@ -14,7 +14,7 @@ A Clojure and ClojureScript formatter for Visual Studio Code.
* Formats the code when new lines are entered, mostly keeping things formated as you type.
* Adds a command for formatting the enclosing form, default key binding is `tab`.
* Adds a command for aligning map items, and bindings in the current form, default key binding `ctrl+alt+l`. (This is a bit experimental and will not always produce the prettiest results. Also it is recursive.) You can also opt-in to have this behaviour be on for all formatting, via settings.
* Adds a command for infering parens/brackets from indents (using ParinferLib), default key binding `ctrl+alt+p`.
* Adds a command for infering parens/brackets from indents (using ParinferLib), default key binding `ctrl+alt+f ctrl+alt+p`.
* Adds a command for indenting and dedenting the current line (using ParinferLib), default key binding `ctrl+i` and `shift+ctrl+i`, respectively.
* Provides the formater for the VSCode *Format Selection* and *Format Document* commands as well as for *Format on Paste*.
* Is intended to be used alongside and by other Clojure extensions.
@@ -89,7 +89,7 @@ export interface EditableDocument {
selectionEnd: number,
selection: { anchor: number, active: number },
model: EditableModel,
growSelectionStack: [number, number][],
growSelectionStack: { anchor: number, active: number }[],
getTokenCursor: (offset?: number, previous?: boolean) => LispTokenCursor,
insertString: (text: string) => void,
getSelectionText: () => string,
@@ -22,15 +22,18 @@ export function moveToRangeEnd(doc: EditableDocument, range: [number, number]) {
}

export function selectRange(doc: EditableDocument, range: [number, number]) {
doc.selection = { anchor: range[0], active: range[1] };
// doc.selection = { anchor: range[0], active: range[1] };
growSelectionStack(doc, range)
}

export function selectRangeFromSelectionStart(doc: EditableDocument, range: [number, number]) {
doc.selection = { anchor: doc.selectionStart, active: range[1] };
// doc.selection = { anchor: doc.selectionStart, active: range[1] };
growSelectionStack(doc, [doc.selectionStart, range[1]])
}

export function selectRangeFromSelectionEnd(doc: EditableDocument, range: [number, number]) {
doc.selection = { anchor: doc.selectionEnd, active: range[0] };
// doc.selection = { anchor: doc.selectionEnd, active: range[0] };
growSelectionStack(doc, [doc.selectionEnd, range[0]])
}


@@ -480,25 +483,25 @@ export function growSelection(doc: EditableDocument, start: number = doc.selecti
}
}

function growSelectionStack(doc: EditableDocument, range: [number, number]) {
export function growSelectionStack(doc: EditableDocument, range: [number, number]) {
const [start, end] = range;
if (doc.growSelectionStack.length > 0) {
const [prevStart, prevEnd] = doc.growSelectionStack[doc.growSelectionStack.length - 1];
if (!(doc.selectionStart == prevStart && doc.selectionEnd == prevEnd)) {
doc.growSelectionStack = [[doc.selectionStart, doc.selectionEnd]];
const prev = doc.growSelectionStack[doc.growSelectionStack.length - 1];
if (!(doc.selectionStart == prev.anchor && doc.selectionEnd == prev.active)) {
doc.growSelectionStack = [doc.selection];
}
} else {
doc.growSelectionStack = [[doc.selectionStart, doc.selectionEnd]];
doc.growSelectionStack = [doc.selection];
}
doc.growSelectionStack.push(range);
[doc.selectionStart, doc.selectionEnd] = [start, end];
doc.selection = { anchor: start, active: end };
doc.growSelectionStack.push(doc.selection);
}

export function shrinkSelection(doc: EditableDocument) {
if (doc.growSelectionStack.length) {
let [stackStart, stackEnd] = doc.growSelectionStack.pop();
if (doc.growSelectionStack.length && stackStart == doc.selectionStart && stackEnd == doc.selectionEnd) {
[doc.selectionStart, doc.selectionEnd] = doc.growSelectionStack[doc.growSelectionStack.length - 1];
let latest = doc.growSelectionStack.pop();
if (doc.growSelectionStack.length && latest.anchor == doc.selectionStart && latest.active == doc.selectionEnd) {
doc.selection = doc.growSelectionStack[doc.growSelectionStack.length - 1];
}
}
}
@@ -106,7 +106,7 @@ class MirroredDocument implements EditableDocument {

model = new DocumentModel(this);

growSelectionStack: [number, number][] = [];
growSelectionStack: { anchor: number, active: number }[] = [];

public getTokenCursor(offset: number = this.selectionEnd, previous: boolean = false): LispTokenCursor {
return this.model.getTokenCursor(offset, previous);
@@ -132,6 +132,10 @@ class MirroredDocument implements EditableDocument {
editor.revealRange(new vscode.Range(active, active));
}

get selection(): { anchor: number, active: number } {
return { anchor: this.selectionStart, active: this.selectionEnd };
}

public getSelectionText() {
const editor = vscode.window.activeTextEditor,
selection = editor.selection;
@@ -61,6 +61,10 @@ export class ReplReadline implements EditableDocument {
this.selectionEnd = selection.active;
}

get selection(): { anchor: number, active: number} {
return { anchor: this.selectionStart, active: this.selectionEnd}
}

/** The offset of the end of the selection into the document. */
private _selectionEnd: number = 0;

@@ -721,7 +725,7 @@ export class ReplReadline implements EditableDocument {
this.freeze();
}

growSelectionStack: [number, number][] = [];
growSelectionStack: { anchor: number, active: number}[] = [];
}

/**
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.