Skip to content

Commit

Permalink
Workaround clearing to first when using occurence
Browse files Browse the repository at this point in the history
Conditionally skip workaround involving positioning of popups
at proper position. Previously with `clearMultipleCursorsToFirstPosition`
enabled, and using occurence, it would clear to second instead
of first position.
  • Loading branch information
trkoch committed Sep 23, 2018
1 parent 845d303 commit b8b1e46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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
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]

0 comments on commit b8b1e46

Please sign in to comment.