Skip to content

IndexError when a selected line has fewer columns than the sort column #2

Open

Description

@dpc00

Claude reports: sorting fails with an IndexError when any selected line has fewer columns than the column picked, and the selection is left unchanged.

Tested on Sublime Text 4 build 4215 (Windows) with Column Sort 2.0.0 from Package Control. Selected these lines (tab separated):

name	qty
pear	3
apple	10
fig
cherry	7

then ran column_pick and chose qty. The console printed:

  File ".../ColumnSort.py", line 23, in run
    rows_cols_tail.sort(key=lambda col:col[col_num], reverse=ascending)
IndexError: list index out of range

Fix, tested here (loose copy of ColumnSort.py): change the key to key=lambda col:col[col_num] if col_num < len(col) else "". The same selection then sorts to name qty, fig, apple 10, pear 3, cherry 7: the header stays first and the short row sorts as an empty value.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions