Save insert-mode selections to jump back to them.

This commit is contained in:
Grégoire Geis 2021-05-17 21:12:34 +02:00
parent 7cebe0bed5
commit 1190132245
6 changed files with 28 additions and 90 deletions

View File

@ -155,6 +155,8 @@ A few changes were made from Kakoune, mostly out of personal preference, and to
make the extension integrate better with VS Code.
- The default yank register `"` maps to the system clipboard.
- Registers can have arbitrary names. If the name of a register starts with a
single space character, it will be local to the current document.
- When using the default configuration (that is to say, these settings can be
modified):
- The cursor is not a block, but a line: Dance focuses on selections, and

View File

@ -245,7 +245,13 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
additionalProperties: false,
},
default: {
insert: {},
insert: {
onLeaveMode: [
[".selections.save", {
register: " insert",
}],
],
},
normal: {
lineNumbers: "relative",
decorations: {
@ -439,7 +445,8 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
},
".": {
text: "to last buffer modification position",
command: "dance.select.lastModification",
command: "dance.selections.restore",
args: [{ register: " insert" }],
},
},
},

45
package.json generated
View File

@ -278,7 +278,16 @@
"additionalProperties": false
},
"default": {
"insert": {},
"insert": {
"onLeaveMode": [
[
".selections.save",
{
"register": " insert"
}
]
]
},
"normal": {
"lineNumbers": "relative",
"decorations": {
@ -560,7 +569,12 @@
},
".": {
"text": "to last buffer modification position",
"command": "dance.select.lastModification"
"command": "dance.selections.restore",
"args": [
{
"register": " insert"
}
]
}
}
},
@ -1333,21 +1347,6 @@
"title": "Jump to last line",
"category": "Dance"
},
{
"command": "dance.select.lastModification",
"title": "Select to last modification",
"category": "Dance"
},
{
"command": "dance.select.lastModification.extend",
"title": "Extend to last modification",
"category": "Dance"
},
{
"command": "dance.select.lastModification.jump",
"title": "Jump to last modification",
"category": "Dance"
},
{
"command": "dance.select.lastVisibleLine",
"title": "Select to last visible line",
@ -2140,18 +2139,6 @@
"command": "dance.select.lastLine.jump",
"when": "dance.mode == 'normal'"
},
{
"command": "dance.select.lastModification",
"when": "dance.mode == 'normal'"
},
{
"command": "dance.select.lastModification.extend",
"when": "dance.mode == 'normal'"
},
{
"command": "dance.select.lastModification.jump",
"when": "dance.mode == 'normal'"
},
{
"command": "dance.select.lastVisibleLine",
"when": "dance.mode == 'normal'"

16
src/commands/README.md generated
View File

@ -114,11 +114,10 @@
<tr><td><a href="./seek.ts#L178"><code>seek.wordEnd.ws</code></a></td><td>Select to next non-whitespace word end</td><td><code>Alt+E</code> (<code>editorTextFocus && dance.mode == 'normal'</code>)</td></tr>
<tr><td><a href="./seek.ts#L179"><code>seek.wordEnd.ws.extend</code></a></td><td>Extend to next non-whitespace word end</td><td><code>Shift+Alt+E</code> (<code>editorTextFocus && dance.mode == 'normal'</code>)</td></tr>
<tr><td><a href="#seekword"><code>seek.word</code></a></td><td>Select to next word start</td><td><code>W</code> (<code>editorTextFocus && dance.mode == 'normal'</code>)</td></tr>
<tr><td rowspan=44><a href="#select"><code>select</code></a></td><td><a href="#selectbuffer"><code>select.buffer</code></a></td><td>Select whole buffer</td><td><code>Shift+5</code> (<code>editorTextFocus && dance.mode == 'normal'</code>)</td></tr>
<tr><td rowspan=41><a href="#select"><code>select</code></a></td><td><a href="#selectbuffer"><code>select.buffer</code></a></td><td>Select whole buffer</td><td><code>Shift+5</code> (<code>editorTextFocus && dance.mode == 'normal'</code>)</td></tr>
<tr><td><a href="#selectfirstVisibleLine"><code>select.firstVisibleLine</code></a></td><td>Select to first visible line</td><td></td></tr>
<tr><td><a href="#selecthorizontally"><code>select.horizontally</code></a></td><td>Select horizontally</td><td></td></tr>
<tr><td><a href="#selectlastLine"><code>select.lastLine</code></a></td><td>Select to last line</td><td></td></tr>
<tr><td><a href="#selectlastModification"><code>select.lastModification</code></a></td><td>Select to last modification</td><td></td></tr>
<tr><td><a href="#selectlastVisibleLine"><code>select.lastVisibleLine</code></a></td><td>Select to last visible line</td><td></td></tr>
<tr><td><a href="#selectlineabove"><code>select.line.above</code></a></td><td>Select line above</td><td></td></tr>
<tr><td><a href="#selectlineaboveextend"><code>select.line.above.extend</code></a></td><td>Extend to line above</td><td></td></tr>
@ -137,8 +136,6 @@
<tr><td><a href="./select.ts#L543"><code>select.firstVisibleLine.jump</code></a></td><td>Jump to first visible line</td><td></td></tr>
<tr><td><a href="./select.ts#L523"><code>select.lastLine.extend</code></a></td><td>Extend to last line</td><td></td></tr>
<tr><td><a href="./select.ts#L522"><code>select.lastLine.jump</code></a></td><td>Jump to last line</td><td></td></tr>
<tr><td><a href="./select.ts#L595"><code>select.lastModification.extend</code></a></td><td>Extend to last modification</td><td></td></tr>
<tr><td><a href="./select.ts#L594"><code>select.lastModification.jump</code></a></td><td>Jump to last modification</td><td></td></tr>
<tr><td><a href="./select.ts#L578"><code>select.lastVisibleLine.extend</code></a></td><td>Extend to last visible line</td><td></td></tr>
<tr><td><a href="./select.ts#L577"><code>select.lastVisibleLine.jump</code></a></td><td>Jump to last visible line</td><td></td></tr>
<tr><td><a href="./select.ts#L212"><code>select.left.extend</code></a></td><td>Extend left</td><td><code>Shift+H</code> (<code>editorTextFocus && dance.mode == 'normal'</code>)<code>Shift+Left</code> (<code>editorTextFocus && dance.mode == 'normal'</code>)</td></tr>
@ -941,17 +938,6 @@ Select to last visible line.
| Jump to last visible line | `lastVisibleLine.jump` | `[".select.lastVisibleLine", { shift: "jump" }]` |
| Extend to last visible line | `lastVisibleLine.extend` | `[".select.lastVisibleLine", { shift: "extend" }]` |
### [`select.lastModification`](./select.ts#L587-L597)
Select to last modification.
#### Variants
| Title | Identifier | Command |
| --------------------------- | ------------------------- | --------------------------------------------------- |
| Jump to last modification | `lastModification.jump` | `[".select.lastModification", { shift: "jump" }]` |
| Extend to last modification | `lastModification.extend` | `[".select.lastModification", { shift: "extend" }]` |
## [`selections`](./selections.ts)
Interacting with selections.

View File

@ -788,7 +788,6 @@ async function loadSelectModule(): Promise<CommandDescriptor[]> {
firstVisibleLine,
horizontally,
lastLine,
lastModification,
lastVisibleLine,
lineEnd,
lineStart,
@ -822,11 +821,6 @@ async function loadSelectModule(): Promise<CommandDescriptor[]> {
(_, argument) => _.runAsync((_) => lastLine(_, _.document, getShift(argument))),
CommandDescriptor.Flags.RequiresActiveEditor,
),
new CommandDescriptor(
"dance.select.lastModification",
(_, argument) => _.runAsync((_) => lastModification(_, getShift(argument))),
CommandDescriptor.Flags.RequiresActiveEditor,
),
new CommandDescriptor(
"dance.select.lastVisibleLine",
(_, argument) => _.runAsync((_) => lastVisibleLine(_, getShift(argument))),
@ -927,16 +921,6 @@ async function loadSelectModule(): Promise<CommandDescriptor[]> {
(_, argument) => _.runAsync(() => commands([".select.lastLine", { shift: "jump", ...argument }])),
CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay,
),
new CommandDescriptor(
"dance.select.lastModification.extend",
(_, argument) => _.runAsync(() => commands([".select.lastModification", { shift: "extend", ...argument }])),
CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay,
),
new CommandDescriptor(
"dance.select.lastModification.jump",
(_, argument) => _.runAsync(() => commands([".select.lastModification", { shift: "jump", ...argument }])),
CommandDescriptor.Flags.RequiresActiveEditor | CommandDescriptor.Flags.DoNotReplay,
),
new CommandDescriptor(
"dance.select.lastVisibleLine.extend",
(_, argument) => _.runAsync(() => commands([".select.lastVisibleLine", { shift: "extend", ...argument }])),

View File

@ -583,31 +583,3 @@ export function lastVisibleLine(_: Context, shift = Shift.Select) {
Selections.set([Selections.shift(selection, toPosition, shift)]);
}
/**
* Select to last modification.
*
* #### Variants
*
* | Title | Identifier | Command |
* | --------------------------- | ------------------------- | --------------------------------------------------- |
* | Jump to last modification | `lastModification.jump` | `[".select.lastModification", { shift: "jump" }]` |
* | Extend to last modification | `lastModification.extend` | `[".select.lastModification", { shift: "extend" }]` |
*/
export function lastModification(_: Context, shift = Shift.Select) {
todo();
/*const cursor = _.extension.recorder.cursorFromEnd();
while (cursor.previous()) {
if (cursor.is(Entry)) {
const position = _.document.positionAt(cursor.absoluteOffset());
Selections.set([Selections.shift(_.mainSelection, position, shift)]);
return;
}
if (cursor.is(Recording.ActionType.TextEditorChange)) {
return;
}
}*/
}