Magnetic pull in an array Background

I have a row of powerful magnets and a bunch of metal objects between them.
Where will the magnets pull them?

Input

Your input is an array of non-negative integers, which will contain at least one 1.
You can use any reasonable format.

The 0s of the array represent empty space, and the 1s represent fixed magnets.
All other numbers are metal objects, which are pulled by the magnets.
Every object gets pulled towards the nearest magnet (if there's a tie, the object is pulled to the right), and it travels in that direction until it hits the magnet or another object.
In the end, all the objects have clustered around the magnets.
The order of the objects is preserved.

Output

Your output is the array where every object has been pulled as close to the nearest magnet as possible.
It should have the same format as the input.

Example

Consider the array

[0,0,2,0,1,1,0,2,0,3,0,5,0,1,0]


The leftmost 2 gets pulled towards the first pair of magnets, as does the second 2.
The 3 has a magnet four steps away in both directions, so it gets pulled to the right.
The 5 also gets pulled to the right, and it goes between the 3 and the magnet.
The correct output is

[0,0,0,2,1,1,2,0,0,0,0,3,5,1,0]


Rules and scoring

You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.

Test cases

[0,1,0] -&gt; [0,1,0]
[1,0,2,0,0,1,0] -&gt; [1,2,0,0,0,1,0]
[7,0,5,0,0,1,0] -&gt; [0,0,0,7,5,1,0]
[1,0,3,0,1,0,3,0,1] -&gt; [1,0,0,3,1,0,0,3,1]
[1,0,0,0,0,0,0,7,3] -&gt; [1,7,3,0,0,0,0,0,0]
[1,2,3,4,5,6,7,8,9,10,11,0,0,0,1] -&gt; [1,2,3,4,5,6,7,0,0,0,8,9,10,11,1]
[12,3,0,0,1,0,1,3,0,0,6,12,0,0,0,1] -&gt; [0,0,12,3,1,0,1,3,6,0,0,0,0,0,12,1]
Pyth, 28 20

o@.e?bhaDk_x1QkQ~hZQ


Thanks @ThomasKwa for golfing 6 bytes!

This abuses stable sorting by assigning to all the values 1 or greater in the list the index of the nearest 1 (ties broken to the rightmost 1) and then sorting the list by these values. Zeroes are given their own index as their sort value.

Test Suite

Verification Suite

Explanation:

o@.e?bhaDk_x1QkQ~hZQ  ##  implicit: Q = eval(input())
o                  Q  ##  Sort Q using the values of the lambda below
 @              ~hZ   ##  select the value from the matching index of the enumerate
  .e           Q      ##  enumerate with b = value, k = index
    ?b                ##  ternary on b
      haDk_x1Q        ##  if true, this thing
              k       ##  otherwise use the index as the sort weight
          _x1Q        ##  the indices of 1 in Q, given in reverse order 
                      ##  (the reverse makes it sort to the right because of stable sorts)
       aDk            ##  sort those indices by |index - k|
      h               ##  take the first value


Example:

Take the test case [1,0,3,0,1,0,3,0,1], for example. When we apply the enumeration, the zeros will all get their own index as a sort value, so I'll skip those, and do a one and a three.

For the first one, we get the indices of ones: [0, 4, 8]. Then reverse it, and sort by the absolute value of the indices minus the index of the one, which happens to be zero here. So we get [0, 4, 8] back again. The first value is 0 so we use that.

For the three, we get the reversed indices and do the same sorting but using two as the index of the three, so both the 0 and the 4 give the same value for the absolute difference, so we get: [4, 0, 8] and we take the 4.

Then the final "sorting values" array will be [0, 1, 4, 3, 4, 5, 8, 7, 8]. Thanks to the stable sort, the ties are broken by the order that the values originally appeared, so we get the final array we want.