Skip to content

Input area improvements/tasks #208

@osa1

Description

@osa1

I was reading the code today and found some potential improvements and a problem in the code.

  • Starting with the problem: InputArea::height is never set. It starts its life as None and stays that way. That means InputArea::get_height always recomputes the height even if nothing changes in InputArea.

  • I think it'd be better to invalidate InputLine::ws_indices (renamed from InputLine::line_starts) on update. Currently we don't update it until calculate_height is called, and if I update a line and forget to call calculate_height then draw will render input area incorrectly.

  • We should have a fast path for the common case of inserting at the end. Currently this causes quadratic behavior on paste, where we turn a long string into a series of key press events (see handle_input_event), and for every key press we compute the whitespace indices from scratch. (this comments was incorrect, see my update in the comments section below) I think InputLine::insert could be easily updated to handle this and efficiently update ws_indices when inserting at the end.

    This also means InputLine::calculate_height shouldn't generate ws_indices from scratch if it's already up-to-date (related to the second point above), otherwise the update in insert will never be used.

  • Similar to the item above, deleting from the end shouldn't require generating the state from scratch.

cc @trevarj

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions