js-assistant icon indicating copy to clipboard operation
js-assistant copied to clipboard

Refactor Idea: Replace usages with const declaration

Open hediet opened this issue 3 years ago • 5 comments

Replace usages with const declaration, when the cursor is at the const declaration.

image

hediet avatar Aug 12 '22 14:08 hediet

Nice idea! For my understanding, how would this be different from inline variable?

lgrammel avatar Aug 12 '22 14:08 lgrammel

It is the opposite direction: I want to replace all duplicate expressions with the const at the cursor.

hediet avatar Aug 12 '22 14:08 hediet

Ah I see, this would be useful!

In the meantime, you can achieve the same by combining the following refactorings:

  1. Extract the right hand side of the const into a new variable (here: top + height - checkBoxHeight - margin)
  2. Inline the original const (here: bottomBoundary)
  3. Rename the new variable to the name of the original const (here: to bottomBoundary)

lgrammel avatar Aug 12 '22 14:08 lgrammel

Just realized that one variant of the refactoring already exists, you should be able to go over top + height - checkboxHeight - margin and use "Replace with existing variable": https://p42.ai/documentation/code-assist/replace-expression-with-existing-variable

lgrammel avatar Nov 04 '22 16:11 lgrammel

Just realized that one variant of the refactoring already exists, you should be able to go over top + height - checkboxHeight - margin and use "Replace with existing variable": https://p42.ai/documentation/code-assist/replace-expression-with-existing-variable

Then I can also just use copy&paste.

hediet avatar Nov 04 '22 16:11 hediet