moveToNewFile: Support selecting the name of a declaration (#24331)
This commit is contained in:
parent
9cda2bdba0
commit
5622bc2dd6
|
@ -22,8 +22,14 @@ namespace ts.refactor {
|
|||
|
||||
const startNodeIndex = findIndex(statements, s => s.end > range.pos);
|
||||
if (startNodeIndex === -1) return undefined;
|
||||
|
||||
const startStatement = statements[startNodeIndex];
|
||||
if (isNamedDeclaration(startStatement) && startStatement.name && rangeContainsRange(startStatement.name, range)) {
|
||||
return { first: startNodeIndex, afterLast: startNodeIndex + 1 };
|
||||
}
|
||||
|
||||
// Can't only partially include the start node or be partially into the next node
|
||||
if (range.pos > statements[startNodeIndex].getStart(file)) return undefined;
|
||||
if (range.pos > startStatement.getStart(file)) return undefined;
|
||||
const afterEndNodeIndex = findIndex(statements, s => s.end > range.end, startNodeIndex);
|
||||
// Can't be partially into the next node
|
||||
if (afterEndNodeIndex !== -1 && (afterEndNodeIndex === 0 || statements[afterEndNodeIndex].getStart(file) < range.end)) return undefined;
|
||||
|
|
19
tests/cases/fourslash/moveToNewFile_selectionOnName.ts
Normal file
19
tests/cases/fourslash/moveToNewFile_selectionOnName.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export {};
|
||||
////function e[|f|]f() { gee(); }
|
||||
////function gee() { eff(); }
|
||||
|
||||
verify.moveToNewFile({
|
||||
newFileContents: {
|
||||
"/a.ts":
|
||||
`import { eff } from "./eff";
|
||||
|
||||
export {};
|
||||
export function gee() { eff(); }`,
|
||||
"/eff.ts":
|
||||
`import { gee } from "./a";
|
||||
export function eff() { gee(); }`,
|
||||
},
|
||||
});
|
Loading…
Reference in a new issue