Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset multiple to first cursor's position #1097

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/occurrence-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ module.exports = class OccurrenceManager {
// It is important to show autocomplete+ popup at proper position( popup shows up at last-selection ).
// E.g. `c o f`(change occurrence in a-function) show autocomplete+ popup at closest occurrence.
const closestRange = this.getClosestRangeForSelection(ranges, selection)
ranges.splice(ranges.indexOf(closestRange), 1) // remove
ranges.push(closestRange) // then push to last
if (!this.vimState.getConfig('clearMultipleCursorsToFirstPosition')) {
ranges.splice(ranges.indexOf(closestRange), 1) // remove
ranges.push(closestRange) // then push to last
}

rangesToSelect.push(...ranges)

Expand Down
1 change: 1 addition & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ module.exports = new Settings('vim-mode-plus', {
description: 'Start in insert-mode when editorElement matches scope'
},
clearMultipleCursorsOnEscapeInsertMode: false,
clearMultipleCursorsToFirstPosition: false,
autoSelectPersistentSelectionOnOperate: true,
automaticallyEscapeInsertModeOnActivePaneItemChange: {
default: false,
Expand Down
7 changes: 5 additions & 2 deletions lib/vim-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,13 @@ module.exports = class VimState {
}

// What's this?
// clear all selections and final cursor position becomes head of last selection.
// clear all selections and final cursor position becomes head of last selection (optionally first selection)
// editor.clearSelections() does not respect last selection's head, since it merge all selections before clearing.
clearSelections () {
this.editor.setCursorBufferPosition(this.editor.getCursorBufferPosition())
const position = (this.getConfig('clearMultipleCursorsToFirstPosition'))
? this.editor.getCursorBufferPositions()[0]
: this.editor.getCursorBufferPosition()
this.editor.setCursorBufferPosition(position)
}

resetNormalMode (options = {}) {
Expand Down
16 changes: 16 additions & 0 deletions spec/occurrence-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1201,3 +1201,19 @@ describe "Occurrence", ->
ensure null, mode: "normal", occurrenceText: []
atom.confirm.andCallFake ({buttons}) -> buttons.indexOf("Continue")
ensure "g o", mode: "normal", occurrenceText: ['oo', 'oo', 'oo', 'oo', 'oo']

describe "clearMultipleCursorsToFirstPosition setting", ->
beforeEach ->
settings.set('clearMultipleCursorsToFirstPosition', true)

it "clear multiple occurence cursors by respecting first cursor's position", ->
set
text: """
ooo: xxx: ooo:
xxx: ooo: xxx:
"""
cursor: [0, 0]
ensure "c o a e", mode: 'insert', numCursors: 3
editor.insertText('===')
ensure "escape"
ensure "escape", mode: 'normal', numCursors: 1, cursor: [0, 2]
10 changes: 10 additions & 0 deletions spec/vim-state-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ describe "VimState", ->
set cursor: [[0, 2], [0, 1]]
ensure 'escape', mode: 'normal', numCursors: 1, cursor: [0, 0]

describe "clearMultipleCursorsToFirstPosition setting", ->
beforeEach ->
settings.set('clearMultipleCursorsToFirstPosition', true)
it "clear multiple cursors by respecting first cursor's position", ->
ensure 'escape', mode: 'normal', numCursors: 1, cursor: [0, 0]

it "clear multiple cursors by respecting first cursor's position", ->
set cursor: [[0, 2], [0, 1]]
ensure 'escape', mode: 'normal', numCursors: 1, cursor: [0, 1]

describe "when disabled", ->
beforeEach ->
settings.set('clearMultipleCursorsOnEscapeInsertMode', false)
Expand Down