mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-09-11 12:25:59 +03:00
Added commands for 'go to last change' and 'insert at last change'.
This commit is contained in:
parent
1ef93e90ab
commit
44a5fc08be
@ -2119,6 +2119,39 @@ class CommandGoForwardInChangelist extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterAction
|
||||
class CommandGoLastChange extends BaseCommand {
|
||||
modes = [ModeName.Normal];
|
||||
keys = [['`', '.'], ["'", '.']];
|
||||
|
||||
public async exec(position: Position, vimState: VimState): Promise<VimState> {
|
||||
const lastPos = vimState.historyTracker.getLastHistoryStartPosition();
|
||||
|
||||
if (lastPos !== undefined) {
|
||||
vimState.cursorPosition = lastPos[0];
|
||||
}
|
||||
|
||||
return vimState;
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterAction
|
||||
class CommandInsertAtLastChange extends BaseCommand {
|
||||
modes = [ModeName.Normal];
|
||||
keys = ['g', 'i'];
|
||||
|
||||
public async exec(position: Position, vimState: VimState): Promise<VimState> {
|
||||
const lastPos = vimState.historyTracker.getLastChangeEndPosition();
|
||||
|
||||
if (lastPos !== undefined) {
|
||||
vimState.cursorPosition = lastPos;
|
||||
vimState.currentMode = ModeName.Insert;
|
||||
}
|
||||
|
||||
return vimState;
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterAction
|
||||
export class CommandInsertAtFirstCharacter extends BaseCommand {
|
||||
modes = [ModeName.Normal, ModeName.Visual];
|
||||
|
@ -548,6 +548,31 @@ export class HistoryTracker {
|
||||
return this.historySteps[this.currentHistoryStepIndex].cursorEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ending cursor position of the last Change of the last Step.
|
||||
*
|
||||
* In practice, this sets the cursor position to the end of
|
||||
* the most recent text change.
|
||||
*/
|
||||
getLastChangeEndPosition(): Position | undefined {
|
||||
if (this.currentHistoryStepIndex === 0) {
|
||||
return undefined;
|
||||
}
|
||||
let lastChangeIndex = this.historySteps[this.currentHistoryStepIndex].changes.length;
|
||||
if (lastChangeIndex === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return this.historySteps[this.currentHistoryStepIndex].changes[lastChangeIndex - 1].end();
|
||||
}
|
||||
|
||||
getLastHistoryStartPosition(): Position[] | undefined {
|
||||
if (this.currentHistoryStepIndex === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.historySteps[this.currentHistoryStepIndex].cursorStart;
|
||||
}
|
||||
|
||||
setLastHistoryEndPosition(pos: Position[]) {
|
||||
this.historySteps[this.currentHistoryStepIndex].cursorEnd = pos;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user