Support format on paste #13945

Closed
jrieken opened this Issue Oct 18, 2016 · 10 comments

Projects

None yet

6 participants

@jrieken
Member
jrieken commented Oct 18, 2016

We should add support for format on paste. Idea is to simply invoke selection formatters when paste has happened.

@jrieken jrieken self-assigned this Oct 18, 2016
@jrieken
Member
jrieken commented Oct 18, 2016

related to #4039

@jrieken jrieken added this to the January 2017 milestone Jan 3, 2017
@rebornix rebornix was assigned by jrieken Jan 3, 2017
@coreh
coreh commented Jan 6, 2017

On OS X, could this be mapped to "Paste and Match Style"? ⌥⇧⌘V

@jrieken
Member
jrieken commented Jan 12, 2017

@rebornix Do you want me to get started on this? We already have the concept for formatting a range so, my plan is to do the following:

  1. detect paste range
  2. invoke range formatter
@rebornix
Member

@jrieken previously I implemented it in another way but we think that's not good, I'll follow your suggestions and do this again :)

@rebornix rebornix added a commit to rebornix/vscode that referenced this issue Jan 12, 2017
@rebornix rebornix fix #13945. support format on paste 1dd05e7
@rebornix rebornix added a commit to rebornix/vscode that referenced this issue Jan 12, 2017
@rebornix rebornix fix #13945. support format on paste 0a80ad6
@rebornix rebornix added a commit to rebornix/vscode that referenced this issue Jan 12, 2017
@rebornix rebornix fix #13945. support format on paste b8631fb
@jrieken jrieken referenced this issue Jan 23, 2017
Closed

Test format on paste #19047

2 of 2 tasks complete
@OliverJAsh

Like @coreh I'm also interested to know whether this can be a command separate from paste so the user can choose which to use on demand (i.e. one keyboard shortcut for paste, one for paste + format)

@jakearchibald

Firstly, thanks for adding this, it's been the one feature I really missed from Sublime Text.

Having a play around with it, it seems to create two entries into undo history per single paste. I can't decide if that's a bug or a feature.

@rebornix
Member
rebornix commented Feb 6, 2017

@jakearchibald It's not a bug but I can't say it's a feature :( The behavior is consistent with FormatOnType or Save as we hook the formatting handler to Type/Save/Paste event, which makes it two entries in undo/redo stack. cc @jrieken

@jakearchibald

Another "is this a bug or not?"

If I paste:

self.addEventListener('fetch', function(event) {
  event.respondWith(
    promiseAny([
      caches.match(event.request),
      fetch(event.request)
    ])
  );
});

It adds a space between function and (event). I didn't expect it to do that.

@rebornix
Member
rebornix commented Feb 8, 2017

@mjbvz I suppose what @jakearchibald mentioned is actually TypeScript formatter's default behavior, right?

@mjbvz
Contributor
mjbvz commented Feb 8, 2017

Yes, you can disable this formatting using "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false or "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment