Skip to content

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.

@gegoune gegoune changed the title refactor(actions): common code for rename-file, enhance refactor(actions): common code for rename-file Nov 22, 2023
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