<ul dir="auto">
<li>Electron version: All</li>
<li>Operating system: Windows vs Mac</li>
</ul>
<p dir="auto">When I define a custom undo behaviour I found it become different between Windows and Mac devices.</p>
<p dir="auto">This is what I did:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// the main menu I overwrite:
let menuTemplate = [
  // Edit
  {
    label: 'Edit',
    submenu: [
      {
        label: 'Undo',
        accelerator: 'CmdOrCtrl+Z',
        click () {
          console.log('Undo');
        }
      },

      {
        label: 'Redo',
        accelerator: 'Shift+CmdOrCtrl+Z',
        click () {
          console.log('Redo');
        }
      },
    ]
  }
];"><pre class="notranslate"><span class="pl-c">// the main menu I overwrite:</span>
<span class="pl-k">let</span> <span class="pl-s1">menuTemplate</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span>
  <span class="pl-c">// Edit</span>
  <span class="pl-kos">{</span>
    <span class="pl-c1">label</span>: <span class="pl-s">'Edit'</span><span class="pl-kos">,</span>
    <span class="pl-c1">submenu</span>: <span class="pl-kos">[</span>
      <span class="pl-kos">{</span>
        <span class="pl-c1">label</span>: <span class="pl-s">'Undo'</span><span class="pl-kos">,</span>
        <span class="pl-c1">accelerator</span>: <span class="pl-s">'CmdOrCtrl+Z'</span><span class="pl-kos">,</span>
        <span class="pl-en">click</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'Undo'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>

      <span class="pl-kos">{</span>
        <span class="pl-c1">label</span>: <span class="pl-s">'Redo'</span><span class="pl-kos">,</span>
        <span class="pl-c1">accelerator</span>: <span class="pl-s">'Shift+CmdOrCtrl+Z'</span><span class="pl-kos">,</span>
        <span class="pl-en">click</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'Redo'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-kos">]</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">]</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">As you can see, I overwrite the Undo behaviour and use the same shortcuts from the Browser. When I press <code class="notranslate">ctrl/cmd+z</code> on Mac, things goes fine, the menu click go first and take over it. But in Windows, it seems like the original <code class="notranslate">webContents.undo()</code> will be executed first, if the undo stack have states (which means you should typing some letters on a <code class="notranslate">&lt;input&gt;</code> first).</p>
<p dir="auto">This makes me have no chance to overwrite the undo for Windows platform. Is this expect in Windows? If we can not change the menu behaviour, is there a way to disable/stop <code class="notranslate">webContents.undo</code> when pressing <code class="notranslate">ctrl+z</code> so that the Main Menu can receive it?</p>
<p dir="auto">Minimal repro:  <a href="https://gist.github.com/DanielDignam/b49084941a2f731501d5">https://gist.github.com/DanielDignam/b49084941a2f731501d5</a></p>
<p dir="auto">We are using node 4.1.1, Chrome 45.0.2454.85, and Electron 0.35.2, on Windows 10</p>
<p dir="auto">Run attached app.   Notice ^Z reports correctly to the console. Type something into the input box and hit the button to remove the element from the DOM. Hit ^Z notice it doesn't report. Hit ^Z again and notice it does.</p>
<p dir="auto">If you rerun and paste something into the text box N times you'll notice the number of ^Z's it takes before it is reported is N+1.</p>
<p dir="auto">The implication is that the input box is still processing events even though it is no longer in the DOM, and doesn't pass the ^Z on until it has emptied its Undo stack.</p>
<p dir="auto">This breaks undo in our application where application undo actions will not be restored on ^Z if an input field has been used and then removed from the DOM.</p>
<p dir="auto">We want to undo other state in our application when there is no form/input.</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Hello World!&lt;/title&gt;
&lt;/head&gt;
&lt;body id='body'&gt;
&lt;h1&gt;Hello World!&lt;/h1&gt;
We are using node &lt;script&gt;document.write(process.versions.node)&lt;/script&gt;,
Chrome &lt;script&gt;document.write(process.versions.chrome)&lt;/script&gt;,
and Electron &lt;script&gt;document.write(process.versions.electron)&lt;/script&gt;.
&lt;script&gt;
    function removeInput(event) {
        var i = document.getElementById(&quot;foo&quot;);
        var b = document.getElementById(&quot;body&quot;);
        b.removeChild(i);
    }
    const remote = require('electron').remote;
    const Menu = remote.Menu;
    const MenuItem = remote.MenuItem;
    var template = [
        {
            label: 'Edit',
            submenu: [
                {
                    label: 'Undo',
                    accelerator: 'CmdOrCtrl+Z',
                    click: function () {
                        console.log('Undo called');
                    },
                    enabled: true
                }
            ]
        }];
    menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);
&lt;/script&gt;
&lt;input id='foo' type='text'/&gt;
&lt;input type='button' onclick='removeInput()'/&gt;
&lt;/body&gt;
&lt;/html&gt;"><pre class="notranslate"><span class="pl-c1">&lt;!DOCTYPE html<span class="pl-kos">&gt;</span></span>
<span class="pl-kos">&lt;</span><span class="pl-ent">html</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;</span><span class="pl-ent">head</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">title</span><span class="pl-kos">&gt;</span>Hello World!<span class="pl-kos">&lt;/</span><span class="pl-ent">title</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">head</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;</span><span class="pl-ent">body</span> <span class="pl-c1">id</span>='<span class="pl-s">body</span>'<span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;</span><span class="pl-ent">h1</span><span class="pl-kos">&gt;</span>Hello World!<span class="pl-kos">&lt;/</span><span class="pl-ent">h1</span><span class="pl-kos">&gt;</span>
We are using node <span class="pl-kos">&lt;</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span><span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">write</span><span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">versions</span><span class="pl-kos">.</span><span class="pl-c1">node</span><span class="pl-kos">)</span><span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>,
Chrome <span class="pl-kos">&lt;</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span><span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">write</span><span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">versions</span><span class="pl-kos">.</span><span class="pl-c1">chrome</span><span class="pl-kos">)</span><span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>,
and Electron <span class="pl-kos">&lt;</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span><span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">write</span><span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">versions</span><span class="pl-kos">.</span><span class="pl-c1">electron</span><span class="pl-kos">)</span><span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>.
<span class="pl-kos">&lt;</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
    <span class="pl-k">function</span> <span class="pl-en">removeInput</span><span class="pl-kos">(</span><span class="pl-s1">event</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">getElementById</span><span class="pl-kos">(</span><span class="pl-s">"foo"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">var</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">getElementById</span><span class="pl-kos">(</span><span class="pl-s">"body"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-en">removeChild</span><span class="pl-kos">(</span><span class="pl-s1">i</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">const</span> <span class="pl-s1">remote</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'electron'</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">remote</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-v">Menu</span> <span class="pl-c1">=</span> <span class="pl-s1">remote</span><span class="pl-kos">.</span><span class="pl-c1">Menu</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-v">MenuItem</span> <span class="pl-c1">=</span> <span class="pl-s1">remote</span><span class="pl-kos">.</span><span class="pl-c1">MenuItem</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-s1">template</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span>
        <span class="pl-kos">{</span>
            <span class="pl-c1">label</span>: <span class="pl-s">'Edit'</span><span class="pl-kos">,</span>
            <span class="pl-c1">submenu</span>: <span class="pl-kos">[</span>
                <span class="pl-kos">{</span>
                    <span class="pl-c1">label</span>: <span class="pl-s">'Undo'</span><span class="pl-kos">,</span>
                    <span class="pl-c1">accelerator</span>: <span class="pl-s">'CmdOrCtrl+Z'</span><span class="pl-kos">,</span>
                    <span class="pl-en">click</span>: <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                        <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'Undo called'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                    <span class="pl-kos">}</span><span class="pl-kos">,</span>
                    <span class="pl-c1">enabled</span>: <span class="pl-c1">true</span>
                <span class="pl-kos">}</span>
            <span class="pl-kos">]</span>
        <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-s1">menu</span> <span class="pl-c1">=</span> <span class="pl-v">Menu</span><span class="pl-kos">.</span><span class="pl-en">buildFromTemplate</span><span class="pl-kos">(</span><span class="pl-s1">template</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-v">Menu</span><span class="pl-kos">.</span><span class="pl-en">setApplicationMenu</span><span class="pl-kos">(</span><span class="pl-s1">menu</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">script</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;</span><span class="pl-ent">input</span> <span class="pl-c1">id</span>='<span class="pl-s">foo</span>' <span class="pl-c1">type</span>='<span class="pl-s">text</span>'/&gt;
<span class="pl-kos">&lt;</span><span class="pl-ent">input</span> <span class="pl-c1">type</span>='<span class="pl-s">button</span>' <span class="pl-c1">onclick</span>='<span class="pl-s">removeInput()</span>'/&gt;
<span class="pl-kos">&lt;/</span><span class="pl-ent">body</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">html</span><span class="pl-kos">&gt;</span></pre></div>