Compare commits

...

3 Commits

Author SHA1 Message Date
jasonwilliams
fbf35b4e1d v0.6.0 2024-01-29 23:29:43 +00:00
jasonwilliams
7b9a1185d2 partial implementation of yank/paste 2024-01-29 23:29:01 +00:00
jasonwilliams
1bdab8436d - Clear selections on insert fixes #14
- Fix #15
2024-01-29 22:07:10 +00:00
4 changed files with 25 additions and 90 deletions

View File

@ -1,6 +1,6 @@
{
"name": "vscode-helix-emulation",
"version": "0.5.7",
"version": "0.6.0",
"displayName": "Helix For VS Code",
"description": "Helix emulation for Visual Studio Code",
"publisher": "jasew",

View File

@ -163,21 +163,21 @@ export const actions: Action[] = [
}),
parseKeysExact([KeyMap.Actions.NewLineBelow], [Mode.Normal], (vimState, editor) => {
vscode.commands.executeCommand('editor.action.insertLineAfter');
enterInsertMode(vimState);
vscode.commands.executeCommand('editor.action.insertLineAfter');
setModeCursorStyle(vimState.mode, editor);
removeTypeSubscription(vimState);
}),
parseKeysExact([KeyMap.Actions.NewLineAbove], [Mode.Normal], (vimState, editor) => {
vscode.commands.executeCommand('editor.action.insertLineBefore');
enterInsertMode(vimState);
vscode.commands.executeCommand('editor.action.insertLineBefore');
setModeCursorStyle(vimState.mode, editor);
removeTypeSubscription(vimState);
}),
parseKeysExact(['P'], [Mode.Normal, Mode.Visual, Mode.VisualLine], putAfter),
parseKeysExact(['p'], [Mode.Normal], putBefore),
parseKeysExact(['p'], [Mode.Normal, Mode.Visual, Mode.VisualLine], putAfter),
parseKeysExact(['P'], [Mode.Normal], putBefore),
parseKeysExact(['u'], [Mode.Normal, Mode.Visual, Mode.VisualLine], () => {
vscode.commands.executeCommand('undo');
@ -191,7 +191,7 @@ export const actions: Action[] = [
deleteLine(vimState, editor);
}),
parseKeysExact(['D'], [Mode.Normal], (vimState, editor) => {
parseKeysExact(['D'], [Mode.Normal], () => {
vscode.commands.executeCommand('deleteAllRight');
}),
@ -213,67 +213,6 @@ export const actions: Action[] = [
});
}),
// these allow you to the delete n lines above/below
// ex. d12i = delete 12 lines up
parseKeysRegex(
RegExp(`^d(\\d+)(${KeyMap.Motions.MoveUp}|${KeyMap.Motions.MoveDown})$`),
/^(d|d\d+)$/,
[Mode.Normal, Mode.Visual],
(vimState, editor, match) => {
const lineCount = parseInt(match[1]);
const direction = match[2] == KeyMap.Motions.MoveUp ? Direction.Up : Direction.Down;
// console.log(`delete ${lineCount} lines down`);
deleteLines(vimState, editor, lineCount, direction);
},
),
// same for change command
parseKeysRegex(
RegExp(`^c(\\d+)(${KeyMap.Motions.MoveUp}|${KeyMap.Motions.MoveDown})$`),
/^(c|c\d+)$/,
[Mode.Normal, Mode.Visual],
(vimState, editor, match) => {
const lineCount = parseInt(match[1]);
const direction = match[2] == KeyMap.Motions.MoveUp ? Direction.Up : Direction.Down;
// console.log(`delete ${lineCount} lines down`);
deleteLines(vimState, editor, lineCount, direction);
enterInsertMode(vimState);
setModeCursorStyle(vimState.mode, editor);
removeTypeSubscription(vimState);
},
),
// same for selection command
parseKeysRegex(
RegExp(`^s(\\d+)(${KeyMap.Motions.MoveUp}|${KeyMap.Motions.MoveDown})$`),
/^(s|s\d+)$/,
[Mode.Normal, Mode.Visual],
(vimState, editor, match) => {
const lineCount = parseInt(match[1]);
const direction = match[2] == KeyMap.Motions.MoveUp ? Direction.Up : Direction.Down;
// console.log(`delete ${lineCount} lines up`);
editor.selections = makeMultiLineSelection(vimState, editor, lineCount, direction);
},
),
// same for yank command
parseKeysRegex(
RegExp(`^y(\\d+)(${KeyMap.Motions.MoveUp}|${KeyMap.Motions.MoveDown})$`),
/^(y|y\d+)$/,
[Mode.Normal, Mode.Visual],
(vimState, editor, match) => {
const lineCount = parseInt(match[1]);
const direction = match[2] == KeyMap.Motions.MoveUp ? Direction.Up : Direction.Down;
// console.log(`delete ${lineCount} lines up`);
const selections = makeMultiLineSelection(vimState, editor, lineCount, direction);
yank(vimState, editor, selections, true);
flashYankHighlight(editor, selections);
},
),
// same for rip command
parseKeysRegex(
RegExp(`^r(\\d+)(${KeyMap.Motions.MoveUp}|${KeyMap.Motions.MoveDown})$`),
@ -346,14 +285,10 @@ export const actions: Action[] = [
flashYankHighlight(editor, highlightRanges);
}),
parseKeysExact(['Y'], [Mode.Normal], (vimState, editor) => {
yankToEndOfLine(vimState, editor);
parseKeysExact(['y'], [Mode.Normal, Mode.Visual], (vimState, editor) => {
// Yank highlight
const highlightRanges = editor.selections.map((selection) => {
const lineLength = editor.document.lineAt(selection.active.line).text.length;
return new vscode.Range(selection.active, selection.active.with({ character: lineLength }));
});
const highlightRanges = editor.selections.map((selection) => selection.with());
yank(vimState, editor, highlightRanges, false);
flashYankHighlight(editor, highlightRanges);
}),
@ -370,11 +305,6 @@ export const actions: Action[] = [
deleteLine(vimState, editor);
}),
parseKeysExact(['R'], [Mode.Normal], (vimState, editor) => {
yankToEndOfLine(vimState, editor);
vscode.commands.executeCommand('deleteAllRight');
}),
parseKeysExact(['s', 's'], [Mode.Normal], (vimState, editor) => {
editor.selections = editor.selections.map((selection) => {
return new vscode.Selection(
@ -506,12 +436,3 @@ function yankLine(vimState: HelixState, editor: vscode.TextEditor): void {
linewise: true,
};
}
function yankToEndOfLine(vimState: HelixState, editor: vscode.TextEditor): void {
vimState.registers = {
contentsList: editor.selections.map((selection) => {
return editor.document.lineAt(selection.active.line).text.substring(selection.active.character);
}),
linewise: false,
};
}

View File

@ -19,18 +19,26 @@ import { whitespaceWordRanges, wordRanges } from '../word_utils';
import KeyMap from './keymaps';
export const motions: Action[] = [
parseKeysExact([KeyMap.Motions.MoveRight], [Mode.Normal, Mode.Visual], (vimState, editor) => {
parseKeysExact([KeyMap.Motions.MoveRight], [Mode.Visual], (vimState, editor) => {
execMotion(vimState, editor, ({ document, position }) => {
return positionUtils.rightNormal(document, position, vimState.resolveCount());
});
}),
parseKeysExact([KeyMap.Motions.MoveLeft], [Mode.Normal, Mode.Visual], (vimState, editor) => {
parseKeysExact([KeyMap.Motions.MoveLeft], [Mode.Visual], (vimState, editor) => {
execMotion(vimState, editor, ({ position }) => {
return positionUtils.left(position, vimState.resolveCount());
});
}),
parseKeysExact([KeyMap.Motions.MoveRight], [Mode.Normal], () => {
vscode.commands.executeCommand('cursorRight');
}),
parseKeysExact([KeyMap.Motions.MoveLeft], [Mode.Normal], () => {
vscode.commands.executeCommand('cursorLeft');
}),
parseKeysExact([KeyMap.Motions.MoveUp], [Mode.Normal], (_vimState, _editor) => {
vscode.commands.executeCommand('cursorMove', {
to: 'up',

View File

@ -5,6 +5,12 @@ import { Mode } from './modes_types';
import { removeTypeSubscription } from './type_subscription';
export function enterInsertMode(helixState: HelixState): void {
// To fix https://github.com/jasonwilliams/vscode-helix/issues/14 we should clear selections on entering insert mode
// Helix doesn't clear selections on insert but doesn't overwrite the selection either, so our best option is to just clear them
const editor = helixState.editorState.activeEditor!;
const activeSelection = editor.selection.active;
editor.selections = [new vscode.Selection(activeSelection, activeSelection)];
helixState.mode = Mode.Insert;
setModeContext('extension.helixKeymap.insertMode');
helixState.commandLine.setText('', helixState);