Skip to content

Commit da5c4fb

Browse files
committed
fix search register
1 parent 83593bb commit da5c4fb

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

dev/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,7 @@ window.onunload = function() {
346346
saveHistory('exCommandHistoryController');
347347
saveHistory('searchHistoryController');
348348
}
349+
350+
Vim.defineEx("write", "w", (cm) => {
351+
console.log("called", cm);
352+
})

src/cm_adapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export class CodeMirror {
164164

165165
static lookupKey = function lookupKey(key: string, map: string, handle: Function) {
166166
var result = CodeMirror.keys[key];
167+
if (!result && /^Arrow/.test(key)) result = CodeMirror.keys[key.slice(5)];
167168
if (result) handle(result);
168169
};
169170

src/vim.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function initVim(CM) {
5353
* @typedef { import("./types").Marker } Marker
5454
* @typedef { import("./types").InputStateInterface } InputStateInterface
5555
* @typedef { import("./types").SearchStateInterface } SearchStateInterface
56+
* @typedef { import("./types").InsertModeChanges } InsertModeChanges
5657
*/
5758
var Pos = CM.Pos;
5859

@@ -1358,19 +1359,24 @@ export function initVim(CM) {
13581359
* inserted at the cursor position.)
13591360
*/
13601361
class Register {
1362+
/** @arg {string} [text] @arg {boolean} [linewise] @arg {boolean } [blockwise] */
13611363
constructor(text, linewise, blockwise) {
13621364
this.clear();
13631365
this.keyBuffer = [text || ''];
1366+
/** @type {InsertModeChanges[]} */
13641367
this.insertModeChanges = [];
1368+
/** @type {string[]}*/
13651369
this.searchQueries = [];
13661370
this.linewise = !!linewise;
13671371
this.blockwise = !!blockwise;
13681372
}
1373+
/** @arg {string} [text] @arg {boolean} [linewise] @arg {boolean } [blockwise] */
13691374
setText(text, linewise, blockwise) {
13701375
this.keyBuffer = [text || ''];
13711376
this.linewise = !!linewise;
13721377
this.blockwise = !!blockwise;
13731378
}
1379+
/** @arg {string} text @arg {boolean} [linewise] */
13741380
pushText(text, linewise) {
13751381
// if this register has ever been set to linewise, use linewise.
13761382
if (linewise) {
@@ -1381,9 +1387,11 @@ export function initVim(CM) {
13811387
}
13821388
this.keyBuffer.push(text);
13831389
}
1390+
/** @arg {InsertModeChanges} changes */
13841391
pushInsertModeChanges(changes) {
13851392
this.insertModeChanges.push(createInsertModeChanges(changes));
13861393
}
1394+
/** @arg {string} query */
13871395
pushSearchQuery(query) {
13881396
this.searchQueries.push(query);
13891397
}
@@ -1803,7 +1811,7 @@ export function initVim(CM) {
18031811
(keyName == '<BS>' && query == '')) {
18041812
vimGlobalState.searchHistoryController.pushInput(query);
18051813
vimGlobalState.searchHistoryController.reset();
1806-
updateSearchQuery(cm, originalQuery);
1814+
updateSearchQuery(cm, originalQuery?.source || "");
18071815
clearSearchHighlight(cm);
18081816
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
18091817
CM.e_stop(e);
@@ -3777,7 +3785,7 @@ export function initVim(CM) {
37773785
'visualLine': vim.visualLine,
37783786
'visualBlock': vim.visualBlock};
37793787
}
3780-
/** @arg {CodeMirrorV} cm @arg {Pos} start @arg {Pos} end @returns {[Pos, Pos]} */
3788+
/** @arg {CodeMirrorV} cm @arg {Pos} start @arg {Pos} end @arg {Boolean} [move] @returns {[Pos, Pos]} */
37813789
function expandSelection(cm, start, end, move) {
37823790
var sel = cm.state.vim.sel;
37833791
var head = move ? start: sel.head;
@@ -5170,16 +5178,14 @@ export function initVim(CM) {
51705178
* If the query contains the /i in the flag part of the regular expression,
51715179
* then both ignoreCase and smartCase are ignored, and 'i' will be passed
51725180
* through to the Regex object.
5173-
* @arg {string|RegExp} query
5181+
* @arg {string} query
51745182
* @arg {boolean} ignoreCase
51755183
* @arg {boolean} smartCase
51765184
*/
51775185
function parseQuery(query, ignoreCase, smartCase) {
51785186
// First update the last search register
51795187
var lastSearchRegister = vimGlobalState.registerController.getRegister('/');
51805188
lastSearchRegister.setText(query);
5181-
// Check if the query is already a regex.
5182-
if (query instanceof RegExp) { return query; }
51835189
// First try to extract regex + flags from the input. If no flags found,
51845190
// extract just the regex. IE does not accept flags directly defined in
51855191
// the regex string in the form /regex/flags
@@ -5305,7 +5311,7 @@ export function initVim(CM) {
53055311
// Returns true if the query is valid.
53065312
/**
53075313
* @arg {CodeMirrorV} cm
5308-
* @arg {string | RegExp} rawQuery
5314+
* @arg {string } rawQuery
53095315
* @arg {boolean | undefined} [ignoreCase]
53105316
* @arg {boolean | undefined} [smartCase]
53115317
*/
@@ -6115,6 +6121,7 @@ export function initVim(CM) {
61156121
},
61166122
/** @arg {CodeMirrorV} cm @arg {ExParams} params*/
61176123
normal: function(cm, params) {
6124+
var noremap = false;
61186125
var argString = params.argString;
61196126
if (argString && argString[0] == '!') {
61206127
argString = argString.slice(1);
@@ -6130,13 +6137,13 @@ export function initVim(CM) {
61306137
var lineEnd = isNaN(params.lineEnd) ? line : params.lineEnd;
61316138
for (var i = line; i <= lineEnd; i++) {
61326139
cm.setCursor(i, 0);
6133-
doKeyToKey(cm, params.argString.trimStart());
6140+
doKeyToKey(cm, params.argString.trimStart(), {noremap});
61346141
if (cm.state.vim.insertMode) {
61356142
exitInsertMode(cm, true);
61366143
}
61376144
}
61386145
} else {
6139-
doKeyToKey(cm, params.argString.trimStart());
6146+
doKeyToKey(cm, params.argString.trimStart(), {noremap});
61406147
if (cm.state.vim.insertMode) {
61416148
exitInsertMode(cm, true);
61426149
}

test/vim_test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4356,20 +4356,26 @@ testVim('ex_global', function(cm, vim, helpers) {
43564356
eq(' one one\n two one', helpers.getNotificationText());
43574357
}, {value: 'one one\n one one\n one one'});
43584358
testVim('ex_normal', function(cm, vim, helpers) {
4359+
helpers.doEx('norm /<Esc>"/p');
4360+
helpers.doEx('norm /x<Cr>"/p');
4361+
helpers.doEx('norm /h<Esc>"/p');
4362+
helpers.doEx('norm /one<Cr>3li<Right> <Esc>"/p');
4363+
eq('one one\nxxx\none one\none one', cm.getValue());
4364+
43594365
cm.setCursor(0, 0);
43604366
helpers.doEx('g/one/normal cw 1<lt>Esc><Esc>$i$');
43614367
helpers.doKeys("rt");
4362-
eq(' 1<Esc> on$e\nxx\n 1<Esc> on$e\n 1<Esc> on$t', cm.getValue());
4368+
eq(' 1<Esc> on$e\nxxx\n 1<Esc> on$e\n 1<Esc> on$t', cm.getValue());
43634369
helpers.doKeys('/', '<', '\n');
43644370
helpers.doKeys('x', 'x', 'p');
4365-
eq(' 1sEc> on$e\nxx\n 1<Esc> on$e\n 1<Esc> on$t', cm.getValue());
4371+
eq(' 1sEc> on$e\nxxx\n 1<Esc> on$e\n 1<Esc> on$t', cm.getValue());
43664372
cm.setCursor(0, 0);
43674373
helpers.doEx('map k j');
43684374
helpers.doEx('normal kkk');
43694375
helpers.assertCursorAt(3, 0);
43704376
helpers.doEx('normal! kkk');
43714377
helpers.assertCursorAt(0, 0);
4372-
}, {value: 'one one\nxx\none one\none one'});
4378+
}, {value: 'one one\nx\none\none one'});
43734379
testVim('ex_global_substitute_join', function(cm, vim, helpers) {
43744380
helpers.doEx('g/o/s/\\n/;');
43754381
eq('one;two\nthree\nfour;five\n', cm.getValue());

0 commit comments

Comments
 (0)