Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fixed Getter Setter Redo Issue #14508

Merged
merged 2 commits into from
Aug 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/extensions/default/JavaScriptRefactoring/WrapSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ define(function (require, exports, module) {
}

var token = TokenUtils.getTokenAt(current.cm, current.cm.posFromIndex(endIndex)),
commaString = ",",
isLastNode,
templateParams,
parentNode,
Expand All @@ -267,16 +268,38 @@ define(function (require, exports, module) {

var propertyNodeArray = parentNode.properties;
// Find the last Propery Node before endIndex
var properyEndNode = propertyNodeArray.find(function (element) {
var properyNodeIndex = propertyNodeArray.findIndex(function (element) {
return (endIndex >= element.start && endIndex < element.end);
});

var propertyNode = propertyNodeArray[properyNodeIndex];

//Get Current Selected Property End Index;
propertyEndPos = editor.posFromIndex(properyEndNode.end);
propertyEndPos = editor.posFromIndex(propertyNode.end);


//We have to add ',' so we need to find position of current property selected
isLastNode = current.isLastNodeInScope(current.ast, endIndex);
var nextPropertNode, nextPropertyStartPos;
if(!isLastNode && properyNodeIndex + 1 <= propertyNodeArray.length - 1) {
nextPropertNode = propertyNodeArray[properyNodeIndex + 1];
nextPropertyStartPos = editor.posFromIndex(nextPropertNode.start);

if(propertyEndPos.line !== nextPropertyStartPos.line) {
propertyEndPos = current.lineEndPosition(current.startPos.line);
} else {
propertyEndPos = nextPropertyStartPos;
commaString = ", ";
}
}

var getSetPos;
if (isLastNode) {
getSetPos = current.document.adjustPosForChange(propertyEndPos, commaString.split("\n"),
propertyEndPos, propertyEndPos);
} else {
getSetPos = propertyEndPos;
}
templateParams = {
"getName": token.string,
"setName": token.string,
Expand All @@ -288,18 +311,17 @@ define(function (require, exports, module) {
current.document.batchOperation(function() {
if (isLastNode) {
//Add ',' in the end of current line
current.document.replaceRange(",", propertyEndPos, propertyEndPos);
current.document.replaceRange(commaString, propertyEndPos, propertyEndPos);
}
propertyEndPos.ch++;

current.editor.setSelection(propertyEndPos); //Selection on line end
current.editor.setSelection(getSetPos); //Selection on line end

// Add getters and setters for given token using template at current cursor position
current.replaceTextFromTemplate(GETTERS_SETTERS, templateParams);

if (!isLastNode) {
// Add ',' at the end setter
current.document.replaceRange(",", current.editor.getSelection().start, current.editor.getSelection().start);
current.document.replaceRange(commaString, current.editor.getSelection().start, current.editor.getSelection().start);
}
});
}
Expand Down