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