nvim-ts-autotag icon indicating copy to clipboard operation
nvim-ts-autotag copied to clipboard

Autorename on .tsx files does not work

Open juhaku opened this issue 2 years ago • 7 comments

Hello, Typing <div and then > will result <div></div> It works fine, but when renaming the field it doesn not work. When typing ciwspan<Esc> within the <div> does not result <span></span> but results only <span></div>.

Also when closing single type with slash / it does not add > the the end. Expected behaviour when typing <div and then / the close tag > should be automatically appended.

Also has noted here https://github.com/alvan/vim-closetag/issues/76 When editing tsx or jsx and using jsx and tsx react elements with <></> it does not automatically end or rename the tag either. When typed < and then closed with > it will not automatically add </> end tag.

juhaku avatar Aug 11 '22 17:08 juhaku

it's working fine for me. have a look at my config packer treesitter ts-autotag

shaeinst avatar Aug 26 '22 17:08 shaeinst

The configs where not much different from mine. However I have previously not used <Esc> key but I prefer typing <C-c>. I know ctrl + c is cancel command / operation in neovim but I find it more intuitive than reaching out to the <Esc> or remapping <Esc> to some other key combination, because I want the pressing of <Esc> to consistent across the modes.

So as I have found out:

  • Typing <div an then > will result <div></div>
  • Typing ciwspan<Esc> within div results <span></span>
    • But typing ciwspan<C-c> will not work and will result <span></div>
  • Typing <> will not autoclose </> jsx / tsx empty elements.
  • Also typing <div and then / will not close with >, so end result will be <div/ not <div/>

Is there a way to make the counterpart element update while typing within the element? The way pretty much any IDE does it?

juhaku avatar Aug 27 '22 10:08 juhaku

you can use nvim-autopairs plugin for such task for example:

Typing <> will not autoclose </> jsx / tsx empty elements.

require('nvim-autopairs').add_rules {
    Rule("%<%>$", "</>", { 'typescript', 'typescriptreact', 'javascript', 'javascriptreact' })
            :use_regex(true),
}

shaeinst avatar Aug 27 '22 11:08 shaeinst

Thanks, that fixes the empty tsx element issue, but still the behavior is lacking in other aspects.

juhaku avatar Aug 27 '22 12:08 juhaku

i am not trying to convince you but using <C-c> instead of ESC seems little weird to me. since ESC is one of the important key in vim, i would suggest you to swap ESC with Caps Lock. Then it would become more easy to use ESC (since your left hand fingers are always close to a,s,d,f). i use keyd to swap keys..

shaeinst avatar Aug 27 '22 12:08 shaeinst

You should install this too :TSInstall tsx

Duplicate from #66

putra4648 avatar Aug 30 '22 06:08 putra4648

You should install this too :TSInstall tsx

Yes sure, it is installed

juhaku avatar Aug 30 '22 09:08 juhaku

You should install this too :TSInstall tsx

Duplicate from #66

That fixed for me, at least autoclosing jsx tags

waseidel avatar Oct 03 '22 13:10 waseidel

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 02 '22 18:12 stale[bot]