editor: Always show the cursor

This commit is contained in:
Andrew Hamilton 2022-06-13 14:15:43 +10:00
parent 47e303aa3b
commit aa9c43d0db

View file

@ -431,19 +431,7 @@ class TextEditor:
if 0 <= end_y < len(appearance):
appearance[end_y] = highlight_part(appearance[end_y], 0, screen_end_x)
def _add_highlights(self, appearance):
view_x, view_y = self.view_widget.position
if not self.is_editing:
return appearance
cursor_y = self.cursor_y - view_y
if self.mark is None:
if 0 <= cursor_y < len(appearance):
appearance[cursor_y] = highlight_line(appearance[cursor_y])
else:
self._highlight_selection(appearance)
if self.cursor_x >= len(appearance[0]):
appearance = fill3.appearance_resize(appearance, (self.cursor_x+1, len(appearance)))
if 0 <= cursor_y < len(appearance):
def _highlight_cursor(self, appearance, cursor_y):
cursor_line = appearance[cursor_y]
screen_x = self.screen_x(self.cursor_x, self.cursor_y)
screen_x_after = (screen_x + 1 if self._current_character() in ["\t", "\n"] else
@ -451,6 +439,21 @@ class TextEditor:
appearance[cursor_y] = (cursor_line[:screen_x] +
termstr.TermStr(cursor_line[screen_x:screen_x_after]).invert() +
cursor_line[screen_x_after:])
def _add_highlights(self, appearance):
view_x, view_y = self.view_widget.position
cursor_y = self.cursor_y - view_y
if 0 <= cursor_y < len(appearance):
self._highlight_cursor(appearance, cursor_y)
if not self.is_editing:
return appearance
if self.mark is None:
if 0 <= cursor_y < len(appearance):
appearance[cursor_y] = highlight_line(appearance[cursor_y])
else:
self._highlight_selection(appearance)
if self.cursor_x >= len(appearance[0]):
appearance = fill3.appearance_resize(appearance, (self.cursor_x+1, len(appearance)))
return appearance
def set_text(self, text):
@ -1039,8 +1042,8 @@ class TextFilesEditor:
file_browser_appearance = self.file_browser.appearance()
else:
file_browser_appearance = []
return (file_browser_appearance +
self.current_editor().appearance_for((width, height-len(file_browser_appearance))))
editor_dimensions = width, height - len(file_browser_appearance)
return file_browser_appearance + self.current_editor().appearance_for(editor_dimensions)
def main():