Mimic the X11 Primary selection Background
In X11 (a windowing system used by a lot of Unix-like OS), what you would call the clipboard behave a bit differently than on other OSes like MacOS or Windows. While the &quot;traditional&quot; clipboard using ctrl+v/ctrl+c works, there is also another clipboard, called PRIMARY selection, that behave as following:

when you select a piece of text, this selection is added to the clipboard
when you use the middle mouse button, the content of that selection is pasted where your mouse is.

Some more details for those who are interested : X11: How does “the” clipboard work?
Challenge
The input in this challenge is any representation of a binary input. In the following I will use 'S' for select and 'P' for paste.
Given the input, you must output the input after making the following changes :

put the content of the current output in the primary selection when you receive a select instruction
paste the content of the primary selection in the middle of the current output when you receive a paste instruction. If the current output is odd numbered, the middle is the length divided by 2 and truncated.

Example
Input is SPSP :
selection = &quot;&quot;
output = &quot;SPSP&quot;
 SPSP
↑

selection = &quot;SPSP&quot;
output = &quot;SPSP&quot;
 SPSP
 ↑

selection = &quot;SPSP&quot;
output = &quot;SPSPSPSP&quot;
 SPSP
  ↑

selection = &quot;SPSPSPSP&quot;
output = &quot;SPSPSPSP&quot;
 SPSP
   ↑

selection = &quot;SPSPSPSP&quot;
output = &quot;SPSPSPSPSPSPSPSP&quot;
 SPSP
    ↑

Final Output is SPSPSPSPSPSPSPSP
Test Cases
&quot;&quot; -&gt; &quot;&quot;
&quot;S&quot; -&gt; &quot;S&quot;
&quot;P&quot; -&gt; &quot;P&quot;
&quot;PS&quot; -&gt; &quot;PS&quot;
&quot;SP&quot; -&gt; &quot;SSPP&quot;
&quot;SPP&quot; -&gt; &quot;SSPSPPPPP&quot;
&quot;SPSP&quot; -&gt; &quot;SPSPSPSPSPSPSPSP&quot;
&quot;SPPSP&quot; -&gt; &quot;SPSPPSPSPSPPSPPSPSPPSPPSPSPPSP&quot;
&quot;SPPSPSSS&quot; -&gt; &quot;SPPSSPPSSPPSSPPSSPPSSPPSPSSSPSSSPSSSPSSSPSSSPSSS&quot;

Reference Implementation
In Python 3 :
def clipboard(inp, select=&quot;S&quot;, paste=&quot;P&quot;):
    out = inp
    primary_selection = &quot;&quot;
    for instruction in inp:
        if instruction is select:
            primary_selection = out
        if instruction is paste:
            out = out[:len(out)//2] + primary_selection + out[len(out)//2:]
    return out

Try it online!
Rules

You may assume that the input contains only the &quot;paste&quot; or &quot;select&quot; characters (you don't need to handle error cases)
You may take your input newline separated (e.g S\n P\n S\n)
You may use any kind of data representation (e.g binary data,\n(newline) as a select character and  (space) as a paste character, etc.)
Standard code-golf rules , shortest submission by bytes wins!
Python 2, 64 59 bytes
Input is a list of integers, 0 for select and 1 for paste. Outputs by modifying the input list.

def c(o,p=[]):
 for y in o*1:p=[o*1,p][y];o[len(o)/2:0]=p*y

Try it online!
Commented:

def c(o, p=[]):
    # o is the current output, p the current clipbord value
    # Iterate over a copy of the input list
    for y in o*1:
        # If y==0 (select) assign a copy of o to p
        p=[o*1,p][y]
        # Replace the empty slice at index len(o)/2 with:
        #  - a copy of p if y==1 (paste)
        #  - an empty list otherwise
        o[len(o)/2:0]=p*y

Try it online!