|
2370 | 2370 | var curStart = cm.getCursor(); |
2371 | 2371 | var replaceTo; |
2372 | 2372 | var curEnd; |
2373 | | - if (vim.visualMode){ |
2374 | | - curStart=cm.getCursor('start'); |
2375 | | - curEnd=cm.getCursor('end'); |
2376 | | - }else{ |
| 2373 | + var selections = cm.listSelections(); |
| 2374 | + if (vim.visualMode) { |
| 2375 | + curStart = cm.getCursor('start'); |
| 2376 | + curEnd = cm.getCursor('end'); |
| 2377 | + } else { |
2377 | 2378 | var line = cm.getLine(curStart.line); |
2378 | 2379 | replaceTo = curStart.ch + actionArgs.repeat; |
2379 | 2380 | if (replaceTo > line.length) { |
2380 | 2381 | replaceTo=line.length; |
2381 | 2382 | } |
2382 | 2383 | curEnd = Pos(curStart.line, replaceTo); |
2383 | 2384 | } |
2384 | | - if (replaceWith=='\n'){ |
| 2385 | + if (replaceWith=='\n') { |
2385 | 2386 | if (!vim.visualMode) cm.replaceRange('', curStart, curEnd); |
2386 | 2387 | // special case, where vim help says to replace by just one line-break |
2387 | 2388 | (CodeMirror.commands.newlineAndIndentContinueComment || CodeMirror.commands.newlineAndIndent)(cm); |
2388 | | - }else { |
2389 | | - var replaceWithStr=cm.getRange(curStart, curEnd); |
| 2389 | + } else { |
| 2390 | + var replaceWithStr = cm.getRange(curStart, curEnd); |
2390 | 2391 | //replace all characters in range by selected, but keep linebreaks |
2391 | | - replaceWithStr=replaceWithStr.replace(/[^\n]/g,replaceWith); |
2392 | | - cm.replaceRange(replaceWithStr, curStart, curEnd); |
2393 | | - if (vim.visualMode){ |
| 2392 | + replaceWithStr = replaceWithStr.replace(/[^\n]/g, replaceWith); |
| 2393 | + if (vim.visualBlock) { |
| 2394 | + // Tabs are split in visua block before replacing |
| 2395 | + var spaces = new Array(cm.options.tabSize+1).join(' '); |
| 2396 | + replaceWithStr = cm.getSelection(); |
| 2397 | + replaceWithStr = replaceWithStr.replace(/\t/g, spaces).replace(/[^\n]/g, replaceWith).split('\n'); |
| 2398 | + cm.replaceSelections(replaceWithStr); |
| 2399 | + } else { |
| 2400 | + cm.replaceRange(replaceWithStr, curStart, curEnd); |
| 2401 | + } |
| 2402 | + if (vim.visualMode) { |
| 2403 | + curStart = cursorIsBefore(selections[0].anchor, selections[0].head) ? |
| 2404 | + selections[0].anchor : selections[0].head; |
2394 | 2405 | cm.setCursor(curStart); |
2395 | 2406 | exitVisualMode(cm); |
2396 | | - }else{ |
| 2407 | + } else { |
2397 | 2408 | cm.setCursor(offsetCursor(curEnd, 0, -1)); |
2398 | 2409 | } |
2399 | 2410 | } |
|
0 commit comments