Skip to content

Commit 9bd95b9

Browse files
authored
Fix bug where selections always include an extra character (microsoft#60)
1 parent 3f09057 commit 9bd95b9

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

pgsqltoolsservice/workspace/script_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_lines_in_range(self, buffer_range: Range) -> List[str]:
130130
# If the line we're looking at is not the beginning or end, select entire line,
131131
# otherwise, trim the unselected part of the line
132132
start_column: int = buffer_range.start.character if line == buffer_range.start.line else 0
133-
end_column: int = buffer_range.end.character + 1 if line == buffer_range.end.line else len(current_line)
133+
end_column: int = buffer_range.end.character if line == buffer_range.end.line else len(current_line)
134134

135135
output.append(current_line[start_column:end_column])
136136
return output

tests/workspace/test_script_file.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_get_lines_in_range_valid(self):
8585
result = sf.get_lines_in_range(params)
8686

8787
# Then: I should get a set of lines with the expected result
88-
expected_result = ['ef', 'ghij', 'kl']
88+
expected_result = ['ef', 'ghij', 'k']
8989
self.assertEqual(result, expected_result)
9090

9191
def test_get_lines_in_range_invalid_start(self):
@@ -119,7 +119,19 @@ def test_get_text_in_range(self):
119119
result = sf.get_text_in_range(params)
120120

121121
# Then: I should get a set of lines with the expected result
122-
expected_result = os.linesep.join(['ef', 'ghij', 'kl'])
122+
expected_result = os.linesep.join(['ef', 'ghij', 'k'])
123+
self.assertEqual(result, expected_result)
124+
125+
def test_get_text_in_range_start_of_line(self):
126+
"""Test that get_text_in_range works when the cursor is at the start of a line"""
127+
sf = self._get_test_script_file()
128+
129+
# If I get text from a range that covers the entire first line and ends on the second line before any text
130+
params = Range.from_data(0, 0, 1, 0)
131+
result = sf.get_text_in_range(params)
132+
133+
# Then I should get the first line and a line with no content as the result
134+
expected_result = os.linesep.join(['abc', ''])
123135
self.assertEqual(result, expected_result)
124136

125137
# VALIDATE POSITION TESTS ##############################################

tests/workspace/test_workspace_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def test_get_text_selection(self):
273273
# Retrieve the full text of the file and make sure it matches
274274
selection_range = Range(Position(1, 1), Position(2, 4))
275275
result_text = workspace_service.get_text(file_uri, selection_range)
276-
self.assertEqual(result_text, os.linesep.join(['ine 2 content', ' line']))
276+
self.assertEqual(result_text, os.linesep.join(['ine 2 content', ' lin']))
277277

278278
# IMPLEMENTATION DETAILS ###############################################
279279

0 commit comments

Comments
 (0)