editor: Fix all lines to have same background width
This commit is contained in:
parent
b92429f487
commit
d9e95c1485
2 changed files with 6 additions and 10 deletions
2
BUGS
2
BUGS
|
|
@ -1,10 +1,10 @@
|
||||||
Current:
|
Current:
|
||||||
- When largest line grows the bounding box should grow.
|
|
||||||
|
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
- Interface freezing often.
|
- Interface freezing often.
|
||||||
- Fix scrolling.
|
- Fix scrolling.
|
||||||
|
- When largest line grows the bounding box should grow.
|
||||||
|
|
||||||
|
|
||||||
Won't fix:
|
Won't fix:
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ def _syntax_highlight(text, lexer, style):
|
||||||
|
|
||||||
class Text:
|
class Text:
|
||||||
|
|
||||||
def __init__(self, text, pad_char=" "):
|
def __init__(self, text, padding_char=" "):
|
||||||
self.padding_char = " "
|
self.padding_char = padding_char
|
||||||
self.text, self.actual_text, self.max_line_length = [], [], 0
|
self.text, self.actual_text, self.max_line_length = [], [], 0
|
||||||
lines = [""] if text == "" else text.splitlines()
|
lines = [""] if text == "" else text.splitlines()
|
||||||
if text.endswith("\n"):
|
if text.endswith("\n"):
|
||||||
|
|
@ -84,11 +84,7 @@ class Text:
|
||||||
self._replace_lines(key, value)
|
self._replace_lines(key, value)
|
||||||
|
|
||||||
def _replace_lines(self, slice_, new_lines):
|
def _replace_lines(self, slice_, new_lines):
|
||||||
new_lengths = [len(line) for line in new_lines]
|
max_new_lengths = max(len(line) for line in new_lines)
|
||||||
try:
|
|
||||||
max_new_lengths = max(new_lengths)
|
|
||||||
except ValueError:
|
|
||||||
max_new_lengths = 0
|
|
||||||
if max_new_lengths > self.max_line_length:
|
if max_new_lengths > self.max_line_length:
|
||||||
padding = self.padding_char * (max_new_lengths - self.max_line_length)
|
padding = self.padding_char * (max_new_lengths - self.max_line_length)
|
||||||
self.text = [line + padding for line in self.text]
|
self.text = [line + padding for line in self.text]
|
||||||
|
|
@ -122,8 +118,8 @@ class Code(Text):
|
||||||
def __init__(self, text, path, theme=NATIVE_STYLE):
|
def __init__(self, text, path, theme=NATIVE_STYLE):
|
||||||
self.lexer = pygments.lexers.get_lexer_for_filename(path, text, stripnl=False)
|
self.lexer = pygments.lexers.get_lexer_for_filename(path, text, stripnl=False)
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
self.padding_char = _syntax_highlight(" ", self.lexer, theme)
|
padding_char = _syntax_highlight(" ", self.lexer, theme)
|
||||||
Text.__init__(self, text)
|
Text.__init__(self, text, padding_char)
|
||||||
|
|
||||||
def _convert_line(self, line, max_line_length):
|
def _convert_line(self, line, max_line_length):
|
||||||
return (termstr.TermStr(line.ljust(max_line_length)) if self.theme is None
|
return (termstr.TermStr(line.ljust(max_line_length)) if self.theme is None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue