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

command to freeze the current column directly #2660

Open
midichef opened this issue Dec 31, 2024 · 6 comments
Open

command to freeze the current column directly #2660

midichef opened this issue Dec 31, 2024 · 6 comments
Labels

Comments

@midichef
Copy link
Contributor

Often I want to replace the current column with a frozen copy. It would be convenient to have a command that does the equivalent of:
Sheet.addCommand("", 'setcol-freeze', 'i = cursorVisibleColIndex; name = cursorCol.name; fc = freeze_col(cursorCol); fc.name = name; addColumnAtCursor(fc); columns.pop(i)', 'replace current column with a frozen copy, with all cells evaluated')
(right now this command triggers a bug that's already been reported #2607)

I can't think of a good keyboard shortcut that is not yet taken.

Do other people want this feature?

@midichef midichef changed the title command to freeze the current column without needing a copy command to freeze the current column directly Dec 31, 2024
@saulpw
Copy link
Owner

saulpw commented Dec 31, 2024

z' currently resets the cache on a column, but it could freeze the column like this instead. This would be more in-line with the rest of the ' commands anyway. I'm fine with leaving cache-col without a binding since I think this new command might itself work in the rare instances I've needed it.

@frosencrantz
Copy link
Contributor

Many times I want to replace a column with it's frozen version, so it would be useful to me. This would save some steps. I haven't tried the sample code. Would the prefrozen column still exist as hidden? If not, it would be useful to rename it to something different, like with a suffix (uf -- unfrozen, pf - prefrozen, ...) I like that your example makes the frozen version the same name as the original column.

It would be nice if this command:

  • is undoable
  • handles the case when the original column is materializing such as when it is still async evaluating values.

This replace original column feature would be useful with other commands that return a new modified version of another column.

@midichef
Copy link
Contributor Author

midichef commented Jan 7, 2025

@frosencrantz
Here's a version that keeps the prefrozen column, as a hidden column with the suffix '_unfrozen'. It'll work if you add it to your .visidatarc.

It is undoable. But it does not handle the case of freezing a column that is still materializing. I'm not sure that can be done.

@BaseSheet.api
def setcol_freeze(sheet):
    unfrozen = sheet.cursorCol
    frozen = sheet.freeze_col(unfrozen)
    frozen.name = unfrozen.name
    unfrozen.hide()
    vd.addUndoColNames([unfrozen])
    unfrozen.name = frozen.name + '_unfrozen'
    sheet.addColumnAtCursor(frozen)
    vd.status(f'replaced {frozen.name} with frozen copy')
Sheet.addCommand("z'", 'setcol-freeze', 'setcol_freeze()', 'replace current column with a frozen copy, with all cells evaluated')

Let me know if you have any feedback.

@frosencrantz
Copy link
Contributor

I will try this. Thank you!

@frosencrantz
Copy link
Contributor

@midichef this is very nice. I have two feedback comments:

  1. There is no visual feedback. After you call the command everything looks the same. To be sure it was successful I went to the ColumnsSheet. If VisiData had some sort of animation support, you could temporarily highlight and unhighlight the column. Maybe a vd.status() message saying that the column is now frozen. As I use it more, maybe that would not be needed, but for my first attempts I wasn't sure. As an aside, it is odd that a frozen column can be modified, and one of the reasons to freeze a generated column is to modify the values. The "unfrozen" column is the one that cannot be directly modified.
  2. The undo is not complete. It leaves the original column with the "_unfrozen" suffix. Not sure if that is fixable, but that seems wrong. If you undo, and then do it again, the _unfrozens are additive: "_unfrozen_unfrozen..."

@midichef
Copy link
Contributor Author

midichef commented Jan 15, 2025

@frosencrantz
Good suggestions. I edited the code snippet above to address your comments. I added a vd.status() message as feedback. And I fixed the undo to restore the column's original name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants