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

refactor(actions): common code for rename-file #2550

Closed
wants to merge 1 commit into from

Conversation

hinell
Copy link
Contributor

@hinell hinell commented Nov 22, 2023

actions-fs-rename-file-demo.mov

  • required to proceed with feat(actions): git-aware cut / paste / rename fs actions #2542 PR
  • Refactor lua/nvim-tree/actions/fs/rename-file.lua:
    • feat: Input_path_editor - new class
    • Deprecate private fn() in case it's used elsewhere
    • Replace fn() by rename_*() based on Input_path_editor new class
    • feat: new rename_relative, unbound by default

Input_path_editor new class

  • Encapsulates reusable code from rename-file.lua used for editing chunks of absolute path per feat(actions): git-aware cut / paste / rename fs actions #2542 (comment)
  • Despite looking complex in fact has only two methods that are used to prepare() / restore() path intended to be modified by user in vim.ui.input (see example)
  • Reusable, extensible, well documented

Why class?

  • it isolates temp data in instance-namespace, easy to use / extend
  • it encapsulates state that can be passed around / referenced from across async callback functions without need to pollute local scope

Why prototype-based class?

  • Prototype is a namespace of a class where instance methods are gathered / localized.

@hinell hinell changed the title refactor(actions): commond code for rename-file, enhance refactor(actions): common code for rename-file, enhance Nov 22, 2023
@hinell hinell force-pushed the actions-fs-rename branch 5 times, most recently from 381c9da to 386e11c Compare November 22, 2023 21:40
@gegoune gegoune changed the title refactor(actions): common code for rename-file, enhance refactor(actions): common code for rename-file Nov 22, 2023
@hinell hinell force-pushed the actions-fs-rename branch 7 times, most recently from 8acdeec to 0fcc8d5 Compare November 27, 2023 13:45
Add `Input_path_editor` new class for common code
Add `api.fs.rename_relative()` based on `Input_path_editor` new class
Hard deprecate private `fn()` in case used directly elsewhere
Replace `fn()` by `rename_*()` based on `Input_path_editor` new class
@alex-courtis
Copy link
Member

See #2551 (comment)

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

Successfully merging this pull request may close these issues.

2 participants