Skip to content

Commit 483e432

Browse files
authored
Merge pull request #381 from cs50/patch/issue-380-improve-truncation
Improve diff visibility
2 parents 4fc0c42 + d8610a0 commit 483e432

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

check50/_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,15 @@ def normalize(obj):
563563
i = index
564564
break
565565

566-
# center around diff
567-
start = max(i - (config.truncate_len // 2), 0)
568-
end = min(start + config.truncate_len, len(s))
566+
# If the diff is within the first config.truncate_len characters,
567+
# start from the beginning (no need for "..." at the start)
568+
if i < config.truncate_len:
569+
start = 0
570+
end = min(config.truncate_len, len(s))
571+
else:
572+
# center around diff for differences further into the string
573+
start = max(i - (config.truncate_len // 2), 0)
574+
end = min(start + config.truncate_len, len(s))
569575

570576
snippet = s[start:end]
571577

check50/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Config:
1313
"""
1414

1515
def __init__(self):
16-
self.truncate_len = 10
16+
self.truncate_len = 30
1717
self.dynamic_truncate = True
1818

1919
# Create boolean validators for your variables here (if needed):

0 commit comments

Comments
 (0)