mirror of https://github.com/Textualize/rich.git
[syntax] silently clamp the column index of stylised ranges to the maximum possible value
This commit is contained in:
parent
b6a4cfab5a
commit
6e634705b7
|
@ -803,7 +803,8 @@ def _get_code_index_for_syntax_position(
|
|||
|
||||
Returns:
|
||||
Optional[int]: The index of the code string for this position, or `None`
|
||||
if the position is out of range.
|
||||
if the given position's line number is out of range (if it's the column that is out of range
|
||||
we silently clamp its value so that it reaches the end of the line)
|
||||
"""
|
||||
lines_count = len(newlines_offsets)
|
||||
|
||||
|
@ -812,8 +813,8 @@ def _get_code_index_for_syntax_position(
|
|||
return None # `line_number` is out of range
|
||||
line_index = line_number - 1
|
||||
line_length = newlines_offsets[line_index + 1] - newlines_offsets[line_index] - 1
|
||||
if line_length < column_index:
|
||||
return None # `column_index` is out of range
|
||||
# If `column_index` is out of range: let's silently clamp it:
|
||||
column_index = min(line_length, column_index)
|
||||
return newlines_offsets[line_index] + column_index
|
||||
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue