Skip to content

Commit 160a7fd

Browse files
authored
add marks ex command (#167)
1 parent 5a4bd87 commit 160a7fd

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/cm_adapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export class CodeMirror {
190190
vimPlugin?: any,
191191
vim?: vimState | null,
192192
currentNotificationClose?: Function | null,
193+
closeVimNotification?: Function | null,
193194
keyMap?: string,
194195
overwrite?: boolean,
195196
textwidth?: number,

src/vim.js

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export function initVim(CodeMirror) {
294294
{ name: 'nohlsearch', shortName: 'noh' },
295295
{ name: 'yank', shortName: 'y' },
296296
{ name: 'delmarks', shortName: 'delm' },
297+
{ name: 'marks', excludeFromCommandHistory: true },
297298
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true },
298299
{ name: 'vglobal', shortName: 'v' },
299300
{ name: 'delete', shortName: 'd' },
@@ -5078,22 +5079,30 @@ export function initVim(CodeMirror) {
50785079
return n;
50795080
}
50805081

5081-
/** @arg {CodeMirror} cm @arg {any} template */
5082-
function showConfirm(cm, template) {
5082+
/** @arg {CodeMirror} cm @arg {any} template @arg {boolean} [long]*/
5083+
function showConfirm(cm, template, long) {
50835084
var pre = dom('div', {$color: 'red', $whiteSpace: 'pre', class: 'cm-vim-message'}, template);
50845085
if (cm.openNotification) {
5085-
cm.openNotification(pre, {bottom: true, duration: 5000});
5086+
if (long) {
5087+
pre = dom('div', {}, pre, dom('div', {}, 'Press ENTER or type command to continue'));
5088+
if (cm.state.closeVimNotification) {
5089+
cm.state.closeVimNotification();
5090+
}
5091+
cm.state.closeVimNotification = cm.openNotification(pre, {bottom: true, duration: 0});
5092+
} else {
5093+
cm.openNotification(pre, {bottom: true, duration: 5000});
5094+
}
50865095
} else {
50875096
alert(pre.innerText);
50885097
}
50895098
}
50905099
/** @arg {string} prefix @arg {string} desc */
50915100
function makePrompt(prefix, desc) {
50925101
return dom('div', {$display: 'flex'},
5093-
dom('span', {$fontFamily: 'monospace', $whiteSpace: 'pre', $flex: 1},
5102+
dom('span', {$fontFamily: 'monospace', $whiteSpace: 'pre', $flex: 1, $display: 'flex'},
50945103
prefix,
50955104
dom('input', {type: 'text', autocorrect: 'off',
5096-
autocapitalize: 'off', spellcheck: 'false', $width: '100%'})),
5105+
autocapitalize: 'off', spellcheck: 'false', $flex: 1})),
50975106
desc && dom('span', {$color: '#888'}, desc));
50985107
}
50995108
/**
@@ -5786,7 +5795,31 @@ export function initVim(CodeMirror) {
57865795
regInfo += '"' + registerName + ' ' + register.toString() + '\n'
57875796
}
57885797
}
5789-
showConfirm(cm, regInfo);
5798+
showConfirm(cm, regInfo, true);
5799+
},
5800+
/** @arg {CodeMirrorV} cm @arg {ExParams} params*/
5801+
marks: function(cm, params) {
5802+
var filterArgs = params.args;
5803+
var marks = cm.state.vim.marks;
5804+
var regInfo = '-----------Marks-----------\nmark\tline\tcol\n\n';
5805+
if (!filterArgs) {
5806+
for (var name in marks) {
5807+
var marker = marks[name] && marks[name].find();
5808+
if (marker) {
5809+
regInfo += name + '\t' + marker.line + '\t' + marker.ch + '\n';
5810+
}
5811+
}
5812+
} else {
5813+
var registerNames = filterArgs.join('');
5814+
for (var i = 0; i < registerNames.length; i++) {
5815+
var name = registerNames.charAt(i);
5816+
var marker = marks[name] && marks[name].find();
5817+
if (marker) {
5818+
regInfo += name + '\t' + marker.line + '\t' + marker.ch + '\n';
5819+
}
5820+
}
5821+
}
5822+
showConfirm(cm, regInfo, true);
57905823
},
57915824
/** @arg {CodeMirrorV} cm @arg {ExParams} params*/
57925825
sort: function(cm, params) {
@@ -6713,6 +6746,16 @@ export function initVim(CodeMirror) {
67136746
var vim = vimApi.maybeInitVimState_(cm);
67146747
var visualBlock = vim.visualBlock || vim.wasInVisualBlock;
67156748

6749+
if (cm.state.closeVimNotification) {
6750+
var close = cm.state.closeVimNotification;
6751+
cm.state.closeVimNotification = null;
6752+
close();
6753+
if (key == '<CR>') {
6754+
clearInputState(cm);
6755+
return true;
6756+
}
6757+
}
6758+
67166759
var wasMultiselect = cm.isInMultiSelectMode();
67176760
if (vim.wasInVisualBlock && !wasMultiselect) {
67186761
vim.wasInVisualBlock = false;

0 commit comments

Comments
 (0)