src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js
function extract(scopes, parentStatement, expns, text, insertPosition) {
        var varType          = "var",
            varName          = RefactoringUtils.getUniqueIdentifierName(scopes, "extracted"),
            varDeclaration   = varType + " " + varName + " = " + text + ";\n",
            parentStatementStartPos = session.editor.posFromIndex(parentStatement.start),
            insertStartPos   = insertPosition || parentStatementStartPos,
            selections       = [],
            doc              = session.editor.document,
            replaceExpnIndex = 0,
            posToIndent,
            edits            = [];

        // If parent statement is expression statement, then just append var declaration
        // Ex: "add(1, 2)" will become "var extracted = add(1, 2)"
        if (parentStatement.type === "ExpressionStatement" &&
                RefactoringUtils.isEqual(parentStatement.expression, expns[0]) &&
                insertStartPos.line === parentStatementStartPos.line &&
                insertStartPos.ch === parentStatementStartPos.ch) {
            varDeclaration = varType + " " + varName + " = ";
            replaceExpnIndex = 1;
        }

        posToIndent = doc.adjustPosForChange(insertStartPos, varDeclaration.split("\n"), insertStartPos, insertStartPos);

        // adjust pos for change
        for (var i = replaceExpnIndex; i < expns.length; ++i) {
            expns[i].start  = session.editor.posFromIndex(expns[i].start);
            expns[i].end    = session.editor.posFromIndex(expns[i].end);
            expns[i].start  = doc.adjustPosForChange(expns[i].start, varDeclaration.split("\n"), insertStartPos, insertStartPos);
            expns[i].end    = doc.adjustPosForChange(expns[i].end, varDeclaration.split("\n"), insertStartPos, insertStartPos);

            edits.push({
                edit: {
                    text: varName,
                    start: expns[i].start,
                    end: expns[i].end
                },
                selection: {
                    start: expns[i].start,
                    end: {line: expns[i].start.line, ch: expns[i].start.ch + varName.length}
                }
            });
        }

        // Replace and multi-select
        doc.batchOperation(function() {
            doc.replaceRange(varDeclaration, insertStartPos);

            selections = doc.doMultipleEdits(edits);
            selections.push({
                start: {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + 1},
                end:   {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + varName.length + 1},
                primary: true
            });
            session.editor.setSelections(selections);
            session.editor._codeMirror.indentLine(posToIndent.line, "smart");
        });
    }
function extract(scopes, parentStatement, expns, text, insertPosition) {
        var varType          = "var",
            varName          = RefactoringUtils.getUniqueIdentifierName(scopes, "extracted"),
            varDeclaration   = varType + " " + varName + " = " + text + ";\n",
            parentStatementStartPos = session.editor.posFromIndex(parentStatement.start),
            insertStartPos   = insertPosition || parentStatementStartPos,
            selections       = [],
            doc              = session.editor.document,
            replaceExpnIndex = 0,
            posToIndent,
            edits            = [];

        // If parent statement is expression statement, then just append var declaration
        // Ex: "add(1, 2)" will become "var extracted = add(1, 2)"
        if (parentStatement.type === "ExpressionStatement" &&
                RefactoringUtils.isEqual(parentStatement.expression, expns[0]) &&
                insertStartPos.line === parentStatementStartPos.line &&
                insertStartPos.ch === parentStatementStartPos.ch) {
            varDeclaration = varType + " " + varName + " = ";
            replaceExpnIndex = 1;
        }

        posToIndent = doc.adjustPosForChange(insertStartPos, varDeclaration.split("\n"), insertStartPos, insertStartPos);

        // adjust pos for change
        for (var i = replaceExpnIndex; i < expns.length; ++i) {
            expns[i].start  = session.editor.posFromIndex(expns[i].start);
            expns[i].end    = session.editor.posFromIndex(expns[i].end);
            expns[i].start  = doc.adjustPosForChange(expns[i].start, varDeclaration.split("\n"), insertStartPos, insertStartPos);
            expns[i].end    = doc.adjustPosForChange(expns[i].end, varDeclaration.split("\n"), insertStartPos, insertStartPos);

            edits.push({
                edit: {
                    text: varName,
                    start: expns[i].start,
                    end: expns[i].end
                },
                selection: {
                    start: expns[i].start,
                    end: {line: expns[i].start.line, ch: expns[i].start.ch + varName.length}
                }
            });
        }

        // Replace and multi-select
        doc.batchOperation(function() {
            doc.replaceRange(varDeclaration, insertStartPos);

            selections = doc.doMultipleEdits(edits);
            selections.push({
                start: {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + 1},
                end:   {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + varName.length + 1},
                primary: true
            });
            session.editor.setSelections(selections);
            session.editor._codeMirror.indentLine(posToIndent.line, "smart");
        });
    }
function extract ( scopes , parentStatement , expns , text , insertPosition ) { var varType = "var" , varName = RefactoringUtils . getUniqueIdentifierName ( scopes , "extracted" ) , varDeclaration = varType + " " + varName + " = " + text + ";\n" , parentStatementStartPos = session . editor . posFromIndex ( parentStatement . start ) , insertStartPos = insertPosition || parentStatementStartPos , selections = [ ] , doc = session . editor . document , replaceExpnIndex = 0 , posToIndent , edits = [ ] ; // If parent statement is expression statement, then just append var declaration // Ex: "add(1, 2)" will become "var extracted = add(1, 2)" if ( parentStatement . type === "ExpressionStatement" && RefactoringUtils . isEqual ( parentStatement . expression , expns [ 0 ] ) && insertStartPos . line === parentStatementStartPos . line && insertStartPos . ch === parentStatementStartPos . ch ) { varDeclaration = varType + " " + varName + " = " ; replaceExpnIndex = 1 ; } posToIndent = doc . adjustPosForChange ( insertStartPos , varDeclaration . split ( "\n" ) , insertStartPos , insertStartPos ) ; // adjust pos for change for ( var i = replaceExpnIndex ; i < expns . length ; ++ i ) { expns [ i ] . start = session . editor . posFromIndex ( expns [ i ] . start ) ; expns [ i ] . end = session . editor . posFromIndex ( expns [ i ] . end ) ; expns [ i ] . start = doc . adjustPosForChange ( expns [ i ] . start , varDeclaration . split ( "\n" ) , insertStartPos , insertStartPos ) ; expns [ i ] . end = doc . adjustPosForChange ( expns [ i ] . end , varDeclaration . split ( "\n" ) , insertStartPos , insertStartPos ) ; edits . push ( { edit : { text : varName , start : expns [ i ] . start , end : expns [ i ] . end } , selection : { start : expns [ i ] . start , end : { line : expns [ i ] . start . line , ch : expns [ i ] . start . ch + varName . length } } } ) ; } // Replace and multi-select doc . batchOperation ( function ( ) { doc . replaceRange ( varDeclaration , insertStartPos ) ; selections = doc . doMultipleEdits ( edits ) ; selections . push ( { start : { line : insertStartPos . line , ch : insertStartPos . ch + varType . length + 1 } , end : { line : insertStartPos . line , ch : insertStartPos . ch + varType . length + varName . length + 1 } , primary : true } ) ; session . editor . setSelections ( selections ) ; session . editor . _codeMirror . indentLine ( posToIndent . line , "smart" ) ; } ) ; }
Does the actual extraction. i.e Replacing the text, Creating a variable
and multi select variable names
Does the actual extraction . i . e Replacing the text Creating a variable and multi select variable names