-
Notifications
You must be signed in to change notification settings - Fork 115
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
last line dd #28
Comments
This fix introduced a new bug that is if you delete everything in the file, or say when you delete the only line in the file with dd, your cursor is GONE again :) |
Has this been fixed? |
It seems this bug has crept back into Vintageous. |
I can send you a pull request if you're interested. |
If you do, please add a test so that this problem doesn't go unnoticed again in the future. |
I'll start working on this today. Could I get a quick introduction to how things are organized? I noticed that the |
For an overview, there's this: https://github.com/guillermooo/Vintageous/wiki/Design
As far as this bug is concerned, I think you will simply have to edit There's two basic steps to a command: a motion that creates a region in ST, and an action that operates on that region. (But there's also counts, modes, etc.) TestsTests are still very much in a state of flux, but this is the style I've more or less settled on: https://github.com/guillermooo/Vintageous/blob/master/tests/commands/test__vi_e.py edit
|
Thank you for that excellent introduction. I'll create a test case for this particular issue, fix the problem and then i'll send a pull request for review. |
I've have made some changes which should fix the following issues:
You can see them here: https://github.com/KevinSjoberg/Vintageous/compare/fix_dd_motion I'm not quite sure how you want me to test this before I submit a pull request. I looked https://github.com/guillermooo/Vintageous/blob/master/tests/commands/test__vi_e.py. My understanding is that you test motion and action separately? My initial thoughts was to write tests in the following manner:
|
The code looks good, but I would point out the following:
if mode == _MODE_INTERNAL_NORMAL:
...
return sublime.Region(...)
return s In case there are changes later, the catch-all
(Will continue below re. testing.) |
Re. testing, that's correct, you have to test the motion and the action separately because you want to test the actual ST commands. Following the given example, you have to do a bit more to get them working (registering with It'd look something like this: import unittest
from Vintageous.vi.constants import _MODE_INTERNAL_NORMAL
from Vintageous.vi.constants import MODE_NORMAL
from Vintageous.vi.constants import MODE_VISUAL
from Vintageous.vi.constants import MODE_VISUAL_LINE
from Vintageous.tests import set_text
from Vintageous.tests import add_sel
from Vintageous.tests import get_sel
from Vintageous.tests import first_sel
from Vintageous.tests import BufferTest
class Test_vi_dd_action_InInternalNormalMode(BufferTest):
def testCanDelete_OnLastLine_NoCount_NonEmptyLine(self):
text = 'abc\nabc\nabc'
set_text(self.view, text)
add_sel(self.view, self.R((2, 0), (2, 3)))
self.view.run_command('_vi_dd_action', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
self.assertEqual(self.view.substr(0, self.view.size()), 'abc\nabc') Or something like that. |
This seems to work for me (but I haven't written tests either): class _vi_dd_motion(sublime_plugin.TextCommand):
def row_at(self, pt):
return self.view.rowcol(pt)[0]
def run(self, edit, mode=None, count=1):
def f(view, s):
if mode == _MODE_INTERNAL_NORMAL:
end = view.text_point(self.row_at(s.b) + (count - 1), 0)
begin = view.line(s.b).a
if ((self.row_at(end) == self.row_at(view.size())) and
(view.substr(begin - 1) == '\n')):
begin -= 1
return sublime.Region(begin, view.full_line(end).b)
return s
regions_transformer(self.view, f) |
Sweet. I'll test it further and submit tests. |
I have found similar errors using With the following file:
If you are on line 5 and do
when expecting:
And if you are on line 4 and do |
@KevinSjoberg Just a heads up that I already have a fix for this one. Cheers. |
While the vintage completely fails to delete the last line if it is an empty line,
vintageous takes two "dd" to delete a line if it is the last line of the file,
first time delete the content, second time delete the new line.
I reckon it can't be intentional because Vim doesn't behave like that.
The text was updated successfully, but these errors were encountered: