Skip to content
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

Multiple indent guides rendered at some indent levels #413

Open
tomlin7 opened this issue Oct 11, 2024 · 0 comments
Open

Multiple indent guides rendered at some indent levels #413

tomlin7 opened this issue Oct 11, 2024 · 0 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed language features syntax highlighting, lsp, other language features suggestions needed bugs/features that are still not figured out and need solution suggestions text editor Related to text editor's features

Comments

@tomlin7
Copy link
Owner

tomlin7 commented Oct 11, 2024

Bug

Multiple indent guides rendered at some indent levels. For example, see the indent level 3 in following screenshot

image

This is either an inconsistency caused by the bitmap used or the code, or tk itself not scaling properly.

Following code manages updation of indent guides

def update_indent_guides(self) -> None:
if self.minimalist:
return
self.tag_remove("indent_guide", "1.0", "end")
self.tag_remove("current_indent_guide", "1.0", "end")
lines = self.get("1.0", "end-1c").split("\n")
self.current_indent_level = self.get_current_indent_level() - 1
for line_number, line in enumerate(lines, start=1):
indent_level = self.calculate_indent_level(line)
if indent_level > 0:
self.add_indent_guide(line_number, indent_level)
def calculate_indent_level(self, line: str) -> int:
indent = len(line) - len(line.lstrip())
return indent // self.base.tab_spaces
def add_indent_guide(self, line_number: int, indent_level: int) -> None:
for level in range(indent_level):
start_index = f"{line_number}.{level * self.base.tab_spaces - 1}"
end_index = f"{line_number}.{level * self.base.tab_spaces + 1}"
self.tag_add(
(
"current_indent_guide"
if level == self.current_indent_level
else "indent_guide"
),
start_index,
end_index,
)

The indent guide uses following bitmaps

self.tag_configure(
"indent_guide",
bgstipple=f"@{self.indentguide_stipple}",
background=self.base.theme.border,
)
self.tag_configure(
"current_indent_guide",
bgstipple=f"@{self.indentguide_stipple}",
background=self.base.theme.secondary_foreground,
)

System Information

  • OS: Windows 11
  • Python Version: 3.12.5
@tomlin7 tomlin7 added bug Something isn't working text editor Related to text editor's features language features syntax highlighting, lsp, other language features help wanted Extra attention is needed suggestions needed bugs/features that are still not figured out and need solution suggestions labels Oct 11, 2024
@tomlin7 tomlin7 self-assigned this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed language features syntax highlighting, lsp, other language features suggestions needed bugs/features that are still not figured out and need solution suggestions text editor Related to text editor's features
Projects
None yet
Development

No branches or pull requests

1 participant