Visual Studio 2013 JavaScript/TypeScript奇怪的缩进行为



在处理TypeScript代码时,代码的自动缩进存在问题。我将VS2013与Resharper一起使用。

这个问题主要发生在方法链接上。

例如使用promise:

someService.GetSomeProperties().then(x => {
    return otherService.doSomethingWithX(x.map(y => y.id));
}).then(x => {
    // Pressing enter sets the cursor to this position
        // Using document format (CTRL+K,CTRL+D) the code moves to this level
        return '';
}).then(x => { // Pressing enter from here
    // Moves the previous line to it's position and cursor here
    return 'a';
    }).then(x => {
        // However document format moves this code block to this indention level
        // as well
    }).then(x => {
        // Follow up chaining remains the same
    });

根据"症状",这种行为似乎通常来自于多行语句。

我已经查看了VS2013的选项和R#,但我找不到任何对这种行为有任何影响的选项。

有人知道怎么修吗?

有人知道怎么修吗?

如果您将then放在新行中(即,每个顶级函数都有自己的行),并且总是使用分号:,则它是固定的

someService.GetSomeProperties()
    .then(x => {
        return otherService.doSomethingWithX(x.map(y => y.id));
    })
    .then(x => {
        // Pressing enter sets the cursor to this position
        // Using document format (CTRL+K,CTRL+D) the code moves to this level
        return '';
    })
    .then(x => { // Pressing enter from here
        // Moves the previous line to it's position and cursor here
        return 'a';
    })
    .then(x => {
        // However document format moves this code block to this indention level
        // as well
    })
    .then(x => {
        // Follow up chaining remains the same
    });

最新更新