Skip to content

Commit a9ac1b9

Browse files
committed
Fix deleteLine to behave correctly on edge cases
deleteLine used to remove the previous line end, rather than the line end for the current line, which was really stupid.
1 parent b84e190 commit a9ac1b9

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

PythonScript/python_tests/tests/ScintillaWrapperTestCase.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,4 +971,35 @@ def test_getCharacterPointer(self):
971971
text = editor.getCharacterPointer()
972972
self.assertEqual(text, 'Hello world char pointer')
973973

974+
def test_deleteLine_with_contents(self):
975+
editor.write('Line 1\r\nLine 2\r\nLine 3\r\n')
976+
editor.deleteLine(1)
977+
text = editor.getText();
978+
self.assertEqual(text, 'Line 1\r\nLine 3\r\n')
979+
980+
def test_deleteLine_middle_no_contents(self):
981+
editor.write('Line 1\r\n\r\nLine 3\r\n')
982+
editor.deleteLine(1)
983+
text = editor.getText();
984+
self.assertEqual(text, 'Line 1\r\nLine 3\r\n')
985+
986+
def test_deleteLine_end_no_contents(self):
987+
editor.write('Line 1\r\nLine 2\r\n\r\n')
988+
editor.deleteLine(2)
989+
text = editor.getText();
990+
self.assertEqual(text, 'Line 1\r\nLine 2\r\n')
991+
992+
def test_deleteLine_end_no_eol(self):
993+
editor.write('Line 1\r\nLine 2\r\nLine 3')
994+
editor.deleteLine(2)
995+
text = editor.getText();
996+
self.assertEqual(text, 'Line 1\r\nLine 2\r\n')
997+
998+
def test_deleteLine_start_no_contents(self):
999+
editor.write('\r\nLine 2\r\nLine 3\r\n')
1000+
editor.deleteLine(0)
1001+
text = editor.getText();
1002+
self.assertEqual(text, 'Line 2\r\nLine 3\r\n')
1003+
1004+
9741005
suite = unittest.TestLoader().loadTestsFromTestCase(ScintillaWrapperTestCase)

PythonScript/src/ScintillaWrapper.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,18 @@ void ScintillaWrapper::forEachLine(PyObject* function)
506506

507507
void ScintillaWrapper::deleteLine(int lineNumber)
508508
{
509-
int start = 0;
509+
int start = PositionFromLine(lineNumber);
510510
int lineCount = GetLineCount();
511-
if (0 != lineNumber && lineCount != 1)
511+
int end;
512+
if (lineCount > lineNumber)
513+
{
514+
end = PositionFromLine(lineNumber + 1);
515+
}
516+
else
512517
{
513-
start = GetLineEndPosition(lineNumber - 1);
518+
end = GetLineEndPosition(lineNumber);
514519
}
515-
int end = GetLineEndPosition(lineNumber);
520+
516521
setTarget(start, end);
517522
this->ReplaceTarget(boost::python::str(""));
518523
}

0 commit comments

Comments
 (0)