Skip to content

Commit 082329d

Browse files
committed
fix :'a,.y ex command
1 parent 8bbdd4a commit 082329d

1 file changed

Lines changed: 48 additions & 11 deletions

File tree

src/vim.js

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export function initVim(CM) {
298298
{ name: 'startinsert', shortName: 'start' },
299299
{ name: 'nohlsearch', shortName: 'noh' },
300300
{ name: 'yank', shortName: 'y' },
301+
{ name: 'put', shortName: 'pu' },
301302
{ name: 'delmarks', shortName: 'delm' },
302303
{ name: 'marks', excludeFromCommandHistory: true },
303304
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true },
@@ -1984,6 +1985,12 @@ export function initVim(CM) {
19841985
if (vim.visualMode) {
19851986
promptOptions.value = '\'<,\'>';
19861987
promptOptions.selectValueOnOpen = false;
1988+
} else {
1989+
var repeat = vim.inputState.getRepeat();
1990+
if (repeat > 1) {
1991+
promptOptions.value = '.,.+' + (repeat - 1);
1992+
promptOptions.selectValueOnOpen = false;
1993+
}
19871994
}
19881995
showPrompt(cm, promptOptions);
19891996
}
@@ -2906,6 +2913,9 @@ export function initVim(CM) {
29062913
vimGlobalState.registerController.pushText(
29072914
args.registerName, 'yank',
29082915
text, args.linewise, vim.visualBlock);
2916+
2917+
var lineCount = Math.abs(cm.getCursor("end").line - cm.getCursor("start").line) || 1;
2918+
showConfirm(cm, lineCount + ' lines yanked', false, 1500);
29092919
return endPos;
29102920
},
29112921
rot13: function(cm, args, ranges, oldAnchor, newHead) {
@@ -3296,7 +3306,7 @@ export function initVim(CM) {
32963306
if (actionArgs.repeat > 1) {
32973307
text = Array(actionArgs.repeat + 1).join(text);
32983308
}
3299-
var linewise = register.linewise;
3309+
var linewise = actionArgs.linewise == undefined ? register.linewise : actionArgs.linewise;
33003310
var blockwise = register.blockwise;
33013311
var textLines = blockwise ? text.split('\n') : undefined;
33023312
if (textLines) {
@@ -5293,8 +5303,8 @@ export function initVim(CM) {
52935303
return n;
52945304
}
52955305

5296-
/** @arg {CodeMirror} cm @arg {any} template @arg {boolean} [long]*/
5297-
function showConfirm(cm, template, long) {
5306+
/** @arg {CodeMirror} cm @arg {any} template @arg {boolean} [long] @arg {number} [duration]*/
5307+
function showConfirm(cm, template, long, duration) {
52985308
var pre = dom('div', {$color: 'red', $whiteSpace: 'pre', class: 'cm-vim-message'}, template);
52995309
if (cm.openNotification) {
53005310
if (long) {
@@ -5304,9 +5314,9 @@ export function initVim(CM) {
53045314
}
53055315
cm.state.closeVimNotification = cm.openNotification(pre, {bottom: true, duration: 0});
53065316
} else {
5307-
cm.openNotification(pre, {bottom: true, duration: 15000});
5317+
cm.openNotification(pre, {bottom: true, duration: duration || 15000});
53085318
}
5309-
} else {
5319+
} else if (!duration) {
53105320
alert(pre.innerText);
53115321
}
53125322
}
@@ -5713,6 +5723,7 @@ export function initVim(CM) {
57135723
result.selectionLineEnd = result.lineEnd;
57145724
}
57155725

5726+
inputStream.eatSpace();
57165727
// Parse command name.
57175728
var commandMatch = inputStream.match(/^(\w+|!!|@@|[!#&*<=>@~])/);
57185729
if (commandMatch) {
@@ -6370,13 +6381,39 @@ export function initVim(CM) {
63706381
nohlsearch: function(cm) {
63716382
clearSearchHighlight(cm);
63726383
},
6373-
/** @arg {CodeMirrorV} cm */
6374-
yank: function (cm) {
6375-
var cur = copyCursor(cm.getCursor());
6376-
var line = cur.line;
6377-
var lineText = cm.getLine(line);
6384+
/** @arg {CodeMirrorV} cm @arg {ExParams} params */
6385+
yank: function (cm, params) {
6386+
var line = params.selectionLine;
6387+
var lineEnd = isNaN(params.selectionLineEnd) ? line : params.selectionLineEnd;
6388+
if (lineEnd < line) {
6389+
var tmp = lineEnd;
6390+
lineEnd = line;
6391+
line = tmp;
6392+
}
6393+
var text = cm.getRange(new Pos(line, 0), new Pos(lineEnd + 1, 0));
63786394
vimGlobalState.registerController.pushText(
6379-
'0', 'yank', lineText, true, true);
6395+
'0', 'yank', text, true, false);
6396+
showConfirm(cm, (lineEnd + 1 - line) + ' lines yanked', false, 1500);
6397+
},
6398+
/** @arg {CodeMirrorV} cm @arg {ExParams} params @arg {boolean} [matchIndent]*/
6399+
put: function(cm, params, matchIndent) {
6400+
var actionArgs = { after: true, isEdit: true, matchIndent: !!matchIndent, repeat: 1, lineWise: true, registerName: '' };
6401+
var args = params.args || [];
6402+
if (args[0] == "!") {
6403+
actionArgs.after = false;
6404+
args.shift();
6405+
}
6406+
if (args[0]) {
6407+
actionArgs.registerName = args[0];
6408+
}
6409+
var line = params.selectionLine;
6410+
if (line != undefined)
6411+
cm.setCursor(new Pos(line, 0));
6412+
actions.paste(cm, actionArgs, cm.state.vim);
6413+
},
6414+
/** @arg {CodeMirrorV} cm @arg {ExParams} params*/
6415+
iput: function(cm, params) {
6416+
this.put(cm, params, true);
63806417
},
63816418
/** @arg {CodeMirrorV} cm @arg {ExParams} params*/
63826419
delete: function(cm, params) {

0 commit comments

Comments
 (0)