Skip to content

Commit

Permalink
Fix #716 yol toggle list (unimpaired)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardroche committed Mar 26, 2020
1 parent 39123cf commit 5cf72e4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt

### Fixed

* Removed [#716](https://github.com/NeoVintageous/NeoVintageous/issues/716): `yol` toggle list sometimes doesn't work (Unimpaired)
* Removed [#714](https://github.com/NeoVintageous/NeoVintageous/issues/714): `^V` is not syntax highlighted like `^J` in command-line output bug (UI)

## 1.20.0 - 2020-03-22
Expand Down
26 changes: 14 additions & 12 deletions nv/options.py
Expand Up @@ -86,6 +86,12 @@ class BooleanViewOption(BooleanOption):

def __init__(self, name: str, on=True, off=False):
super().__init__(name, None)
if not isinstance(on, tuple):
on = (on,)

if not isinstance(off, tuple):
off = (off,)

self._on = on
self._off = off

Expand All @@ -97,18 +103,18 @@ def _set(self, view, value):
# changed" event. Sublime triggers the event any time the settings set()
# method is called, even if the actual value itself has not changed.
if value:
if current_value != self._on:
settings.set(self._name, self._on)
if current_value not in self._on:
settings.set(self._name, self._on[0])
else:
if current_value != self._off:
settings.set(self._name, self._off)
if current_value not in self._off:
settings.set(self._name, self._off[0])

def _get(self, view):
value = view.settings().get(self._name)

if value == self._on:
if value in self._on:
value = True
elif value == self._off:
elif value in self._off:
value = False

return value
Expand Down Expand Up @@ -172,7 +178,7 @@ def _get_default_shell() -> str:
'hlsearch': BooleanOption('hlsearch', True),
'ignorecase': BooleanOption('ignorecase', False),
'incsearch': BooleanOption('incsearch', True),
'list': BooleanViewOption('draw_white_space', on='all', off='selection'),
'list': BooleanViewOption('draw_white_space', on=('all',), off=('selection', 'none')),
'magic': BooleanOption('magic', True),
'menu': BooleanIsVisibleOption('menu', True), # {not in Vim}
'minimap': BooleanIsVisibleOption('minimap', True), # {not in Vim}
Expand Down Expand Up @@ -266,8 +272,4 @@ def set_option(view, name: str, value=None) -> None:


def toggle_option(view, name: str) -> None:
value = get_option(view, name)
if not isinstance(value, bool):
raise ValueError('option cannot be toggled')

set_option(view, name, not value)
set_option(view, name, not get_option(view, name))
16 changes: 7 additions & 9 deletions nv/plugin_abolish.py
Expand Up @@ -120,22 +120,20 @@ def translate(self, view):

class _nv_abolish_command(TextCommand):
def run(self, edit, to=None, mode=None):

if to in _ALIASES:
try:
to = _ALIASES[to]
except KeyError:
pass

if to in _COERCIONS:
try:
coerce_func = _COERCIONS[to]
else:
raise ValueError('unknown coercion')
except KeyError:
return

new_sels = []
for sel in self.view.sel():
if sel.empty():
sel = self.view.word(sel)

sel = self.view.word(sel)
new_sels.append(sel.begin())

self.view.replace(edit, sel, coerce_func(self.view.substr(sel)))

if new_sels:
Expand Down
23 changes: 23 additions & 0 deletions tests/functional/test__plugin_unimpaired.py
Expand Up @@ -298,3 +298,26 @@ def test_toggle_basic_options(self):
self.assertOption(name, False, msg=name)
self.feed('yo%s' % key)
self.assertOption(name, True, msg=name)

def test_issue_716_toggle_list(self):
self.normal('f|izz')
self.view.settings().set('draw_white_space', 'none')
self.feed('yol')
self.assertEqual(self.view.settings().get('draw_white_space'), 'all')
self.assertOption('list', True)
self.feed('yol')
self.assertEqual(self.view.settings().get('draw_white_space'), 'selection')
self.assertOption('list', False)
self.feed('yol')
self.assertEqual(self.view.settings().get('draw_white_space'), 'all')
self.assertOption('list', True)
self.feed('[ol')
self.assertEqual(self.view.settings().get('draw_white_space'), 'all')
self.assertOption('list', True)
self.feed(']ol')
self.assertEqual(self.view.settings().get('draw_white_space'), 'selection')
self.assertOption('list', False)
self.view.settings().set('draw_white_space', 'selection')
self.feed('yol')
self.assertEqual(self.view.settings().get('draw_white_space'), 'all')
self.assertOption('list', True)

0 comments on commit 5cf72e4

Please sign in to comment.