Skip to content

Commit

Permalink
Merge pull request #1338 from rebornix/1318
Browse files Browse the repository at this point in the history
Fix #1318
  • Loading branch information
johnfn authored Feb 28, 2017
2 parents 50e4d29 + 004f118 commit cfea890
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
36 changes: 28 additions & 8 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4504,6 +4504,15 @@ class ActionReplaceCharacter extends BaseCommand {
let timesToRepeat = vimState.recordedState.count || 1;
const toReplace = this.keysPressed[1];

/**
* <character> includes <BS>, <SHIFT+BS> and <TAB> but not any control keys,
* so we ignore the former two keys and have a special handle for <tab>.
*/

if (['<BS>', '<SHIFT+BS>'].indexOf(toReplace.toUpperCase()) >= 0) {
return vimState;
}

if (position.character + timesToRepeat > position.getLineEnd().character) {
return vimState;
}
Expand All @@ -4520,14 +4529,25 @@ class ActionReplaceCharacter extends BaseCommand {
endPos = new Position(endPos.line, endPos.character + 1);
}

vimState.recordedState.transformations.push({
type : "replaceText",
text : toReplace.repeat(timesToRepeat),
start : position,
end : endPos,
diff : new PositionDiff(0, timesToRepeat - 1),
});

if (toReplace === '<tab>') {
vimState.recordedState.transformations.push({
type: "deleteRange",
range: new Range(position, endPos)
});
vimState.recordedState.transformations.push({
type: "tab",
cursorIndex: this.multicursorIndex,
diff: new PositionDiff(0, -1)
});
} else {
vimState.recordedState.transformations.push({
type : "replaceText",
text : toReplace.repeat(timesToRepeat),
start : position,
end : endPos,
diff : new PositionDiff(0, timesToRepeat - 1),
});
}
return vimState;
}

Expand Down
15 changes: 15 additions & 0 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,21 @@ export class ModeHandler implements vscode.Disposable {
return vimState;
}
break;
case "tab":
await vscode.commands.executeCommand('tab');
if (command.diff) {
if (command.cursorIndex === undefined) {
throw new Error("No cursor index - this should never ever happen!");
}

if (!accumulatedPositionDifferences[command.cursorIndex]) {
accumulatedPositionDifferences[command.cursorIndex] = [];
}

accumulatedPositionDifferences[command.cursorIndex].push(command.diff);
}

break;
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/transformations/transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ export interface Dot {
type: "dot";
}

/**
* Represents Tab
*/
export interface Tab {
type: "tab";
cursorIndex?: number;

/**
* Move the cursor this much.
*/
diff: PositionDiff;
}

/**
* Represents macro
*/
Expand All @@ -211,7 +224,8 @@ export type Transformation
| ShowCommandLine
| Dot
| Macro
| DeleteTextTransformation;
| DeleteTextTransformation
| Tab;

/**
* Text Transformations
Expand Down

0 comments on commit cfea890

Please sign in to comment.