@@ -232,6 +232,35 @@ function nextZoomLevel(currentZoom, steps) {
232
232
}
233
233
}
234
234
235
+ const moveTabToExistingWindow = function ( orientation , currentTab ) {
236
+ chrome . windows . getCurrent ( { } , currentWindow => {
237
+ chrome . windows . getAll ( { populate : true } , windows => {
238
+ const filteredWindows = windows . filter ( window => {
239
+ if ( window . id !== currentWindow . id ) {
240
+ if ( orientation === 'left' ) {
241
+ return window . left < currentWindow . left ;
242
+ } else if ( orientation === 'right' ) {
243
+ return window . left > currentWindow . left ;
244
+ } else if ( orientation === 'top' ) {
245
+ return window . top < currentWindow . top ;
246
+ } else if ( orientation === 'bottom' ) {
247
+ return window . top > currentWindow . top ;
248
+ }
249
+ }
250
+ } ) ;
251
+ if ( filteredWindows . length > 0 ) {
252
+ const destinationWindow = filteredWindows [ 0 ] ;
253
+ chrome . tabs . move ( currentTab . id , { windowId : destinationWindow . id , index : - 1 } ) . then ( ( ) => {
254
+ chrome . windows . get ( destinationWindow . id , { populate : true } , newWindow => {
255
+ const newTab = newWindow . tabs . slice ( - 1 ) [ 0 ] ;
256
+ selectSpecificTab ( { id : newTab . id } ) ;
257
+ } ) ;
258
+ } ) ;
259
+ }
260
+ } ) ;
261
+ } ) ;
262
+ } ;
263
+
235
264
// These are commands which are bound to keystrokes which must be handled by the background page.
236
265
// They are mapped in commands.js.
237
266
const BackgroundCommands = {
@@ -313,6 +342,19 @@ const BackgroundCommands = {
313
342
} ) ;
314
343
} ,
315
344
345
+ mergeTabToExistingWindowOnLeft ( request ) {
346
+ moveTabToExistingWindow ( "left" , request . tab ) ;
347
+ } ,
348
+ mergeTabToExistingWindowOnRight ( request ) {
349
+ moveTabToExistingWindow ( "right" , request . tab ) ;
350
+ } ,
351
+ mergeTabToExistingWindowAbove ( request ) {
352
+ moveTabToExistingWindow ( "top" , request . tab ) ;
353
+ } ,
354
+ mergeTabToExistingWindowBelow ( request ) {
355
+ moveTabToExistingWindow ( "bottom" , request . tab ) ;
356
+ } ,
357
+
316
358
nextTab ( request ) {
317
359
return selectTab ( "next" , request ) ;
318
360
} ,
0 commit comments