update plugin files

This commit is contained in:
REJack
2021-02-23 12:22:20 +01:00
parent d5f41bfd34
commit 1ac5eeaaa1
13 changed files with 255 additions and 180 deletions

View File

@@ -244,6 +244,7 @@
{ name: 'yank', shortName: 'y' },
{ name: 'delmarks', shortName: 'delm' },
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true },
{ name: 'vglobal', shortName: 'v' },
{ name: 'global', shortName: 'g' }
];
@@ -353,7 +354,7 @@
return cmd;
}
var modifiers = {'Shift': 'S', 'Ctrl': 'C', 'Alt': 'A', 'Cmd': 'D', 'Mod': 'A'};
var modifiers = {Shift:'S',Ctrl:'C',Alt:'A',Cmd:'D',Mod:'A',CapsLock:''};
var specialKeys = {Enter:'CR',Backspace:'BS',Delete:'Del',Insert:'Ins'};
function cmKeyToVimKey(key) {
if (key.charAt(0) == '\'') {
@@ -1450,7 +1451,7 @@
showPrompt(cm, {
onClose: onPromptClose,
prefix: promptPrefix,
desc: searchPromptDesc,
desc: '(JavaScript regexp)',
onKeyUp: onPromptKeyUp,
onKeyDown: onPromptKeyDown
});
@@ -4110,16 +4111,6 @@
var vim = cm.state.vim;
return vim.searchState_ || (vim.searchState_ = new SearchState());
}
function dialog(cm, template, shortText, onClose, options) {
if (cm.openDialog) {
cm.openDialog(template, onClose, { bottom: true, value: options.value,
onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp,
selectValueOnOpen: false});
}
else {
onClose(prompt(shortText, ''));
}
}
function splitBySlash(argString) {
return splitBySeparator(argString, '/');
}
@@ -4306,28 +4297,64 @@
(ignoreCase || forceIgnoreCase) ? 'i' : undefined);
return regexp;
}
function showConfirm(cm, text) {
/**
* dom - Document Object Manipulator
* Usage:
* dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>'])
* Examples:
* dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'}))
* dom(document.head, dom('script', 'alert("hello!")'))
* Not supported:
* dom('p', ['arrays are objects'], Error('objects specify attributes'))
*/
function dom(n) {
if (typeof n === 'string') n = document.createElement(n);
for (var a, i = 1; i < arguments.length; i++) {
if (!(a = arguments[i])) continue;
if (typeof a !== 'object') a = document.createTextNode(a);
if (a.nodeType) n.appendChild(a);
else for (var key in a) {
if (!Object.prototype.hasOwnProperty.call(a, key)) continue;
if (key[0] === '$') n.style[key.slice(1)] = a[key];
else n.setAttribute(key, a[key]);
}
}
return n;
}
function showConfirm(cm, template) {
var pre = dom('pre', {$color: 'red'}, template);
if (cm.openNotification) {
cm.openNotification('<span style="color: red">' + text + '</span>',
{bottom: true, duration: 5000});
cm.openNotification(pre, {bottom: true, duration: 5000});
} else {
alert(text);
alert(pre.innerText);
}
}
function makePrompt(prefix, desc) {
var raw = '<span style="font-family: monospace; white-space: pre">' +
(prefix || "") + '<input type="text" autocorrect="off" ' +
'autocapitalize="off" spellcheck="false"></span>';
if (desc)
raw += ' <span style="color: #888">' + desc + '</span>';
return raw;
return dom(document.createDocumentFragment(),
dom('span', {$fontFamily: 'monospace', $whiteSpace: 'pre'},
prefix,
dom('input', {type: 'text', autocorrect: 'off',
autocapitalize: 'off', spellcheck: 'false'})),
desc && dom('span', {$color: '#888'}, desc));
}
var searchPromptDesc = '(JavaScript regexp)';
function showPrompt(cm, options) {
var shortText = (options.prefix || '') + ' ' + (options.desc || '');
var prompt = makePrompt(options.prefix, options.desc);
dialog(cm, prompt, shortText, options.onClose, options);
var template = makePrompt(options.prefix, options.desc);
if (cm.openDialog) {
cm.openDialog(template, options.onClose, {
onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp,
bottom: true, selectValueOnOpen: false, value: options.value
});
}
else {
options.onClose(prompt(shortText, ''));
}
}
function regexEqual(r1, r2) {
if (r1 instanceof RegExp && r2 instanceof RegExp) {
var props = ['global', 'multiline', 'ignoreCase', 'source'];
@@ -4501,7 +4528,7 @@
if (start instanceof Array) {
return inArray(pos, start);
} else {
if (end) {
if (typeof end == 'number') {
return (pos >= start && pos <= end);
} else {
return pos == start;
@@ -4564,7 +4591,7 @@
try {
this.parseInput_(cm, inputStream, params);
} catch(e) {
showConfirm(cm, e);
showConfirm(cm, e.toString());
throw e;
}
var command;
@@ -4608,7 +4635,7 @@
params.callback();
}
} catch(e) {
showConfirm(cm, e);
showConfirm(cm, e.toString());
throw e;
}
},
@@ -4880,12 +4907,12 @@
registers: function(cm, params) {
var regArgs = params.args;
var registers = vimGlobalState.registerController.registers;
var regInfo = '----------Registers----------<br><br>';
var regInfo = '----------Registers----------\n\n';
if (!regArgs) {
for (var registerName in registers) {
var text = registers[registerName].toString();
if (text.length) {
regInfo += '"' + registerName + ' ' + text + '<br>';
regInfo += '"' + registerName + ' ' + text + '\n'
}
}
} else {
@@ -4897,7 +4924,7 @@
continue;
}
var register = registers[registerName] || new Register();
regInfo += '"' + registerName + ' ' + register.toString() + '<br>';
regInfo += '"' + registerName + ' ' + register.toString() + '\n'
}
}
showConfirm(cm, regInfo);
@@ -4992,6 +5019,10 @@
}
cm.replaceRange(text.join('\n'), curStart, curEnd);
},
vglobal: function(cm, params) {
// global inspects params.commandName
this.global(cm, params);
},
global: function(cm, params) {
// a global command is of the form
// :[range]g/pattern/[cmd]
@@ -5001,6 +5032,7 @@
showConfirm(cm, 'Regular Expression missing from global');
return;
}
var inverted = params.commandName[0] === 'v';
// range is specified here
var lineStart = (params.line !== undefined) ? params.line : cm.firstLine();
var lineEnd = params.lineEnd || params.line || cm.lastLine();
@@ -5025,28 +5057,33 @@
// now that we have the regexPart, search for regex matches in the
// specified range of lines
var query = getSearchState(cm).getQuery();
var matchedLines = [], content = '';
var matchedLines = [];
for (var i = lineStart; i <= lineEnd; i++) {
var matched = query.test(cm.getLine(i));
if (matched) {
matchedLines.push(i+1);
content+= cm.getLine(i) + '<br>';
var line = cm.getLineHandle(i);
var matched = query.test(line.text);
if (matched !== inverted) {
matchedLines.push(cmd ? line : line.text);
}
}
// if there is no [cmd], just display the list of matched lines
if (!cmd) {
showConfirm(cm, content);
showConfirm(cm, matchedLines.join('\n'));
return;
}
var index = 0;
var nextCommand = function() {
if (index < matchedLines.length) {
var command = matchedLines[index] + cmd;
var line = matchedLines[index++];
var lineNum = cm.getLineNumber(line);
if (lineNum == null) {
nextCommand();
return;
}
var command = (lineNum + 1) + cmd;
exCommandDispatcher.processCommand(cm, command, {
callback: nextCommand
});
}
index++;
};
nextCommand();
},
@@ -5066,9 +5103,11 @@
regexPart = new RegExp(regexPart).source; //normalize not escaped characters
}
replacePart = tokens[1];
if (regexPart && regexPart[regexPart.length - 1] === '$') {
regexPart = regexPart.slice(0, regexPart.length - 1) + '\\n';
replacePart = replacePart ? replacePart + '\n' : '\n';
// If the pattern ends with $ (line boundary assertion), change $ to \n.
// Caveat: this workaround cannot match on the last line of the document.
if (/(^|[^\\])(\\\\)*\$$/.test(regexPart)) {
regexPart = regexPart.slice(0, -1) + '\\n';
replacePart = (replacePart || '') + '\n';
}
if (replacePart !== undefined) {
if (getOption('pcre')) {
@@ -5097,11 +5136,9 @@
if (flagsPart) {
if (flagsPart.indexOf('c') != -1) {
confirm = true;
flagsPart.replace('c', '');
}
if (flagsPart.indexOf('g') != -1) {
global = true;
flagsPart.replace('g', '');
}
if (getOption('pcre')) {
regexPart = regexPart + '/' + flagsPart;
@@ -5242,7 +5279,7 @@
// Set up all the functions.
cm.state.vim.exMode = true;
var done = false;
var lastPos = searchCursor.from();
var lastPos, modifiedLineNumber, joined;
function replaceAll() {
cm.operation(function() {
while (!done) {
@@ -5255,14 +5292,18 @@
function replace() {
var text = cm.getRange(searchCursor.from(), searchCursor.to());
var newText = text.replace(query, replaceWith);
var unmodifiedLineNumber = searchCursor.to().line;
searchCursor.replace(newText);
modifiedLineNumber = searchCursor.to().line;
lineEnd += modifiedLineNumber - unmodifiedLineNumber;
joined = modifiedLineNumber < unmodifiedLineNumber;
}
function next() {
// The below only loops to skip over multiple occurrences on the same
// line when 'global' is not true.
while(searchCursor.findNext() &&
isInRange(searchCursor.from(), lineStart, lineEnd)) {
if (!global && lastPos && searchCursor.from().line == lastPos.line) {
if (!global && searchCursor.from().line == modifiedLineNumber && !joined) {
continue;
}
cm.scrollIntoView(searchCursor.from(), 30);
@@ -5327,7 +5368,7 @@
return;
}
showPrompt(cm, {
prefix: 'replace with <strong>' + replaceWith + '</strong> (y/n/a/q/l)',
prefix: dom('span', 'replace with ', dom('strong', replaceWith), ' (y/n/a/q/l)'),
onKeyDown: onPromptKeyDown
});
}
@@ -5535,9 +5576,7 @@
clearFakeCursor(vim);
// In visual mode, the cursor may be positioned over EOL.
if (from.ch == cm.getLine(from.line).length) {
var widget = document.createElement("span");
widget.textContent = "\u00a0";
widget.className = className;
var widget = dom('span', { 'class': className }, '\u00a0');
vim.fakeCursorBookmark = cm.setBookmark(from, {widget: widget});
} else {
vim.fakeCursor = cm.markText(from, to, {className: className});